2 Replies Latest reply on Sep 15, 2014 12:53 PM by flummer

    How Do I Run Ultrasonic Sensor on Galileo?

    Syah

      Hi,

       

      I am using DYP-ME007 ultrasonic sensor. Previously, on my UNO, I execute these codes below.

       

       

      #include <NewPing.h>
      
      
      #define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
      #define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
      #define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
      
      
      NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
      
      
      void setup() {
        Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
      }
      
      
      void loop() {
        delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
        unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
        Serial.print("Ping: ");
        Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)
        Serial.println("cm");
      }
      

       

      However, apparently it is not able to compile as it requires avr header as listed under the known issues. As such, how do I achieve the same thing on the Galileo?

        • 1. Re: How Do I Run Ultrasonic Sensor on Galileo?
          DiegoV_Intel

          Hi Syah,

           

          Could you try to compile the code again and attach the error log, please?

           

          Have a nice day!

           

          Regards,

          Diego.

          • 2. Re: How Do I Run Ultrasonic Sensor on Galileo?
            flummer

            Hi Syah,

             

            The library that you are using seems to rely on AVR specific interrupt and timer features for relatively tight I/O timing to read the echo signal and from there calculate the distance.

             

            It will likely not work with the Galileo, since your code is executed as a program under Linux and I/O timing like what you need here isn't really possible.

             

            If you would like to have the higher processing power you get with the Galileo (eg. for network, web service, xml, etc.) I would suggest that you add in a small Arduino or other micro controller that can do the measurements with your sensor, and then communicate with the Galileo board via UART, I2C or SPI.

             

            I understand that it would be cool to have all code in one place and not have to deal with multiple units, but it will likely be very much up hill if at all possible to do it with just the Galileo.

             

            /Thomas

            1 of 1 people found this helpful