Hardware Reference
In-Depth Information
Building the Arduino sketch
At this point, we have working sensors on our Arduino board, and we also have an account
on Xively that is ready to receive some data. We are now going to write the sketch that will
connect to your Wi-Fi network and upload data automatically to your Xively account.
We are now going to write down the code in the Arduino IDE. We start by including the
correct libraries as shown:
#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "DHT.h"
Then, just as in Chapter 2 , Control Lights from Your Phone or Tablet , we need to define on
which pins the CC3000 board is connected:
#define ADAFRUIT_CC3000_IRQ 3
#define ADAFRUIT_CC3000_VBAT 5
#define ADAFRUIT_CC3000_CS 10
And define the pin and type of the DHT sensor:
#define DHTPIN 7
#define DHTTYPE DHT11
We can now create the instance of the CC3000 chip:
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS,
ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);
Now, you will have a few things to modify in the sketch. The first couple of things are the
SSID and password of your Wi-Fi network:
#define WLAN_SSID "yourSSID"
#define WLAN_PASS "yourPassword"
Now, you need to enter some information concerning Xively that we got earlier in this
chapter. Modify these lines so that you use your own API key and feed ID:
Search WWH ::




Custom Search