11 Replies Latest reply on Jun 30, 2017 7:24 AM by FGT

    DHT11 C wrapper for Arduino Code

    milesZappa

      I am trying to create a C code wrapper to run the Arduino code for reading from DHT11 temperature and humidity sensor on a Galileo Gen 2.

       

      The Arduino code I am using is from this discussion: 

      DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one

       

      I was wondering how to run the program on demand rather than continuously as the Arduino code does.

        • 1. Re: DHT11 C wrapper for Arduino Code
          FGT

          milesZappa wrote:

           

          I am trying to create a C code wrapper to run the Arduino code for reading from DHT11 temperature and humidity sensor on a Galileo Gen 2.

           

          The Arduino code I am using is from this discussion:

          DHT workaround for Galileo and Galileo Gen2 using 2 pins instead of one

           

          I was wondering how to run the program on demand rather than continuously as the Arduino code does.

          My suggestion would be

          a) Check your sketch is running fine

          b) Change writing on Serial to write to a file

          c) Read the file

           

          Another method would be making a pipe, but I think the "file method" is good enough, mostly because reading this sensor would be needed in a rather low frequency.

           

          In case you already have the sketch running fine and do not know about how to do b) and c) just let me know and I'll try to help.

           

          HTH,

           

          Fernando.

          • 2. Re: DHT11 C wrapper for Arduino Code
            Intel Corporation
            This message was posted on behalf of Intel Corporation

            Hello milesZappa,

            I was wondering if you could check the suggestions provided by FGT.

            If you have any update or question, don’t hesitate to contact us.

            Regards,
            Andres V.

            • 3. Re: DHT11 C wrapper for Arduino Code
              JernejH

              Hi, Fernando.

               

              This post seems interesting and I was just wondering if it is possible to run Arduino code on demand when you are in Linux environment? Is it like some sort of bash script like method.

               

              For example:

               

              Command_to_run_arduini_code        arduino_file

               

              What would be command and how can we generate arduino_file?

               

              Kind regards

              Jernej

              • 4. Re: DHT11 C wrapper for Arduino Code
                FGT

                JernejH wrote:

                 

                Hi, Fernando.

                 

                This post seems interesting and I was just wondering if it is possible to run Arduino code on demand when you are in Linux environment? Is it like some sort of bash script like method.

                 

                For example:

                 

                Command_to_run_arduini_code arduino_file

                 

                What would be command and how can we generate arduino_file?

                 

                Kind regards

                Jernej

                 

                Step 1: generate the sketch binary, which is made in the Arduino IDE.

                Step 2: upload the sketch to the Intel Galileo, which is made in the Arduino IDE. The Arduino IDE uploads the sketch binary and automatically runs it. I'd suggest you rename the binary:

                             $ mv /sketch/sketch.elf /sketch/<the_name_you_want>

                             reboot the Intel Galileo so that the sketch stops running/using resources (or, alternatively, kill the sketch process)

                Step 3: run the sketch with <the_name_you_want>, e.g. in a command line

                             $ <the_name_you_want>

                 

                Remember all the sketches run forever, so take into account that once you run a sketch it does not end running unless you explicitly kill the process (e.g. $ killall <the_name_you_want>)

                 

                HTH,

                 

                Fernando.

                1 of 1 people found this helpful
                • 5. Re: DHT11 C wrapper for Arduino Code
                  JernejH

                  Hi, Fernando.

                   

                  This is very interesting. I have two follow-up questions>

                   

                  1. Is it possible to make sketch do something and then stop automatically? In the case of DHT, it could be used to write to a file and then terminate until the sketch is called again. Does Arduino code allow to be without void loop()?

                   

                  2. The other question I have is related to computing resources. If we assume, we have an Arduino sketch which reads from DHT11 sensor every 5 minutes( for example we use delay(300000) in void loop()). How would this impact available computing resources of another program we may run along side it. By this I mean if I have Arduino sketch running, and then I run a python script, will the python script run normally?

                   

                  Kind regards

                  Jernej

                  • 6. Re: DHT11 C wrapper for Arduino Code
                    FGT

                    JernejH wrote:

                     

                    Hi, Fernando.

                     

                    This is very interesting. I have two follow-up questions>

                     

                    1. Is it possible to make sketch do something and then stop automatically? In the case of DHT, it could be used to write to a file and then terminate until the sketch is called again. Does Arduino code allow to be without void loop()?

                     

                    2. The other question I have is related to computing resources. If we assume, we have an Arduino sketch which reads from DHT11 sensor every 5 minutes( for example we use delay(300000) in void loop()). How would this impact available computing resources of another program we may run along side it. By this I mean if I have Arduino sketch running, and then I run a python script, will the python script run normally?

                     

                    Kind regards

                    Jernej

                    Hi Jernej,

                     

                    About 1)

                    I think there is no way to make Arduino sketches without loop()... but in the case of Galileo maybe there are some alternatives in order to end the running the sketch. The ones I think possible are not very elegant, though...

                    a) The sketch itself may use system("killall sketch.elf")... I don't know if it's going to work, but you can give it a try.

                    b) Given you will start the sketch from another process (e.g. from bash command line) that same process may use killall to end the sketch. Adding a little bit of code, you will be able to verify that the file contains the DHT data and at that time end the sketch.

                     

                    About 2)

                    Having a sequence of a) DHT reading/s, b) save reading/s in file, c) delay(300000) will let the Linux OS mostly idle, since none of those tasks are particularly time or resource consuming. I think a python script will run almost normally.

                     

                    HTH,

                     

                    Fernando.

                    1 of 1 people found this helpful
                    • 7. Re: DHT11 C wrapper for Arduino Code
                      JernejH

                      Hi, Fernando.

                       

                      Thank you. I will test and then report back. However, I still have one more question. Is it possible to copy the sketch and to use it on multiple Galileos? If sketch has to be loaded on every Galileo manually, it could be very time-consuming.

                       

                      Kind regards

                      Jernej

                      • 8. Re: DHT11 C wrapper for Arduino Code
                        FGT

                        JernejH wrote:

                         

                        Hi, Fernando.

                         

                        Thank you. I will test and then report back. However, I still have one more question. Is it possible to copy the sketch and to use it on multiple Galileos?

                         

                        Identical Intel Galileo, identical hardware (e.g. DHT11): yes.

                         

                        Two details:

                        1) I'd evelop-test-etc. in one Intel Galileo and then copy the SD card.

                        2) Take into account that if you use the previous method and have fixed IP's in the same LAN then you'll have to set the specific IPs card-by-card.

                         

                        HTH,

                         

                        Fernando.

                        • 9. Re: DHT11 C wrapper for Arduino Code
                          JernejH

                          Hi, Fernando.

                           

                          I was able to run sketch like this:

                           

                          chmod +x <name_of_sketch>

                          ./<name_of_sketch> /dev/ttyS0> /dev/null 2>&1 &

                           

                          as described in https://communities.intel.com/thread/48813

                           

                          It works, I still have to copy the sketch from one image to another to see if that would work. I tested it with blink basic example, not the DHT example.

                           

                          Kind regards

                          Jernej

                          • 10. Re: DHT11 C wrapper for Arduino Code
                            milesZappa

                            Rather than writing a wrapper for the Arduino library, I modified it to work in C++ for Galileo Gen 2.

                            The code is attached.

                            • 11. Re: DHT11 C wrapper for Arduino Code
                              FGT

                              Thank you

                               

                              Why do you need/use mraa?

                               

                              Fernando.