Last Updated: January 6, 2021
Originally Published: June 6, 2019
Skill Level: Intermediate
Table Of Contents
- Introduction
- What Is Needed
- Background Information
- Adafruit IO Setup
- Building The Circuit
- Writing The Sketch
- Running And Testing The System
- Summary
Introduction
This tutorial will teach you how to use the Adafruit IO service to connect your Arduino Uno WiFi Rev2 to the outside world. A basic understanding of electronics and programming is expected along with some familiarity with the Arduino platform. If you are new to Arduino or would just like to refresh your knowledge, please see our Blink: Making An LED Blink On An Arduino Uno tutorial before proceeding with this one. In addition, this tutorial will use a solderless breadboard to build a simple circuit from a schematic diagram. The Core Electronics’ How to Use Breadboards, Science Buddies’ How to Use a Breadboard, and SparkFun’s How to Read a Schematic guides are good resources for learning how to translate a schematic to a breadboard.
The resources created for this tutorial are available on GitHub for your reference.
What Is Needed
- Linux, macOS, Or Windows Based Computer With A USB Port
- Arduino IDE
- Arduino Uno WiFi Rev2 (available on Arduino and SparkFun) With Compatible USB Cable
- Solderless Breadboard (available on Adafruit and SparkFun)
- Preformed Breadboard Jumper Wire Kit (available on SparkFun and CanaKit)
- 4 x Male-Male Jumper Wires (available on Adafruit and Arrow)
- Standard 5mm Red LED (available on Adafruit and SparkFun)
- 10 KΩ Linear Potentiometer (available on Adafruit and Sparkfun)
- 330 Ω Resistor (available on SparkFun and Amazon)
Background Information
In a previous article, Controlling An Arduino Uno WiFi Rev2 Or Arduino Uno With WiFi Shield From A Web Browser, I described how to create and run a web server on your Arduino Uno. This worked well for accessing your Arduino over a local network, but it was not visible over the internet. In order to extend this approach and allow your Arduino based server to be accessed over the internet, techniques such as port forwarding, external hosting, static IP addressing, or use of a Dynamic DNS service are required. Although doable, these techniques can be complicated, costly, or not very secure. For these reasons, they are not usually the best fit for hobbyists to access their Arduino devices over the internet.
This tutorial will instead utilize Adafruit’s Adafruit IO service to connect an Arduino to the outside world. Adafruit IO is free, secure, compatible across many development boards, and allows your device to be accessed privately or shared with others if you so choose. Upgrades are available, but the free tier gives us a lot to work with and may be all that you will ever need. Please see the Internet of Things for Everyone and Adafruit IO Basics learning guides for additional information on using the Adafruit IO service. There is even a general category listing that contains all kinds of Adafruit IO based projects.
My development system consists of the Arduino Uno WiFi Rev2 development board connected to a macOS based computer running the desktop Arduino IDE. If you are using a different Arduino board or computer setup, the vast majority of this tutorial should still apply, however, some minor changes may be necessary.
If you need assistance with your particular setup, post a question in the comments section below and I, or someone else, can try to help you.
Adafruit IO Setup
This project will connect an LED and a potentiometer to an Arduino that we will then associate with the Adafruit IO service for access and control. But before we do that, we need to configure our intentions on Adafruit IO.
If you don’t already have an Adafruit account, go to their website and sign up for one now. Please note that the Adafruit IO service does not require a separate account. Once your account is created, head over to the Adafruit IO site and sign in if you haven’t already.
Now, let’s create our feeds. Feeds hold the metadata and values associated with a particular component or sensor. They are unique to each individual source of data you send to the system. In our case, we need two feeds, one for a potentiometer and one for an LED.
Click Feeds within the toolbar at the top of the Adafruit IO site and then select view all from the pop-down window that appears. Click the New Feed button to create a new feed. In the Create a new Feed window that pops up, enter Potentiometer in the Name field along with an optional Description, such as Potentiometer value. Click the Create button when done. Then create a Red LED feed in the same fashion. The Key column in the Feeds listing displays the identifiers that we will use in our program. The keys of potentiometer and red-led are shown for the feeds we just created.
If you click on the individual feeds, you will be provided additional information and settings specific to that feed. The main area presents recent data in both visual and listing formats. Clicking the gear icons along the right allows you to change settings for your feed such as Privacy and Sharing controls.
Now we need a way to visualize and communicate with the feeds. Dashboards are used for this purpose. Widgets such as indicators, sliders, buttons, and charts are available.
Let’s create a dashboard for our project. Click Dashboards within the top toolbar and then select view all from the pop-down window. Click the New Dashboard button to create a new dashboard. In the Create a new Dashboard window that pops up, enter Arduino in the Name field along with an optional Description, such as Arduino based project. Feel free to name the dashboard something that has meaning to you. Click the Create button when done.
Now it is time to add our blocks (widgets) to visually interact with our feeds (data).
Click the Arduino dashboard we just created and you will be presented with a blank canvas. Click the gear pull-down menu in the upper right corner of the page and select Create New Block. A Create a new block pop-up window will appear with a table of available blocks we can choose. Hovering over the blocks will provide the name of the block. Select the Toggle block and the title of the window will change to Create a Toggle Block. Select the Red LED feed and then click the Next step button. In the Block settings window, enter Red LED Control in the Block Title field and leave the Button On Text and Button Off Text fields as ON and OFF respectively.
You can test the values that will be produced by clicking on the toggle switch on the right side of the window and watching the Test Value field change. Click the Create block button to finish creating your toggle block. Your block should now be displayed on the screen.
Next, create a Gauge block for the potentiometer and choose the Potentiometer feed. In the Block settings window, enter Potentiometer for the Block Title field, 0 for Gauge Min Value, 1023 for Gauge Max Value, 102 for Low Warning Value, and 921 for High Warning Value. The high and low values correspond to the top and bottom 10% of possible values. Leave the rest of the fields with their default values.
Test the gauge display by entering values in the Test Value field. For instance, enter a number below 102 and the color of the gauge will change from green to red. Click the Create block button to finish creating your gauge block. The Potentiometer will be displayed below the Red LED Control bock.
Select Edit Layout from the gear pull-down menu and you should see gear icons appear for each of the blocks. These gear icons can be clicked to edit the blocks’ settings that we set previously during creation. In addition, you can move and change the size of the blocks while in edit mode. Move a block by clicking somewhere in the block and dragging it to a new location. Resize a block by clicking the lower right corner of the block and adjust it to the size you want. Click the Save Layout button when finished to save your work.
Adafruit IO is now ready to interact with our Arduino board. Before we leave, we need to retrieve our account credentials that will be required for our sketch to access the system. Click the My Key link within the top toolbar and the YOUR ADAFRUIT IO KEY popup window will appear. Copy the Username and Active Key values shown for your account and save them for later use. Close the window when done.
Building The Circuit
Before connecting any circuitry to your Arduino board, disconnect it from power and your computer. This avoids accidental damage during wiring.
Place the components and wire up the circuit on a breadboard according to the schematic diagram shown below and then connect it to your Arduino Uno.
The circuit should look similar to the one shown below once completed.
Once the circuit is built, connect your Arduino to your computer with the USB cable.
Writing The Sketch
Adafruit IO does not yet officially support the Arduino Uno WiFi Rev2, but with assistance from the Adafruit team, I was able to get it working with a few workarounds. These will be mentioned as they are needed.
Let’s first install the required libraries. The first workaround we need to apply is to use Adafruit’s modified version of the standard WiFiNINA library. Uninstall Arduino’s official WiFiNINA library if it is installed. This simply entails closing the Arduino IDE if it is open and then deleting the WiFiNINA library from the default library location, typically located in the ~/Documents/Arduino/libraries directory. Once deleted, go to Adafruit’s GitHub repository for the modified WiFiNINA library and then download the library as a zip file. This is available by clicking on the green Code button within GitHub and then selecting Download ZIP. Next, open the Arduino IDE, select Sketch > Include Library > Add .ZIP Library… from the main menu, and then Choose your zip file from the pop-up window to install the library. Note, I am told that Adafruit plans to name this library differently in order to avoid these naming conflicts in the future.
Next, we need to install a few more libraries. These are standard libraries and can be installed in the traditional way through the Library Manager. Install the Adafruit IO Arduino, Adafruit MQTT Library, and ArduinoHttpClient libraries.
Note: Some recent versions (1.8.5 through 1.8.6) of the Arduino megaAVR Boards core library had a bug related to the use of F()
macros. These macros are used by the Adafruit IO Arduino and Adafruit MQTT Library libraries mentioned above which caused the sketch to not compile. This issue was fixed as of the 1.8.7 version of the Arduino megaAVR Boards core library.
All of our setup work is finally complete, so we can now move on to creating our program. Create and save a sketch named AIO_LED_Pot with the code shown below.
// AIO_LED_Pot - AIO_LED_Pot.ino // // Description: // Interfaces an LED and a potentiometer on an Arduino Uno WiFi Rev2 with the // Adafruit IO service. // Note: Must use Adafruit's modified version of the WiFiNINA library // (https://github.com/adafruit/WiFiNINA), define USE_AIRLIFT, and instantiate // AdafruitIO_WiFi with pin connections for Arduino Uno WiFi Rev2 compatability. // NOTE: The sketch sometimes gets stuck initially connecting to the service and // needs to be reuploaded. // // Circuit: // Red LED connected to pin D2. // 10K potentiometer connected to pin A0. // // Created by John Woolsey on 05/29/2019. // Copyright © 2019 Woolsey Workshop. All rights reserved. // Defines #define AIO_USERNAME "your_aio_username" #define AIO_KEY "your_aio_key" #define AIO_POT_FEED "potentiometer" #define AIO_REDLED_FEED "red-led" #define WIFI_SSID "your_wifi_ssid" #define WIFI_PASS "your_wifi_password" #define USE_AIRLIFT // required for Arduino Uno WiFi R2 board compatability // Libraries #include <AdafruitIO_WiFi.h> // Pin Mapping const byte RedLED = 2; const byte Pot = A0; // Constructors AdafruitIO_WiFi aio(AIO_USERNAME, AIO_KEY, WIFI_SSID, WIFI_PASS, SPIWIFI_SS, SPIWIFI_ACK, SPIWIFI_RESET, NINA_GPIO0, &SPI); AdafruitIO_Feed *potFeed = aio.feed(AIO_POT_FEED); AdafruitIO_Feed *redLEDFeed = aio.feed(AIO_REDLED_FEED); void setup() { // Pin configuration pinMode(RedLED, OUTPUT); // Serial bus initialization (Serial Monitor) Serial.begin(9600); while(!Serial); // wait for serial connection // Adafruit IO connection and configuration Serial.print("Connecting to Adafruit IO"); aio.connect(); // connect to Adafruit IO service while(aio.status() < AIO_CONNECTED) { Serial.print("."); delay(1000); // wait 1 second between checks } Serial.println(); Serial.println(aio.statusText()); // print AIO connection status // Set up message handler that calls function when messages are received redLEDFeed->onMessage(redLEDMessageHandler); // Synchronize current state redLEDFeed->get(); // request feed value (message) from AIO } void loop() { aio.run(); // keep client connected to AIO service int potValue = analogRead(Pot); potFeed->save(potValue); // send potentiometer value to AIO Serial.print("Potentiometer feed sent <- "); Serial.println(potValue); delay(5000); // limit AIO updates (30 per minute on free tier) } // Handles Red LED feed message received from AIO void redLEDMessageHandler(AdafruitIO_Data *data) { String value = data->toString(); // capture feed value from AIO Serial.print("Red LED feed received -> "); Serial.println(value); digitalWrite(RedLED, value == "ON" ? HIGH : LOW); }
Let’s take a look at some of the more interesting parts of the code.
Lines 21 and 22 hold your Adafruit IO credentials. Change these values to those representing your account.
Lines 23 and 24 are the feed keys (identifiers) we previously set up on the Adafruit IO site.
Lines 25 and 26 hold your WiFi network credentials. Change these values to those for your network.
Line 27 is the next required work-around. It simply defines USE_AIRLIFT
which is then checked internally by the Adafruit IO library for ESP32 module based WiFi configuration that is also used by our Uno.
Line 31 imports what we need from the Adafruit IO Arduino library. Note, the modified WiFiNINA library along with the other libraries are imported automatically and do not need to be explicitly imported separately.
Line 40 begins our configuration for connecting to the Adafruit IO service. We first initialize the service instance with the required account credentials and WiFi module pin settings using a name of aio
. This is the last workaround necessary to make our Arduino Uno WiFi Rev2 compatible with the Adafruit IO service. Typically, only the Adafruit IO credentials are necessary, i.e. AdafruitIO_WiFi aio(AIO_USERNAME, AIO_KEY)
. The next two lines then set up pointers to our feeds.
Lines 54-61 go through the process of connecting to the Adafruit IO service, aio.connect()
and aio.status()
, and then prints the status, aio.statusText()
, once connected.
Line 63 uses the onMessage()
function to set up a message handler that calls the redLEDMessageHandler()
function whenever a new message is received for the Red LED feed.
Line 66 uses the get()
function to request a feed update from the service for the Red LED feed. When the update is received, the redLEDMessageHandler()
function, defined in lines 80-84, is called that physically turns on or off the LED based on the current Red LED state as stored within the service. Specifically, line 81 captures the feed’s incoming data and then converts that data to a string with the toString()
function. Other data type helpers, such as isTrue()
, toBool()
, toInt()
, toFloat()
, toPinLevel()
, etc., are also available.
Line 71 executes the aio.run()
function on each iteration of the loop in order to keep us connected to the Adafruit IO service.
Line 73 sends our potentiometer value to the AIO service using the save()
function.
Line 75 delays execution for 5 seconds for each loop iteration. A delay is required so as not to flood the Adafruit IO service with requests. The free tier only allows 30 updates per minute, but I am being conservative by using 5 instead of the minimum 2 second delay.
If there is something that needs further explanation, please let me know in the comment section and I will try to answer your question.
Running And Testing The System
Now that our circuit is built and our software is written, it is time to run and test our project.
Open the Serial Monitor window (Tools > Serial Monitor) so that we can see the sketch’s output. Upload (Sketch > Upload) the sketch to the board and you should see Connecting to Adafruit IO printed to the screen followed shortly by Adafruit IO connected.
I don’t know if it is the modified WiFiNINA library or my implementation, but sometimes the sketch gets stuck and needs to be re-uploaded to the board. This occurs when you initially see Connecting to Adafruit IO………. (dots continuing) without Adafruit IO connected. ever being printed.
Once the sketch is running, go back to the Adafruit IO website and open the Arduino dashboard. Click the Red LED Control switch (Toggle) and you should see the red LED light up on your breadboard. Yipee! Turn it on and off a few times to verify everything is working properly.
Next, slowly turn the potentiometer on your breadboard back and forth. You should see the Potentiometer Gauge on Adafruit IO displaying the new values. If you turn it to the extremes (values below 102 or above 921), you will see the gauge color change from green to red alerting you that the value is either below the Low Warning Value or above the High Warning Value settings we set earlier. Keep in mind the values will only update every 5 seconds due to the delay we added to the end of the loop()
function in the sketch.
Now that our project has data we created during testing, go back and look at the feed data on Adafruit IO. Click Feeds in the top toolbar then click the Potentiometer feed. You will see your recent data points along with when they were created. Do the same for the Red LED feed.
Before we end, now would be a good time to upload the BareMinimum sketch (File > Examples > 01.Basics > BareMinimum) to reset all pins back to their default states.
Keep in mind we are still using Adafruit’s modified version of the WiFiNINA library. You may want to reinstall Arduino’s official WiFiNINA library at this time to get you back to the standard library setup.
Summary
In this tutorial, we learned how to use the Adafruit IO service to connect your Arduino Uno WiFi Rev2 to the outside world. We configured feeds for each of our connected electrical components and created a dashboard for interacting with those components on the Adafruit IO website. We wrote a sketch that communicates the states of our components with the Adafruit IO service and then used the service to interact with our components.
The final source code and schematic used for this tutorial are available on GitHub.
Don’t forget to check out all of the Adafruit IO based learning guides available by Adafruit.
Thank you for joining me on this journey and I hope you enjoyed the experience. Please feel free to share your thoughts in the comments section below.
[…] WoolseyWorkshop published an in-depth tutorial about connecting an Arduino Uno WiFi Rev2 to Adafruit.io. […]
[…] Do you have an Arduino WiFi Rev2? If so, we have good news! The latest Adafruit IO Arduino library is compatible with the Arduino WiFi Rev2. WoolseyWorkshop’s blog posted an in-depth tutorial about connecting this board to the outside world. – WoolseyWorkshop […]
Thank for this guide, it probably saved me a bunch of time getting a baseline setup going.
Btw., I noticed a limitation in the Adafruit IO library causing decimal values to be fail to publish. Fixed here: https://github.com/adafruit/Adafruit_IO_Arduino/pull/97
You are welcome, and thanks for the update.
Hi,
Trying your guido to get my arduino wifi Rev2 to work with a DHT22 sensor. Always gives me following error: exit status 1
Fout bij het compileren voor board Arduino Uno WiFi Rev2
Used a working sketch with the DHT22 sensor, adapted it accordingly to work with the IO streamer (aio) but somehow it gets stuck.
I can provide the code if you would like to help.
Thanks for the detailed guide!
I would first suggest turning on verbose output during compilation to see if you can get more information on what may be going wrong. I can take a quick look at your code if you want to send it to me via the Contact page or post a link to where I can retrieve it. I would also suggest posting your issue to the “Internet of Things: Adafruit IO” forum at Adafruit Forums if you believe it is Adafruit IO related or to the “Arduino WiFi Rev2” forum at Arduino Forums if you believe it is board related.
I researched the issue and it appears the 1.8.5 version of the megaAVR board changes the way the F (flash based strings) macro works, which is being used by the various libraries being included. If you revert back to the 1.8.4 version, your program should compile.
Hi,
Worked like a charm!
Thank you.
Regards,
Stijn
Hi John,
thanks for this detailed topic. Very interesting and usefull. I have the Arduino uno Wifi rev2 so I tried to programm it with your code. But I have issues to connect to IO Adafruit service (I guess?). In the series monitor window I am stuck with “Connecting to Adafruit IO……..” which means my uno wifi does not connect to Adafruit. I can see it connected on my wifi but I am now stuck. Of course I tried many time to dowload again the programm as you mentionned. You have to know that I had to downgrade the MegaAVR board from v1.8.5 to v1.8.4 as you said in comments.
I don’t know how to investigate more than that. It would be very helpfull if you can help me.
Thanks
I have researched that issue multiple times and have not been able to determine the cause. It has been a while since I ran this code, so I retested my setup and it is now failing almost half the time. I suggest replacing the
Serial.print(".");
line within thewhile(aio.status() < AIO_CONNECTED)
loop withSerial.print("Status: "); Serial.println(aio.statusText());
to provide the actual network status that perhaps you can explore. I get the "Network connection failed." message each time mine fails. That is all I know to offer at this time.I am using the following versions for my setup.
Arduino IDE: 1.8.10
Arduino megaAVR board library: 1.8.4
Adafruit IO Arduino library: 3.3.1
Adafruit WiFiNINA library: commit 3f251f0
For anyone wondering why this is happening, I’ve managed to solve the problem by adding the SSL certificate to the Arduino board. Just follow the instructions for adding the SSL certificate from this link: https://learn.adafruit.com/adafruit-feather-m0-wifi-atwinc1500/updating-ssl-certificates
Thank you. Much appreciated.
Well explained, much appreciated!
In line 40, you specify SPIWIFI_SS, SPIWIFI_ACK, SPIWIFI_RESET, NINA_GPIO0 and &SPI but I cannot find the place where these are defined in your code in the first place.
I am glad to hear you liked the article.
The
SPIWIFI_SS
,SPIWIFI_ACK
,SPIWIFI_RESET
,NINA_GPIO0
pin constants are defined in the Arduino pins header file (pins_arduino.h) for the specific core package. For instance, the pins file used for the Arduino Uno WiFi Rev2 board is located on my Mac in the ~/Library/Arduino15/packages/arduino/hardware/megaavr/1.8.6/variants/uno2018/ directory.&SPI is the reference to the SPI class defined in Arduino’s base SPI library (SPI.h). That library is included when the top level Adafruit IO library (AdafruitIO_WiFi.h) is included in the sketch, specifically from the AdafruitIO_AIRLIFT.h header within that library.
Hope this helps. Let me know if something needs further explanation.
Hi
Thanks for detailed explination , I followed steps one by one but got compliation error as below, can you help ?
C:\Users\imad\Documents\Arduino\libraries\Adafruit_IO_Arduino\src\AdafruitIO.cpp:290:12: note: in expansion of macro ‘F’
return F(“Unknown status code”);
^
Multiple libraries were found for “AdafruitIO_WiFi.h”
Used: C:\Users\imad\Documents\Arduino\libraries\Adafruit_IO_Arduino
Multiple libraries were found for “Adafruit_MQTT.h”
Used: C:\Users\imad\Documents\Arduino\libraries\Adafruit_MQTT_Library
Multiple libraries were found for “ArduinoHttpClient.h”
Used: C:\Users\imad\Documents\Arduino\libraries\ArduinoHttpClient
Multiple libraries were found for “SPI.h”
Used: C:\Users\imad\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.6\libraries\SPI
Multiple libraries were found for “WiFiNINA.h”
Used: C:\Users\imad\Documents\Arduino\libraries\WiFiNINA-master
exit status 1
Error compiling for board Arduino Uno WiFi Rev2.
I suspect you are using an Arduino WiFi Rev2 board or something similar. The megaAVR core package for that family of devices changed, as of 1.8.5 causing an F macro issue in various libraries. Revert the Arduino megaAVR Boards package version back to 1.8.4 (Main Menu > Tools > Board: > Board Manager…) and that should resolve the issue. Please see earlier comments as well for more context.
Hello. I have arduino uno wifi rev2 and i run the code normally and in the serial monitor it shows the message “Connecting to Adafruit IO……” without any more progress after about 10 minutes. the only deiiference is that i dont have potensiometer for now (i am going to buy soon) Could this be a problem? thank you!
I don’t believe the connection issue is related to you not using a potentiometer. This issue has been known for a while. Please try uploading your sketch a few times until it connects. Also, take a look at some of the other comments that have been posted about this issue for some guidance. Jort stated on August 25, 2020 that he/she had solved the problem and provided a solution.
This code no longer compiles.
Thanks for letting me know; I will take a look.
I don’t know the error(s) you received, but I suspect they are due to the F() macro.
#define F(str) (str)
return F("Idle. Waiting for connect to be called...");
The megaAVR core library, used for the Arduino Uno WiFi Rev2, made a change in version 1.8.5 that broke any code using F() macros. I submitted a ticket (https://github.com/arduino/ArduinoCore-megaavr/issues/62) to Arduino for this back in December of 2019, but it is still being worked on. For now, I suggest reverting the megaAVR core library to version 1.8.4 and that should resolve your compiling issue.
Also, please verify you are using Adafruit’s version of the WiFiNINA library as mentioned in the article.
By the way, I updated the article to formally include this information so as not to further confuse new readers like yourself.
Thank you for reading the article and for letting me know about the compiling issue.
Hi John. Great article!! Thanks so much for taking the time. After working through all the details, I have the sketch working perfectly. However, as I work the approach into a project I am working on, I have run into a problem. I have utilized a MAX31865 PT100 RTD temp sensor amplifier, which utilizes SPI (w/ library Adafruit_MAX31865.h). With a call to the library…
Adafruit_MAX31865 thermo = Adafruit_MAX31865(13);
AND when I include an AIO save command…
EvapTempFeed->save(“Test”);
the sketch will no longer connect to AIO. If I take either of these out of the sketch, it connects as intended. I have tried connecting the amp via both software serial (pins 10-13) and hardware serial (via the ICSP header). The results in both cases are the same. It compiles, no errors, but it simply will not connect.
Can you offer any advice?
Thanks!
I’m glad you enjoyed the article.
I do see a couple of problems with the code you provided. First of all, use pin 10, instead of 13, for the SPI CS pin since pin 13 is used for the SPI clock.
Adafruit_MAX31865 thermo = Adafruit_MAX31865(10);
Second, you should be saving/sending a number, not text, to the AIO service. Try testing with an integer, e.g. 2, 34, etc., without quotes, first to make sure the service is getting data. Once that is verified, try sending the actual temperature value.
EvapTempFeed->save(2);
EvapTempFeed->save(temperatureValue);
Hope this works for you.
Hi John,
Thanks for the quick response, very kind of you. I tried using pin 10 for SPI cs, then also pins 9, 11, and 12. None of those worked. But then pin 4, and it worked. Not sure why this is, but I’ll run with it. Thanks!!
That is great news. Glad to hear it is working for you.
Hello John, et al.
On my Win7 Pro box I had no success with this project. Just bought my Uno Wifi Rev2 about 1 month ago (current date: 12/19/2020), and running the latest IDE. I followed your description to the letter. By the way it was written in such a format a 3rd grader could follow it. I’m not an C++ or Arduino guru but been around in IT for 35 years ALL the way back to DOS days, so I’m really not new to computer science, but I’m scratching my head what I could’ve missed. We all know the definition of insanity: do the same thing over and over and get the same results. 😉 I’m wondering if something changed with Adafruit’s services which is causing the sketch to not be friendly and connect. My Uno Wifi is Tx’ing but no Rx’ing. Any thoughts or help would be nice – thanks!
Spencer M.
When you say your “Uno Wifi is Tx’ing but no Rx’ing”, do you mean that data is properly being sent to Adafruit, but you are not receiving commands, i.e. turning the LED on and off? Are you seeing your potentiometer values in the Adafruit service?
There are all kinds of things that can go awry, from the code and libraries, IDE options, Adafuit’s service, to even a bad Arduino board. Let’s begin by making sure the code looks good. Copy the code from the AIO_LED_Pot.ino program listing in the article and compare (diff) it to your program. Let me know how that goes.
John, I didn’t see how to reply to your response.
Still no success.
I see the Tx light constantly flashing and do not ever see the Rx light flashing. I presume if the Rx light flashes it would mean it’s connected to the Adafruit IO services, but it never does. I re-uploaded many times. I only see the Connecting to Adafruit IO following by the dots. The aio.status never changes to CONNECTED. I diff’d what I have in my IDE and it’s the same as the sketch from this article with the exceptions of the obvious like username, key, ssid. etc. I do not get any compilation errors; however lately I’ve been seeing this message after every compilation: ==> “This behaviour is deprecated and will result in an error in future version
You probably want to use 0xcd instead of 0xc9 (double check with your datasheet first).
“. I followed your article at least five times starting over from the beginning. What thing I don’t understand is why the schematic diagram shows a positive wire from the pot side of the breadboard to the LED side. I can’t figure out what would be using it. I have the cathode of the LED jumper’d to the negative. Sorry to be a bother; I’m just one that hates to throw in the towel. I also deleted and recreating my feeds and dashboard a few times; I cut/pasted my key i(from Adafruit) nto the sketch so I know it’s right
Could I have some library installed that is causing a conflict that is unbeknownst to me?
Thank you John.
Ah, you are getting stuck at the dots. This is probably not your fault. I don’t know why, but some people seem to get stuck at the “Connecting to Adafruit IO” portion of the sketch. Perhaps there is some strange combination of network configurations/libraries/events that cause issues with connecting to the Adafruit IO service. I have not been able to figure anything out on my end, but I also don’t have many problems in connecting. In an earlier comment, Jort says he solved it by adding an SSL certificate to the Arduino board and provided a link to how to accomplish that. Perhaps you can try that and see if it helps. If you go through that process, note that the FirmwareUpdater sketch location for the Arduino Uno WiFi Rev2 board is at Main Menu > File > Examples > WiFiNINA > Tools > FirmwareUpdater.
I also see the deprecated notice for the fuse, but it has not caused me any issues that I am aware of.
When you say “positive wire from the pot side of the breadboard to the LED side”, are you referring to the image? The two small red wires are just connecting to the positive and negative rails on both sides of the breadboard. Yes, the LED cathode should be connected to ground.
Let me know how it goes.
Hi John. Thank you for this concise tutorial!
I have hooked up an Uno Wifi Rev2 using a Grove Base Shield with a Grove sensor and it works like a charm. A downgrade of the Arduino MegaAVR Boards library seems to be obsolete now. I am using the current version 1.8.7 without any problems.
One minor issue: when I switch the Arduino off and on, then the sketch does not start properly. Switching it off and on the second time works for some reason.
That is great news. I saw that the Arduino team had closed the ticket and the fix would be in the next release, I just didn’t know the release occurred already. Thanks for sharing.
Hi,
Great writeup!
Unfortunately, I seem to be having an issue whereby my code is failing when I try to include more than 5 Adafruit ‘feeds’. When I remove my most recent feed to bring it back to 5 then the code compiles and uploads. However, when I include a 6th feed, the code compiles and uploads but the Arduino UNO WiFi Rev2 board ‘L’ LED just sits their blinking very quickly and no operation of the code is present.
Is this a known issue, or would you possibly be able to provide any guidance on what is going on?
Cheers,
George C
I’m glad you liked it.
I have not heard of that issue before. I believe that Adafruit originally limited their free plan to 5 feeds. Maybe there is something left in some code somewhere that is limiting you to that original number. To the best of my knowledge, the Uno WiFi Rev2 board is still not officially supported.
Perhaps you can add a few debugging messages to determine where the sketch is getting stuck and then we can troubleshoot further from there.
Thanks for the quick reply.
I’m not exactly sure how to debug. The code works when I have 5 feeds, but move to 6 or more the arduino LED blinks (maybe 5/sec) and nothing happens – no serial comm’s etc….
From looking online at other issues, it “potentially” points to a bootloader issue. But I cannot see how having one extra line of code for an extra feed would cause such an issue.
I imagine that you are correct with something in one of libraries limiting the number of feeds to 5. Could you suggest where I could begin looking for such a limit?
Many thanks again.
George
Since you describe your issue as just adding a 6th feed, I will create a test sketch and try to debug the issue over the next few days and get back to you.
Thank you very much. If you could let me know any details of what you find that would be great.
I’ll keep looking myself in the meantime as well.
Many thanks
I was able to confirm the issue you are seeing when adding the 6th feed.
While researching the issue, I found several instances of others having similar issues, not just with Adafruit IO but with the number of WiFi connections in general. It appears there is generally a limit of 5 active TCP connections when using WiFi. I could not determine where this is being set while perusing the code of the various libraries, but my guess is that this limit is there for a reason, and even if we tried to override it, we may run into other issues. I even tried to create a workaround using two AIO instances, but that did not work either.
I’m sorry I was unable to find a solution for you.
No problem, thanks again for your help. My main concern was that I had an issue in my code, so it’s a relief to hear that you could confirm the fault.
Hi again,
Just ben playing around with the code more, as was getting stuck at the “Connecting to Adafruit IO……” a fair bit which was annoying.
I believe a simple fix could be to include aio.connect(); within the while loop (Line 56 of the above example). Since implementing this I have not had a single connection issue. I have also tested this by turning my WiFi router off and on while the board was attempting to connect, and after the router came back online the board connected.
Please let me know if there is a specific reason why I should NOT do this, but it does appear to make sense, as once in the while loop, the board was never attempting to “reconnect” in the original code.
Cheers,
George
You shouldn’t need it, but there is obviously something going wrong there every once in a while. If it works for you, I don’t see any reason why you shouldn’t add it. It makes logical sense to include it. Good find and thanks for letting us know!