ultrasonic sensor array on udoo neo

Discussion in 'UDOO NEO' started by Juan Sebastian Guerrero, Dec 24, 2015.

  1. Juan Sebastian Guerrero

    Juan Sebastian Guerrero UDOOer

    Joined:
    Dec 24, 2015
    Messages:
    9
    Likes Received:
    3
    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.
     

    Attached Files:

    Al3Co likes this.
  2. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    Dear Juan,
    let us test it a bit and we'll let you know how it works on our side.
     
  3. Andrea Rovai

    Andrea Rovai Well-Known Member

    Joined:
    Oct 27, 2014
    Messages:
    1,703
    Likes Received:
    240
    At which tension you're powering the sensor? 3.3 or 5? at which pin do you attach the data line of the sensor?
     
  4. Juan Sebastian Guerrero

    Juan Sebastian Guerrero UDOOer

    Joined:
    Dec 24, 2015
    Messages:
    9
    Likes Received:
    3
    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();
    }
     

Share This Page