10 Replies Latest reply on Mar 23, 2016 8:26 AM by DiegoV_Intel

    About the Delay() function in Arduino IDE

    Bcwong1

      Hello there,

       

      I would like to ask a question about the programming the Edison Arduino Board. The delay() function does not give the right amount of delay when I utilised it to program a PWM signal. For example, delay(1) gives a delay of 1.4 ms instead of 1ms.

       

      Thank you.

       

      Regards,

      Wong

        • 1. Re: About the Delay() function in Arduino IDE
          DiegoV_Intel

          Hi Bcwong1,

           

          Sometimes the timing functions are not 100% accurate. I recommend you to try a different approach avoiding to use the delay() function. The following example shows how to blink a LED without using the delay() function, I recommend you to check it and apply this approach in your application to see if you get better results: Arduino - BlinkWithoutDelay

           

          On the other hand, the following sketch might be helpful as well: Edison/setPWM_Edison.ino at master · MakersTeam/Edison · GitHub. This sketch sets the frequency and duty cycle of a PWM signal.

           

          Regards,

          Diego

          • 2. Re: About the Delay() function in Arduino IDE
            Bcwong1

            Yes I understood that the delay function can sometimes be inaccurate. I was able to obtain an accurate PWM by incorporating millis() and micros() into my program with some simple algorithms. I was just wondering if all the edison boards have the same problem with the delay function in arduino ide.

            • 3. Re: About the Delay() function in Arduino IDE
              DiegoV_Intel

              Hi Bcwong1,

               

              Could you share the sketch you used to test the delay() function? I can use my Edison to test the sketch and see if I get the same result as you.

               

              Regards,

              Diego

              • 4. Re: About the Delay() function in Arduino IDE
                Bcwong1

                Hello there,

                 

                I have made a simple sketch to produce a PWM signal using the delay() function.

                 

                 

                int led = 2;

                void setup() {

                  pinMode( led, OUTPUT );

                }

                 

                 

                void loop() {

                        digitalWrite( led,HIGH );

                        delay(2);

                        digitalWrite( led, LOW );

                        delay(2);

                }

                 

                On the oscilloscope, instead of getting the expected waveform of :

                i) 50 % duty cycle

                ii) 4ms period

                 

                I got a waveform which had a period of 4.8 ms.

                 

                Regards,

                Wong

                • 5. Re: About the Delay() function in Arduino IDE
                  DiegoV_Intel

                  Hi Bcwong1,

                   

                  I did the test and I got the same result as you. I got a waveform with a period of 4.826ms. Check the picture below:

                  test.jpg

                   

                  Regards,

                  Diego

                  • 6. Re: About the Delay() function in Arduino IDE
                    Bcwong1

                    Dear Diego,

                     

                    I have a question here. I have just bought the INTEL Grove indoor environment kit for Intel Edison. I downloaded the demo code from GitHub and thus uploaded the program to my Intel Edison with arduino breakout. The program is supposed to connect to my wifi network. However, it failed to do so. Surprisingly, when I removed the usb cable from the port, my Intel Edison got reset and the program ran anew. After a while, it got connected to the wifi network. I repeated the procedure a few times and the outcome was the same. Do you mind clearing my doubts on this matter? I have also attached the link to the source code for your convenience.

                    https://github.com/Seeed-Studio/Grove_Indoor_Environment_Demo

                     

                    Thank you.

                     

                    Regards,

                    Denver

                    • 7. Re: About the Delay() function in Arduino IDE
                      DiegoV_Intel

                      Hi Bcwong1,

                       

                      I've just tested the code you mentioned. I was able to upload it and get connected to the Wi-Fi network. However, when I unplugged the USB cable, the sketch was reset (only the sketch, the board remained running). I've seen this behavior before, but I couldn't find the thread where it was reported. Somehow, this behavior is "normal" (or expected). When the USB cable is unplugged, the Arduino sketch starts running again. I usually power my Edison only through the USB cable so I don't have this issue because there is no need to unplug the USB cable.

                       

                      There are some other known issues related to the Arduino sketches that have been reported with the latest image versions. I recommend you to use the image version 146 which is the most stable one in order to work with Arduino sketches. You can download it from the following link: Intel Edison Software Release 2.1

                       

                      Regards,

                      Diego

                      • 8. Re: About the Delay() function in Arduino IDE
                        Bcwong1

                        Dear Diego,

                         

                        As per what our discussion was about, I found out that my intel edison connected to the wifi network so seamlessly when I changed my network type to WPA instead of WPA2. I wonder what is the reason for this?

                         

                        Regards,

                        Denver

                        • 9. Re: About the Delay() function in Arduino IDE
                          Bcwong1

                          Dear Diego,

                           

                          I am a newbie of IOT. I wonder if you can recommend to me a website or a way of how I can simply control a LED light connected to my Edison without being connected to same network as my Edison. I know that the cloud service is involved here but is there a better and convenient approach?

                           

                          Regards,

                          Denver

                          • 10. Re: About the Delay() function in Arduino IDE
                            DiegoV_Intel

                            Hi Bcwong1,

                             

                            I'm not sure why you had issues connecting to the network when the network type WPA2. I've checked the network where my Edison is connected to and it is a WPA2 network, and I haven't had issues so far. However, if you are able to connect the Edison with no issues when the network type is WPA, I recommend you to keep doing it that way.

                             

                            Regarding your last question, you can access the Edison from a different network by setting up the port-forwarding feature in your router. There are several examples about accessing an Arduino from a different network and they explain how to set up the port-forwarding feature. This is related to the router itself, not the Edison, so the settings have to be done in the router. The following is a guide about accessing an Arduino UNO from another network: Accessing Arduino over internet - All. Even though the guide uses an Arduino UNO, the steps can be used with Edison. I hope this helps you.

                             

                            Regards,

                            Diego