I wanted my Arduino on the internet.
There are lots of new internet-friendly, Arduino-esque objects, such as the Spark Core. And those are cool.
But getting a plain ol’ Arduino Uno onto the web has been hard. I’ve tried repeatedly. And I have failed. Repeatedly.
This week, I gave it one last try. And I won.
Step 1: The Right Hardware
This win was made possible by a new (at least to me) wifi board from Adafruit.
Ideally, I would have used these longer pins, which allow you to stack boards and provide easy access to all of the Arduino connections. But didn’t have those, and I had a #MakeEveryWeek deadline, so I soldered some female header pins I had into a row provided on the board.
Also ideally, I would have used the version of the board with a built-in antenna. But Adafruit was out, and I was impatient, so I got a slightly different board and added antenna with a connecting cable.
Step 2: Connection Software
The tutorial also has Adafruit example software and install instructions. I downloaded the board’s library, plugged the Arduino into my laptop and fired up my Arduino software.
Once done, the example sketches appear in the Arduino desktop software under
File -> Examples -> Adafruit_CC3000.
The tutorial says it’s best to start with the “buildtest” example sketch, so I did, changing the placeholder values for my home wifi name and its password.
I sent the program to the Ardiuno, opened the serial monitor and took a deep breath. I had no expectation that it would work, mainly because I’ve spent long hours trying to get a different board to work.
To my surprise, this one connected on the first try.
Switching over to the WebClient sketch, to hit the Adafrut test site, and it worked, too. Amazing.
Step 3: Beam Up Live Data
Now for the real test: Could I actually upload data?
My destination was Sparkfun’s free data-capture system. I like the simplicity of the Sparkfun site, which allows you to add data just by hitting a URL. Check out the demo link on the first page of the site.
I wired up a thermistor to my Arduino, along with a 10K resistor, like this:
(Since the wifi shield is on top of the Arduino, my wires actually go to the equivalent spots the wifi board. Also, the red LED is irrelevant for this project.)
I modified the WebClient example code to tack a “temperature” value from the sensor onto the end of the base URL and to hit the Sparkfun site. (I didn’t bother to convert the sensor voltage levels to actual degrees.)
Soon, I was feeding data to the Sparkfun site!
Parts & Code
Here are the parts I used for this project:
- Ardunio Uno
- Adafruit wifi board
- Power supply
- Resistor (comes with the thermistor)
- Jumper wires
And here is a link to the code I used.
The webClient sketch uses the website host name (like data.sparkfun.com) to determine the host's IP address (like 18.104.22.168). That operation worked on my home wifi, but not with my mobile hotspot.
To demonstrate this as part of a workshop at the NICAR 2015 conference in Atlanta, I was going to need the hotspot.
The fix was to get the IP address from a terminal command like this ...
... and hardcode that address into the program like this:
ip = cc3000.IP2U32(54, 86, 132, 254);
Separately, I needed to combine the base URL and the temperature value into one variable that had to be type
char. My grasp of this isn’t firm, but the steps I took are described as comments in the code, if you’re interested. And let me know if you have a better way to do it!
#MakeEveryWeek is a challenge to myself to do just that for all of 2015. The original post on the idea is here, and the running list of projects so far is here.