11 Replies Latest reply on May 6, 2015 5:46 PM by CMata_Intel

    Edison Arduino Board and Ultrasonic Ranger


      Please excuse the long post - I have inserted code and included the comments, attribution and copyright.


      I'm having trouble making the Seeedstudio Grove Ultrasonic Ranger work while connected to the Edison Arduino Board with the Seeedstudio Base Shield installed.  Please help with these questions:


      When I connect power to the board (either with the USB or the barrel connector, the lamp at DS2 (between J2 and J4) begins to blink and continues until I disconnect power.  The lamp at DS1 (between J13 and J2) comes on steadily and does not blink.  Is the blinking lamp normal or is that a sign of a problem?


      The sample code provided by Seeedstudio, UltrasonicDisplayonTerm (see below) indicates that pin 7 should be connected to the sensor using one of the 4 wire cables.  See the line "Ultrasonic ultrasonic(7);"  I assume that means the socket labeled "D7" on the base shield.  Is that the correct socket?


      Thanks in advance!


      --------- code -----------------


      * UltrasonicDisplayOnTerm.ino

      * Example sketch for ultrasonic ranger


      * Copyright (c) 2012 seeed technology inc.

      * Website    : www.seeed.cc

      * Author     : LG, FrankieChu

      * Create Time: Jan 17,2013

      * Change Log :


      * The MIT License (MIT)


      * Permission is hereby granted, free of charge, to any person obtaining a copy

      * of this software and associated documentation files (the "Software"), to deal

      * in the Software without restriction, including without limitation the rights

      * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell

      * copies of the Software, and to permit persons to whom the Software is

      * furnished to do so, subject to the following conditions:


      * The above copyright notice and this permission notice shall be included in

      * all copies or substantial portions of the Software.













      //    Function: Measure the distance to obstacles in front and print the distance

      //              value to the serial terminal.The measured distance is from

      //              the range 0 to 400cm(157 inches).

      //    Hardware: Grove - Ultrasonic Ranger

      //    Arduino IDE: Arduino-1.0



      #include "Ultrasonic.h"


      Ultrasonic ultrasonic(7);

      void setup()




      void loop()


          long RangeInInches;

          long RangeInCentimeters;

          RangeInInches = ultrasonic.MeasureInInches();

          RangeInCentimeters = ultrasonic.MeasureInCentimeters();

          Serial.println("The distance to obstacles in front is: ");

          Serial.print(RangeInInches);//0~157 inches

          Serial.println(" inch");


          Serial.println(" cm");



      ------- end code -------------

        • 1. Re: Edison Arduino Board and Ultrasonic Ranger

          Hi PalmerCliff


          The DS2 led is the buit-in led so I'm guessing that you ran the Blink sketch so it's still blinking. If you go to the Arduino IDE and run a blank sketch it will stop blinking. The DS1 is the power LED so it should be "ON"

          If you are using a Base Shield like this one, yes you have to connect the sensor in D7 according to that code.




          • 2. Re: Edison Arduino Board and Ultrasonic Ranger

            Thanks CMata - I did run the "Blink" sketch, several days (and perhaps a dozen power cycles and shutdown/restarts) ago.  Will power cycles (unplugging the USB and power supply cables then reconnecting them after a 10 sec delay)  and linux "shutdown -h now" commands not terminate a sketch?  I'll run a blank sketch and see if it stops the light blinking.


            I had assumed the blinking DS2 LED was an indicator of a problem which prevented the ultrasonic sensor sketch from working.  If it's running the blink sketch I wonder if that means there's nothing to concern me.


            Has anyone else had success with this sensor and the Edison Arduino board?  I'd appreciate hearing about your experience.


            Thanks again

            • 3. Re: Edison Arduino Board and Ultrasonic Ranger

              The tale continues...  I reimaged the Edison Arduino board and DS2 stopped blinking.  I started the Arduino IDE and loaded the UltrasonicDisplayonTerm sketch, then uploaded it.  The log from the Arduino IDE is below (again, my apologies for the length).  Immediately upon displaying "Transfer complete", DS2 began to blink again.  The results in the terminal showed zero for distance even though I was moving a flat object toward and away from the sensor.

              It seems to me that something is going wrong when I upload the sketch, but I am not seeing an error.

              I would appreciate any ideas...



              ----- Log Begins -----

              Build options changed, rebuilding all


              Sketch uses 78,174 bytes (0%) of program storage space. Maximum is 10,000,000 bytes.


              starting download script


              Args to shell: C:\Intel\arduino-1.6.0+Intel\hardware\tools\x86\bin C:\Users\cpalmer\AppData\Local\Temp\build1933622112445155653.tmp/UltrasonicDisplayOnTerm.cpp.elf COM5

              # clupload script to invoke lsz

              COM PORT 5

              # Copyright (C) 2014 Intel Corporation


              # This library is free software; you can redistribute it and/or

              # modify it under the terms of the GNU Lesser General Public

              # License as published by the Free Software Foundation; either

              Converted COM Port COM5 to tty port /dev/ttyS4

              Sending Command String to move to download if not already in download mode

              # version 2.1 of the License, or (at your option) any later version.


              Deleting existing sketch on target

              # This library is distributed in the hope that it will be useful,

              # but WITHOUT ANY WARRANTY; without even the implied warranty of


              # Lesser General Public License for more details.


              # You should have received a copy of the GNU Lesser General Public

              # License along with this library; if not, write to the Free Software

              # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA



              echo "starting download script"

              echo "Args to shell:" $*


              # ARG 1: Path to lsz executable.

              # ARG 2: Elf File to download

              # ARG 3: COM port to use.


              #path contains \ need to change all to /




              #COM ports are not always setup to be addressed via COM for redirect.

              #/dev/ttySx are present. Howwever, COMy -> /dev/ttySx where x = y - 1




              echo "COM PORT" $com_port_id


              echo "Converted COM Port" $com_port_arg "to tty port" $tty_port_id


              echo "Sending Command String to move to download if not already in download mode"

              echo "~sketch downloadEdison" > $tty_port_id


              #Move the existing sketch on target.

              echo "Deleting existing sketch on target"

              "$fixed_path/lsz.exe" --escape -c "mv -f /sketch/sketch.elf /sketch/sketch.elf.old" <> $tty_port_id 1>&0


              Transfer complete

              # Execute the target download command


              #Download the file.


              "$fixed_path/lsz.exe" --escape --binary --overwrite $host_file_name <> $tty_port_id 1>&0

              Sending: UltrasonicDisplayOnTerm.cpp.elf

              Moving downloaded file to /sketch/sketch.elf on target


              Bytes Sent:   1024/  79768   BPS:-2147483648 ETA 00:00 

              Bytes Sent:   9216/  79768   BPS:-2147483648 ETA 00:00 

              Bytes Sent:  10240/  79768   BPS:-2147483648 ETA 00:00


              Bytes Sent:  11264/  79768   BPS:-2147483648 ETA 00:00

              Bytes Sent:  12288/  79768   BPS:-2147483648 ETA 00:00

              Bytes Sent:  13312/  79768   BPS:-2147483648 ETA 00:00

              Bytes Sent:  14336/  79768   BPS:-2147483648 ETA 00:00

              Bytes Sent:  15360/  79768   BPS:-2147483648 ETA 00:00

              Bytes Sent:  16384/  79768   BPS:-2147483648 ETA 00:00

              Bytes Sent:  17408/  79768   BPS:-2147483648 ETA 00:00

              Bytes Sent:  18432/  79768   BPS:1181545  ETA 00:00 

              Bytes Sent:  19456/  79768   BPS:1247186  ETA 00:00 

              Bytes Sent:  20480/  79768   BPS:1312827  ETA 00:00 

              Bytes Sent:  21504/  79768   BPS:1378469  ETA 00:00 

              Bytes Sent:  22528/  79768   BPS:1444110  ETA 00:00 

              Bytes Sent:  23552/  79768   BPS:1509752  ETA 00:00 

              Bytes Sent:  24576/  79768   BPS:1575393  ETA 00:00 

              Bytes Sent:  25600/  79768   BPS:1641034  ETA 00:00 

              Bytes Sent:  26624/  79768   BPS:1706676  ETA 00:00 

              Bytes Sent:  27648/  79768   BPS:1772317  ETA 00:00 

              Bytes Sent:  28672/  79768   BPS:1837959  ETA 00:00 

              Bytes Sent:  29696/  79768   BPS:1903600  ETA 00:00 

              Bytes Sent:  30720/  79768   BPS:1969241  ETA 00:00 

              Bytes Sent:  31744/  79768   BPS:2034883  ETA 00:00 

              Bytes Sent:  32768/  79768   BPS:2100524  ETA 00:00 

              Bytes Sent:  33792/  79768   BPS:2166166  ETA 00:00 

              Bytes Sent:  34816/  79768   BPS:2231807  ETA 00:00 

              Bytes Sent:  35840/  79768   BPS:2297448  ETA 00:00 

              Bytes Sent:  36864/  79768   BPS:2363090  ETA 00:00 

              Bytes Sent:  37888/  79768   BPS:2428731  ETA 00:00 

              Bytes Sent:  38912/  79768   BPS:2494373  ETA 00:00 

              Bytes Sent:  39936/  79768   BPS:2560014  ETA 00:00 

              Bytes Sent:  40960/  79768   BPS:2625655  ETA 00:00 

              Bytes Sent:  41984/  79768   BPS:2691297  ETA 00:00 

              Bytes Sent:  43008/  79768   BPS:2756938  ETA 00:00 

              Bytes Sent:  44032/  79768   BPS:2822580  ETA 00:00 

              Bytes Sent:  45056/  79768   BPS:2888221  ETA 00:00 

              Bytes Sent:  46080/  79768   BPS:1476927  ETA 00:00 

              Bytes Sent:  47104/  79768   BPS:1509747  ETA 00:00 

              Bytes Sent:  48128/  79768   BPS:1494662  ETA 00:00 

              Bytes Sent:  49152/  79768   BPS:1526463  ETA 00:00 

              Bytes Sent:  50176/  79768   BPS:1511283  ETA 00:00 

              Bytes Sent:  51200/  79768   BPS:1497036  ETA 00:00 

              Bytes Sent:  52224/  79768   BPS:1526976  ETA 00:00 

              Bytes Sent:  53248/  79768   BPS:1512688  ETA 00:00 

              Bytes Sent:  54272/  79768   BPS:1499188  ETA 00:00 

              Bytes Sent:  55296/  79768   BPS:1527475  ETA 00:00 

              Bytes Sent:  56320/  79768   BPS:1513941  ETA 00:00 

              Bytes Sent:  57344/  79768   BPS:1541467  ETA 00:00 

              Bytes Sent:  58368/  79768   BPS:1527921  ETA 00:00 

              Bytes Sent:  59392/  79768   BPS:1515066  ETA 00:00 

              Bytes Sent:  60416/  79768   BPS:1541188  ETA 00:00 

              Bytes Sent:  61440/  79768   BPS:1528323  ETA 00:00 

              Bytes Sent:  62464/  79768   BPS:1516082  ETA 00:00 

              Bytes Sent:  63488/  79768   BPS:1540936  ETA 00:00 

              Bytes Sent:  64512/  79768   BPS:1528687  ETA 00:00 

              Bytes Sent:  65536/  79768   BPS:1517005  ETA 00:00 

              Bytes Sent:  66560/  79768   BPS:1540708  ETA 00:00 

              Bytes Sent:  67584/  79768   BPS:1529018  ETA 00:00 

              Bytes Sent:  68608/  79768   BPS:1517845  ETA 00:00 

              Bytes Sent:  69632/  79768   BPS:1540499  ETA 00:00 

              Bytes Sent:  70656/  79768   BPS:1529320  ETA 00:00 

              Bytes Sent:  71680/  79768   BPS:1518614  ETA 00:00 

              Bytes Sent:  72704/  79768   BPS:1540309  ETA 00:00 

              Bytes Sent:  73728/  79768   BPS:1529597  ETA 00:00 

              Bytes Sent:  74752/  79768   BPS:1519321  ETA 00:00 

              Bytes Sent:  75776/  79768   BPS:1540134  ETA 00:00 

              Bytes Sent:  76800/  79768   BPS:1529822  ETA 00:00 

              Bytes Sent:  77824/  79768   BPS:1519943  ETA 00:00 

              Bytes Sent:  78848/  79768   BPS:1539942  ETA 00:00 

              Bytes Sent:  79768   BPS:1499344                        


              Transfer complete


              #mv the downloaded file to /sketch/sketch.elf


              echo "Moving downloaded file to /sketch/sketch.elf on target"

              "$fixed_path/lsz.exe" --escape -c "mv $target_download_name /sketch/sketch.elf; chmod +x /sketch/sketch.elf" <> $tty_port_id 1>&0


              Transfer complete

              ----- Log Ends -----

              • 4. Re: Edison Arduino Board and Ultrasonic Ranger

                Not sure of your question.  Looks like the transfer was complete...


                HOWEVER: most likely the ultrasonic device will not work.  Why?  The Edison takes a very long time to switch a pin from output mode to input mode.  With the normal Edison code base this can be longer than the time it takes for the ultrasonic device (same as the old Ping sensor) to receive the echo, so then when the code in the library goes into a pulsein command, the pulse will never happen and your program will hang in this.  More details in the thread: Ping Sensor - pinMode too slow?  (both Arduino and MRAA)


                Note: I made some changes to the Arduino code base for the Edison which sped this up quite a bit, although still maybe too slow on Arduino Edison board.  However so far none of these updates were incorporated into the Intel code base.



                • 5. Re: Edison Arduino Board and Ultrasonic Ranger

                  The question/concern was the blinking DS2 on the board - I think the blinking is telling me there is a problem somewhere.

                  Thanks for the work you have done on timing the pin mode change.  I am going to try the code on a Arduino Uno and see if the same thing happens.

                  I noticed in the thread you mentioned some suggestion about buffering the data returned from the ultrasonic ranger.  Did you have any luck making that work?

                  Thanks Again

                  • 6. Re: Edison Arduino Board and Ultrasonic Ranger

                    Hi PalmerCliff


                    I understood that after that you "reimaged the Edison board" the DS2 led stopped blinking. Is this rigt? When you say reimaged, do you mean, re-flashed?

                    Are you selecting the right board and port in your Arduino IDE?

                    Did you tried the code on the Arduino UNO? If it works on the Arduino and not in the Edison is because the library was made specifically for Arduino so there may be some differences in the libraries that the Ultrasonic library is calling. They also have different architectures so when the library was written they should take care of specific things about the pins, speed rate and others.




                    • 7. Re: Edison Arduino Board and Ultrasonic Ranger
                      Hi CMata,


                      You are correct that after I reflashed/reimaged (not sure why there is a perception of a difference in terms - I reloaded the Yocto Linux image onto the Edison) the DS2 led stopped blinking.  As long as I don't try to rerun the ultrasonic sensor code the DS2 led does not blink, but begins to blink immediately if I do try to rerun the ultrasonic sensor code.  Running other sketches does not cause this LED to blink.  I am carefully selecting the Edison board and the port identified as "Intel Edison Com Port" in Windows 7 device manager.


                      I expect to receive an Arduino UNO in the next few days and will update when I know the results of trying the ultrasonic sensor with that platform.  I am also receiving an Arudino Mega  2560 and will try the ultrasonic sensor on that platform also..  Both boards are made by Inland.


                      In addition, an engineer with SeeedStudio (who made the ultrasonic sensor) suggested I use the C/C++ sample code instead of the Arduino Sketch.  That's also on my list to try.


                      Thanks so much for your interest and helpful suggestions.  I'm confident that this problem will be solved soon and I will be able to report either success or a wider range of problems.

                      • 8. Re: Edison Arduino Board and Ultrasonic Ranger

                        Hi CMata, I did get the Arduino UNO board and try it with the Seeedstudio Ultrasonic ranger and the sample code provided by Seeedstudio and it worked.  It accurately measures distance.  I installed a copy of the Arduino IDE in a directory seperate from the Intel-supplied version and then installed the Seeedsutdio-supplied library.  Everything worked great.


                        The next step is to try the c/c++ approach using Eclipse instead of the Arduino IDE.

                        • 9. Re: Edison Arduino Board and Ultrasonic Ranger

                          Hi PalmerCliff


                          I'm glad that the sensor is working fine, if you haven't started to work with Eclipse and your project I recommend you to take a look at: https://software.intel.com/en-us/articles/install-eclipse-ide-on-intel-iot-platforms




                          • 10. Re: Edison Arduino Board and Ultrasonic Ranger

                            Thanks CMata, I am starting to look at the Eclipse information Intel has posted.  Is this forum the correct place to post questions about locating sample code and steps to use Eclipse (I am familiar with Eclipse but not using it with the Edison)?

                            Thanks again

                            • 11. Re: Edison Arduino Board and Ultrasonic Ranger

                              Hi PalmerCliff


                              I encourage you to post all your questions in the communities because there could be another maker that has done something similar and could help you. You can also post your questions about the Eclipse using the Edison board and we will be glad to help you. About the sample codes, as you may know the Eclipse you download from the "Edison Downloads website" has some templates that could be very helpful for you.


                              Best regards;