9 Replies Latest reply on Sep 23, 2015 6:16 PM by CMata_Intel

    Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?

    spartanBoss

      Hi,

       

      I have been trying to do this for a while now, however I am new to this coding! Would anyone be kind enough in order to provide me with some code, so that I can send live temperature sensor data from one arduino board, and display it on a lcd or serial monitor of a different edison board connected to the same wifi?

       

      I have read many different posts on here and other websites, and managed to make a p2p connection between the two boards, however I am absolutley unable to code so that the two boards talk to each other. This is the code I have so far (This only works for one board, as I do not know how to input the other board into it):

       

      My questions are: How do I link this with the two boards (please provide me with some code if possible), what programs do I need to use, do I need to upload two different files to the two edisons? Please help!

       

      -----------------------------------------------

      #include <math.h>

      #include <rgb_lcd.h>

      #include <Wire.h>

       

      rgb_lcd lcd;

      const int pinTemp = A0;      // pin of temperature sensor

      float temperature;           //A0

      int B=3975;                  // B value of the thermistor

      float resistance;

      int blueLED = 3;

      int btn = 4;

       

      void setup()

      {

        pinMode(btn, INPUT);

        pinMode (blueLED, OUTPUT);

         lcd.begin(16, 2);          // I2C lets the main loop know that the lcd is 16 by 2

      }

       

      void loop(){

      int buttonState = digitalRead(btn);

      if(buttonState == 1){

        digitalWrite(blueLED,1);

           int val = analogRead(pinTemp);                               // get analog value

          resistance=(float)(1023-val)*10000/val;                      // get resistance

          temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;     // calc temperature

        // Print out to the LCD

          lcd.print("Temp1: ");   

          lcd.print(temperature); //print the output of the above calculations

          lcd.print(" *C");

          lcd.setCursor(0, 1);  

          delay(1000);            // delay 1 second, adjust this to affect the rate that the device polls the temp

          lcd.clear();      // refreshes the LCD

       

      }

      else if (buttonState == 0){

        lcd.print("Temp1: OFF ");

        lcd.setCursor(0, 1);

        digitalWrite(blueLED,0);

        delay(1000);

        lcd.clear();      // refreshes the LCD

      }

      }

       

      -------------------------------------------------

       

       

      HOW WOULD YOU SOLVE THIS/ CODE THIS?

        • 1. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
          CMata_Intel

          Hi spartanBoss,

           

          You can try with writing and reading files.

          Let's say the IP address of the transmitter board  is 10.10.1.1 and that you have a file named /home/root/file.txt where you are saving all the lectures of the sensor. In the receiver board you will be reading all those lines too.

           

          You can test this doing the following.

           

          In the transmitter board:

          1. Create the file /home/root/file.txt

          2. Run the command echo 1 >> /home/root/file.txt

           

          In the receiver board

          1. Check your IP address with configure_edison --showWiFiIP . For the test, let's say the IP is 10.10.1.1

          2. Run the command ssh 10.10.1.1 tail -f /home/root/file.txt .

          3. After you ran the command and give the respective permissions you can start changing the file in the other board.

           

          Testing:

          • In the transmitter, run echo 23 >> /home/root/file.txt. In the receiver board you should see the 23 number.
          • You can do this and seeing the changes in the Serial Monitor by changing the command with:  ssh 10.10.1.1 tail -f /home/root/file.txt > /dev/ttyGS0

           

          You can try with something like this using the Arduino IDE with system calls, in one Edison writing all the sensor values and in the other one you will be reading the last line of the file. I suggest you to do this kind of communication using the Linux Terminal and not the Arduino IDE, but if you want to use the IDE, there are some examples in the Internet related with data-loggers that might help you to do read the file and use the information as a variable in the IDE.

           

          -> Another alternative could be creating a web server/client with the boards. There are some examples in the Arduino IDE you should look at, like the WiFiUdpSendReceiveString.ino

           

          Regards,

          Charlie

          • 2. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
            spartanBoss

            Hi Charlie,

             

            Thanks for your reply. Just a few questions:

            1.When you say 'Create the file /home/root/file.txt' how do I exactly do this and where?

            2. how would I make the sensor data be writen to that file?

            3. Lastly, do the two arduinos have to be connected to sepearate machines (e.g. one laptop and another), or can they just be connected to the same wifi (In this case I udnerstand that they would have different IP addresses right?)

             

            Thank you in advance!

            • 3. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
              CMata_Intel

              Hi spartanBoss,

               

              1. In order to create a file you can use the touch command and for this example you have to create the file it in  /home/root

              You can run in your board the following command and you will create the file in the suggested location.

              root@edison:~# touch /home/root/file.txt
              

              2. It depends on how are you going to develop this.

              In the Arduino IDE, you could search in the Internet some examples for Arduino, there is an example in the Arduino IDE (File > Examples > SD > Datalogger) that may help you on this.

              If you are going to use C, C++, Python or Javascript for this, you will need to search for examples of scripts in these languages for how to read and write files.

              3. I tested this by using one laptop as host-machine and two Edison boards connected to the same WiFi network. You can use two Host-Machines or one, but you will need to have both boards in the same WiFi network. Yes, the boards will have different IP addresses.

               

              Regards,

              Charlie

              • 4. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
                spartanBoss

                Hi. I am afraid I have tried your method and it does not work for me. Would i tbe possible if you give me step by step guidance and tell me exactly how to do it? My transmitter ip is 192.168.0.18 and my reciever ip is 192.168.0.17. I have connected to one edison over ssh using one laptop, and to the other using another laptop through ssh. The two edisons are connected by wifi p2p, and are on the same port on each laptop.

                 

                Thanks

                • 5. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
                  CMata_Intel

                  Hi,

                   

                  Which step is not working for you?

                  In the transmitter, run echo 23 >> /home/root/file.txt

                  In the receiver, run  ssh 192.168.0.18  tail -f /home/root/file.txt

                  After this, every time you run (in the transmitter) echo "something" >>/home/root/file.txt you should see a new line in the receiver board.

                   

                   

                  Regards,

                  Charlie

                  • 6. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
                    Konradical

                    HeyCMata_Intel,


                    I have a related question to logging data into a text file and sending it to another machine:


                    1. What are the limitations for the text file as far as size in this memory location? I'm looking to log 6 bytes at a 100 Hz rate for lets assume 10 minutes. What problems will I run into? Will I lose the data file if I power goes out or the Edison goes beyond the range of the Wifi network?

                     

                    2. If I wanted to send the text file off to a computer for visual analysis, is it best to stream it straight to the computer or first create the file, then transfer it. Currently I'm controlling my Edison via ssh and will eventually implement a script to run all the commands without a user. What are the best options when it comes to acquiring the data back to my computer? 

                     

                    Thanks,

                    Konrad

                    • 7. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
                      CMata_Intel

                      Hi Konradical,

                       

                      1. I'm not sure if there is a maximum size for a file. There would be a lot of things involved like Yocto version, file format, working partition, free space and others. We could do some tests, could you share your code? Have you done some tests with this?

                      About your concerns if you will lose data. If you are writing into the file and the power of the board goes down you will loose data depending on how are you writing into the file. If the board goes beyond of the WiFi network; will you be using the WiFi resources to write into the file? If you will not be using WiFi resources to write into the file I don't picture issues if you are going to send the entire file to another machine after writing the file.

                      2. If you need your project to be running for ten minutes and if you loose the connection between the devices you will receive only a part of the lectures. But if you first write all the lectures into the file and then you send it to your PC, I think you will have the safety of having a backup with all the data in the Edison

                       

                      Regards,

                      Charlie

                      • 8. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
                        Konradical

                        Hey CMata_Intel,

                         

                        I would be willing to share my code to figure this out. Currently though it's a mess as I'm testing out my sensors and other functionalities. Would you need all of it? It's written in C++ and the main part that writes to a file includes initializing a File object located in /home/root/data.txt and using it with a looping fprintf to add lines of data to the text file. I have not performed any tests of my own yet as far as memory usage. I'm unfamiliar with what to test for and how. I imagine it entails a deeper knowledge of Linux-Yocto. Would the memory the file is written to be a part of the 4GB of eMMC? Is this a viable substitute for storing data on an SD card that doesn't need removing?

                         

                        As for questions about connectivity, I'm developing a mobile system that will go in and out of range for acceptable communication. All wireless communication however will only occur when the system is back in range. Therefore, I think I'm safe on that portion of the project. I was worried that the device would need to remain constantly in range to not have to restart the network connection process.

                         

                        In summary of what I'm seeking to implement in my project, I want to know how much memory I have available so I can figure out how much data I can save and thus, calculate how long my system can gather data.

                         

                        Thanks for the help!

                         

                        Konrad

                        • 9. Re: Send tempertaure sensor data from one edison, and display the temperature on another edison using the LCD?
                          CMata_Intel

                          Hi Konrad,

                           

                          I did a small test. I used this code and ran the command python AnalogReadSerial.py > /home/root/file.txt I was able to created a file with a size higher than 100M, the partition that is affected is /home and has a size of 1.3G so that would be limit. If you want to change this size you must create a custom image and re-size the partitions of the board.

                           

                          Regards,

                          Charlie