9 Replies Latest reply on May 26, 2015 9:13 AM by DiegoV_Intel

    Ultrasonic_sensor intel galileo iot

    asyraf

      Hi,

      i already done displaying cputemp on putty by following Recipes - Internet of Things

      P_20150512_201138.jpg

      now i try connect ultrasonic sensor(4 Pin HC-SR04) to galileo

      P_20150512_201033.jpg

      i already run the arduino code(sketch_may11a.ino) as attach and its work by displaying reading on serial monitor..

      so, how i can display that sensor reading on Putty just like cputemp

      example :

                        sensorreading : 23cm

        

      tq

        • 1. Re: Ultrasonic_sensor intel galileo iot
          DiegoV_Intel

          Hi asyraf,

           

          I checked your code and I have been trying to display the data on the terminal (PuTTY) from the Arduino IDE without luck. It seems that displaying data in the terminal from the IDE is not possible. However, you can send the data to the terminal and store it in a file. Then you could open the file directly in the terminal and see the data taken by the Arduino sketch.

           

          To do this you should include a system call in your code with a Linux command to save the data in the file. The system call should look like this:

          system(command);
          
          
          
          

           

          The variable "command" is the Linux command you will run. This command should be this one:

          echo sensorreading:0.0cm >> /home/test.txt
          
          
          
          

           

          This command will save the text "sensorreading:0.0cm" in the file /home/test.txt. However, since you need to save data taken by the sensor you need to catch the current value read by the sensor and store it in the file. This can be done as follow:

          String command = "echo sensorreading:";
          command += String( int( dist ) ) +  "." + String( getDecimal( dist ) );
          command += "cm >> /home/test.txt";
          
          
          
          

           

          These three lines will build the Linux command. Note that I'm using the function "getDecimal()". This function can be found here: Float to String and Float to Character Array - Arduino | Arduino HacksArduino Hacks (check the method 2). This is because you need to convert the float variable "dist" in a string type to build the Linux command and send it using the system call.

           

          So, after building the Linux command you have to use the system call as follow:

          system(command.buffer);
          
          
          
          

           

          Using this way you will be able to save the information in a file in order to check it later directly in the Linux terminal. To open the file you have to use the following command:

          cat /home/test.txt
          
          
          
          

           

          And you will get an output like this:

          output.JPG

           

          I get always "0.0" because I don't have the sensor to take real values. I hope you find this suggestion useful.

           

          Regards,

          Diego.

          • 2. Re: Ultrasonic_sensor intel galileo iot
            asyraf

            i dont understand this part:

             

            To do this you should include a system call in your code with a Linux command to save the data in the file. The system call should look like this:

            1.  system(command);

             

            can you explain more how to make system call from my code, thank you DiegoV_Intel

            • 3. Re: Ultrasonic_sensor intel galileo iot
              DiegoV_Intel

              Hi asyraf,

               

              Sure. The function system() allows you to run Linux commands from the Arduino sketch. The following lines should be added in your code just below the line "dist = pulseIn(EchoPin, HIGH) / 58.0;":

              String command = "echo sensorreading:"; 
              command += String( int( dist ) ) +  "." + String( getDecimal( dist ) ); 
              command += "cm >> /home/test.txt"; 
              system(command.buffer); 
              

               

              Notice that the function getDecimal() is described here: Float to String and Float to Character Array - Arduino | Arduino HacksArduino Hacks

               

              Let me know if it is clearer now.

               

              Regards,

              Diego.

              • 4. Re: Ultrasonic_sensor intel galileo iot
                asyraf

                its really work!!!

                 

                1.PNG

                now im try to visualize data from sensorreading by following same step from Intel Galileo - Internet of Things,do you think it possible  because  i realize that i need to edit JavaScript from https://github.com/ibm-messaging/iot-galileo/releases/download/v0.2.0/ibm-iot-quickstart.zip before i run it on Putty..

                • 5. Re: Ultrasonic_sensor intel galileo iot
                  DiegoV_Intel

                  Hi asyraf,

                   

                  I have followed those steps and I was able to display the CPU temperature and I got the following:

                  output1.JPG

                   

                  As far as I understand you, you want to display the value read by the sensor instead of the temperature value, is it correct? That is possible and as you said, you have to edit the script before. As you can see, at the end of the ibm-iot-quickstart.js script there is a function called sendMessage(). The data that is sent is defined in the following line:

                   

                  message.d.cputemp = data/1000;
                  
                  
                  
                  

                   

                  So you should use the data taken by the sensor instead of the temperature data. For example you could replace the line by this one:

                   

                  message.d.cputemp = "test";
                  
                  
                  
                  

                   

                  and you will get the following output:

                  output2.JPG

                   

                  But as you can see, the website is designed to receive the temperature data, so it won't have much sense if you send another data because the visual interface will be the same.

                   

                  Regards,

                  Diego.

                  • 6. Re: Ultrasonic_sensor intel galileo iot
                    asyraf

                    it seem quite difficult to do , very sad i cant send data to internet through sensor using that website , do you have any suggestion to send data  from any sensor connected  to internet i try Intel Galileo - Programming GPIO From Linux - Malinov Family Web Presence on how to manipulate gpio but it only can read the value of voltage only not the actual data...

                    • 7. Re: Ultrasonic_sensor intel galileo iot
                      DiegoV_Intel

                      Hi asyraf,

                       

                      Did you already try the WebServer example in the Arduino IDE? It might be interesting for you.

                       

                      Regards,

                      Diego.

                      • 8. Re: Ultrasonic_sensor intel galileo iot
                        asyraf

                        Hi Diego,


                        i never try WebServer, if it can send sensor data through internet maybe i should try, can you give some tutorial or websites link related

                         

                        TQVM

                        • 9. Re: Ultrasonic_sensor intel galileo iot
                          DiegoV_Intel

                          Hello asyraf,

                           

                          The WebServer example can be found in the Arduino IDE under File>Examples>Ethernet>WebServer. Make sure you select the proper Galileo board in the Arduino IDE when you attempt to upload the code to the board. The Arduino IDE for Galileo can be downloaded from here: Intel® Galileo Boards and Kits — Software Downloads

                           

                          Regards,

                          Diego.