7 Replies Latest reply on Nov 3, 2014 5:42 PM by SaulQuintero

    Intel Galileo working with SR04

    Ashling_Qin

      hi all, My code work with SR04 sensor on the UNO board is ok. But when I use Galileo Board all return data are 0. That's any different between library on UNO and Galileo? Are there any one can help me?

      The following is my code.

      const int TrigPin = 2;

      const int EchoPin = 3;

      float cm;

      void setup()

      {

      Serial.begin(9600);

      pinMode(TrigPin, OUTPUT);

      pinMode(EchoPin, INPUT);

      }

      void loop()

      {

       

       

      digitalWrite(TrigPin, LOW);

      delayMicroseconds(2);

      digitalWrite(TrigPin, HIGH);

      delayMicroseconds(10);

      digitalWrite(TrigPin, LOW);

       

      cm = pulseIn(EchoPin, HIGH) / 58.0; 

      cm = (int(cm * 100.0)) / 100.0;

      Serial.print(cm);

      Serial.print("cm");

      Serial.println();

      delay(1000);

      }

        • 1. Re: Intel Galileo working with SR04
          Intel_Alvarado

          Hi Ashling_Qin,

          Yes, there are differences between the libraries of the Arduino and the Galileo. I suggest you to take a look at this document https://communities.intel.com/docs/DOC-23388 . In section 1 you will find the supported libraries.

          Regards

          Sergio

          • 2. Re: Intel Galileo working with SR04
            Ashling_Qin

            thanks, I think the problem in Galileo board is pulsein().

            • 3. Re: Intel Galileo working with SR04
              Intel_Alvarado

              Hi Ashling_Qin

              There was a bug in the implementation of the pulseIn() function take a look at this document https://communities.intel.com/docs/DOC-22797.I believe the problem is not with the pulseIn() function anymore. Take a look at the document posted in my last comment under section 2.1.2.The problem with this function is listed in the resolved issues of newer software releases. In case you don’t have it, try upgrading your software version to the newer one.

              Regards

              Sergio

              • 4. Re: Intel Galileo working with SR04
                Ashling_Qin

                I already upgrading my software version to a new one. But now the problem with vcc pin. If keep connect with vcc it doesn't work, and it only work when the vcc turn off than turn on.

                • 5. Re: Intel Galileo working with SR04
                  Intel_Alvarado

                  Why don’t you try uploading the sketch first and the connecting the sensor, sometimes the board has errors uploading sketches with sensors already connected. Also, make sure you are using the correct polarity in the sensor.

                  Regards

                  Sergio

                  • 6. Re: Intel Galileo working with SR04
                    Ashling_Qin

                    Hi Sergio,

                    Thanks you advice. I check the polarity of the sensor already, it have no problem.

                    I have try another code without "Pulesin()", it had working on sensor. there are some problem with the accuracy of distance value. I think that might be the code working need take some time, it effect the value of distance.And I check on some website it said that "Pulesin()" work well on Galileo gen 2. The board what I use is gen 1.

                    I test the pulse on the Oscillograph, it can found pules signal. The problem is signal go too quickly so that Galileo cannot read the result. I think if I can change the timing of "Pulesin()" in library. it will work better.

                    Regards,

                    Ashling

                    • 7. Re: Intel Galileo working with SR04
                      SaulQuintero

                      Hi!
                      I also had that problem, but un updating my version of the Arduino IDE for Galileo (1.5.3 - Intel1.0.3) over Intel Galileo 1st Gen, and I fixed the problem.
                      You must use the FastIO ports (D2 and D3) for Trig and Echos ports.
                      The code that works is the one outlined below:

                       

                      #define trigPin 3

                      #define echoPin 2

                      void setup() {

                           Serial.begin (9600);

                           pinMode(trigPin, OUTPUT_FAST);

                           pinMode(echoPin, INPUT_FAST);

                      }

                       

                      void loop() {

                           long duration, distance;


                           digitalWrite(trigPin, LOW);

                           delayMicroseconds(2);

                           digitalWrite(trigPin, HIGH);

                           delayMicroseconds(10);

                           digitalWrite(trigPin, LOW);

                       

                           duration = pulseIn(echoPin, HIGH);

                           distance = (duration/2) / 29.1;

                           if (distance >= 100 || distance <= 0){

                                Serial.println("Out of range");

                           }else {

                                Serial.print(distance);

                                Serial.println(" cm");

                           }

                           delay(500);

                      }