8 Replies Latest reply on May 28, 2016 7:13 PM by XimBIco

    How can ı make 4pins ultrasonic sensor works?(In coding part)

    esconda

      Hello Everyone!

      I am working in one unmanned ground vehicle robot for my thesis, finally I decided to use ultrasonic sensor for automatic control.

       

      In this thessis I have to compare Intel Galileo and arduino uno in same project, using same components.

       

      In this case I bought 4 pin ultrasonic sensor and after some try, I managed it to work in Arduino uno.

       

      After this I tried it on the Galileo, Unfortunately it didn't work with same type of code.

       

      According my investigation,I used many code which is suggested by users in this webside.

       

      So untill this last part of investigation, I know "Pulseın()" code works with Galileo but unfortunately it doesn give any response , says; 0inch, 0 cm

       

      I know that other codes also doesnt work.Also I am really new to galileo and environmental components integrated codes with Arduino ide.

       

      Anybody help me in this condition, how can I make ultrasonic sensor work in galileo.If ı can not manage it , it is going te be written galileo side as a "-" in my thesis.

       

      Bu I don't want it.It should work somehow

        • 1. Re: How can ı make 4pins ultrasonic sensor works?(In coding part)
          CMata_Intel

          Hi esconda

           

          I found this example, is for a 3 pin ultrasonic sensor, maybe you could modify it to your case, or can help you on how to start.

          Also, be sure about the libraries that you are using there could are differences between the libraries for Arduino and Galileo Boards. For this take a look at:

          C:\arduino-1.5.3-Intel.1.0.4\hardware\arduino\edison\cores

          C:\arduino-1.5.3-Intel.1.0.4\hardware\arduino\edison\libraries

          Try to use simple code just to debug this, is going to be easier in this way. If you still having problems with this attach the log of what you are receiving in the IDE.

           

          Regards;

          CMata

          • 2. Re: How can ı make 4pins ultrasonic sensor works?(In coding part)
            CMata_Intel

            HI esconda ;

             

            I realized that the link didn't show in the previous message. Sorry for that. The link that I was talking about is this: 3 Pin ultrasonic sensor in galileo

            Let us know about new results in your project.

             

            Best Regards,

            CMata

            • 3. Re: How can ı make 4pins ultrasonic sensor works?(In coding part)
              esconda

              I found the solution, recently new library released for Intel Galileo with name of Newping function.

              After installing this library, I managed to work it according to below code.Pin 2 and 3 uses higher frequency according to other pins.If we use it for trigger and echo pins, it responses immediately.

               

               

              const int outPin = 2; // Using FAST_IO

              const int inPin = 3; // Using FAST_IO

               

               

              void setup() {

               

               

                Serial.begin(115200);

                pinMode(outPin, OUTPUT_FAST);

                pinMode(inPin, INPUT_FAST);

              }

               

               

              void loop()

              {

                // establish variables for duration of the ping,

                // and the distance result in inches and centimeters:

                long duration, inches, cm;

               

               

                // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.

                // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

                fastDigitalWrite(outPin, LOW);

                waitMicros(2);

                fastDigitalWrite(outPin, HIGH);

                waitMicros(10);

                fastDigitalWrite(outPin, LOW);

               

               

                // The same pin is used to read the signal from the PING))): a HIGH

                // pulse whose duration is the time (in microseconds) from the sending

                // of the ping to the reception of its echo off of an object.

                duration = pulseIn(inPin, HIGH); // calls fastGpioPciDigitalRead

               

               

                // convert the time into a distance

                inches = microsecondsToInches(duration);

                cm = microsecondsToCentimeters(duration);

               

                Serial.print(inches);

                Serial.print("in, ");

                Serial.print(cm);

                Serial.print("cm");

                Serial.println();

               

                delay(100);

              }

               

               

              void waitMicros(int val)

              {

                unsigned long a = micros();

                unsigned long b = micros();

                while((b-a) < val)

                {

                  b = micros();

                  if(a>b)

                  {

                    break;

                  }

                }

              }

               

               

              long microsecondsToInches(long microseconds)

              {

                // According to Parallax's datasheet for the PING))), there are

                // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per

                // second).  This gives the distance travelled by the ping, outbound

                // and return, so we divide by 2 to get the distance of the obstacle.

                // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf

                return microseconds / 74 / 2;

              }

               

               

              long microsecondsToCentimeters(long microseconds)

              {

                // The speed of sound is 340 m/s or 29 microseconds per centimeter.

                // The ping travels out and back, so to find the distance of the

                // object we take half of the distance travelled.

                return microseconds / 29 / 2;

              }

              • 4. Re: How can ı make 4pins ultrasonic sensor works?(In coding part)
                CMata_Intel

                Hi esconda

                 

                Great news! If you have any other question don't hesitate to ask the communities.

                 

                Best Regards;

                CMata

                • 5. Re: How can ı make 4pins ultrasonic sensor works?(In coding part)
                  julianak

                  Hi, I'd like to know where you found the NewPing library for Galileo.

                  I am trying to use HC-SR04 sensor with Intel Galileo gen2 but I haven't found any mentions to NewPing for Galileo anywhere else than your post...

                  Thanks in advance!

                  • 6. Re: How can ı make 4pins ultrasonic sensor works?(In coding part)
                    CMata_Intel

                    Hi julianak

                     

                    Have you tried with this example for HC-SR04? HC-SR04 Sketch

                    I'm not sure which was the library that esconda used. It could be this one NewPing_v1.5.zip - arduino-new-ping - NewPing Library v1.5 - NewPing - Fast ultrasonic Arduino library for the HC-SR0…

                     

                    Regards;

                    CMata

                    • 7. Re: How can ı make 4pins ultrasonic sensor works?(In coding part)
                      julianak

                      Hi CMata_Intel

                       

                      I found a simpler way to make it work, since PulseIn function is now working on Galileo.

                       

                      [code]

                      const int TrigPin = 2;

                      const int EchoPin = 3;

                      float dist;

                       

                      void setup()

                      {

                        Serial.begin(9600);

                        pinMode(TrigPin, OUTPUT_FAST);

                        pinMode(EchoPin, INPUT_FAST);

                      }

                       

                      void loop()

                      {

                        fastDigitalWrite(TrigPin, HIGH);

                        delayMicroseconds(10);

                        fastDigitalWrite(TrigPin, LOW);

                        dist = pulseIn(EchoPin, HIGH) / 58.0;

                       

                        Serial.print(dist);

                        Serial.println(" cm");

                        delay(100);

                      }

                      [/code]

                      1 of 1 people found this helpful
                      • 8. Re: How can ı make 4pins ultrasonic sensor works?(In coding part)
                        XimBIco

                        I finally managed to make my HC-SR04 sensor work fine on Intel Galileo Gen 1, with the following configuration:

                         

                        - Arduino IDE 1.6.5

                        - Select Menu: Tools -> Board -> Board Manager

                        - Select list item 'Intel i586 Boards by Intel' - for Board Galileo (there should be another item for Edison too, just disregard it)

                        - Click 'More Info' link.

                        - A combo box will appear to select the board's version.

                        - Select version 1.6.2.

                        - The code above which is setting up the pins 2 and 3 worked just fine.

                         

                        The most recent version of this board 1.6.7 on Arduino IDE was showing a compiling error related to a missing 'core.a' file.

                        1 of 1 people found this helpful