Hello every one. I'm trying to connect an ultrasonic sensor array on the udoo neo but it doesn't works, the only data who is displayed is a bunch of zeros and then a real data and again zeros. I tested the same circuit and code on the arduino uno and it works fine. 4 Ultrasonic sensor HC-SR04 Trigger pins (2,4,6,8) Echo pins (3,5,7,9) I attached the circuit, pay no attention to raspberry pi connections.
At which tension you're powering the sensor? 3.3 or 5? at which pin do you attach the data line of the sensor?
I am powering the sensor with 5 volts, and data (Echo) pins are connected (3,5,7,9). I attached the code. That works fine in arduino. Code: const int max_time = 23200; struct sensor { int trigger; int echo; }; const sensor s0 = {2, 3}; const sensor s1 = {6, 7}; const sensor s2 = {8, 9}; const sensor s3 = {10, 11}; const sensor s[] = {s0, s1, s2, s3}; const int interval = 10; unsigned long ping_interval[4]; int current_sensor = 0; int medidas [4]; void setup() { Serial.begin(9600); for (int i = 0; i < sizeof(s); i++) { pinMode(s.trigger, OUTPUT); pinMode(s.echo, INPUT); } ping_interval[0] = millis() + 75; for (int i = 1; i < 4; i++) { ping_interval = ping_interval[i-1] + interval; } } unsigned long read_sensor(const struct sensor &sen) { digitalWrite(sen.trigger, HIGH); delayMicroseconds(5); digitalWrite(sen.trigger, LOW); unsigned long t = pulseIn(sen.echo, HIGH); t = t > max_time ? max_time : t; return t; } void loop() { for (int i = 0; i < 4; i++) { if (millis() >= ping_interval){ ping_interval += interval * 4; if (i ==0 && current_sensor == 3) cycle(); medidas = read_sensor(s); current_sensor = i; } //delay(50); } } void cycle() { for(int i = 0; i < 4; i++) { Serial.print(medidas); Serial.print(" "); } Serial.println(); }