Skip to content

Commit

Permalink
add io home series sketch #1 (#65)
Browse files Browse the repository at this point in the history
add io home series sketch #1

bump the library version for a new master release

add sketch dependencies for travis build
  • Loading branch information
brentru authored Aug 27, 2018
1 parent 203cf51 commit 3a05cfc
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ before_install:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)

install:
- arduino --install-library "Adafruit IO Arduino","Adafruit MQTT Library","ArduinoHttpClient","Adafruit Unified Sensor","Adafruit NeoPixel","DHT sensor library"
- arduino --install-library "Adafruit IO Arduino","Adafruit MQTT Library","ArduinoHttpClient","Adafruit Unified Sensor","Adafruit NeoPixel","DHT sensor library", "Adafruit BME280 Library", "Adafruit SGP30 Sensor"

script:
# build ESP8266 target
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

44 changes: 44 additions & 0 deletions examples/io_home_series/neopixel_and_thermometer/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/************************ Adafruit IO Config *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME "your_username"
#define IO_KEY "your_key"

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
// - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
// - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
// - Feather HUZZAH ESP32 -> https://www.adafruit.com/product/3405
// - Feather M0 WiFi -> https://www.adafruit.com/products/3010
// - Feather WICED -> https://www.adafruit.com/products/3056

#define WIFI_SSID "your_ssid"
#define WIFI_PASS "your_pass"

// comment out the following two lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);


/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
// - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);


/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
// - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Adafruit IO House: Lights and Temperature
//
// Learn Guide: https://learn.adafruit.com/adafruit-io-house-lights-and-temperature
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Brent Rubell for Adafruit Industries
// Copyright (c) 2018 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

// include the NeoPixel library
#include "Adafruit_NeoPixel.h"

// include the si7021 library
#include "Adafruit_Si7021.h"
/************************ Example Starts Here *******************************/

// pin the NeoPixel strip is connected to
#define STRIP_PIN 12
// pin the NeoPixel Jewel is connected to
#define JEWEL_PIN 2

// amount of neopixels on the NeoPixel strip
#define STRIP_PIXEL_COUNT 34
// amount of neopixels on the NeoPixel jewel
#define JEWEL_PIXEL_COUNT 7

// type of neopixels used by the NeoPixel strip and jewel.
#define PIXEL_TYPE NEO_GRB + NEO_KHZ800

// main loop() delay, in seconds
#define TEMP_DELAY 7

// Temperature and Humidity: Si7021 Sensor
int temperatureData;
int humidityData;

// initalize neopixel strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(STRIP_PIXEL_COUNT, STRIP_PIN, PIXEL_TYPE);
// initalize neopixel jewel
Adafruit_NeoPixel jewel = Adafruit_NeoPixel(JEWEL_PIXEL_COUNT, JEWEL_PIN, PIXEL_TYPE);

// initalize the sensor object
Adafruit_Si7021 sensor = Adafruit_Si7021();

// set up the Adafruit IO feeds
AdafruitIO_Feed *indoorLights = io.feed("indoor-lights");
AdafruitIO_Feed *outdoorLights = io.feed("outdoor-lights");
AdafruitIO_Feed *humidity = io.feed("humidity");
AdafruitIO_Feed *temperature = io.feed("temperature");

void setup() {

// start the serial connection
Serial.begin(115200);

// wait for serial monitor to open
while(! Serial);

// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();

// subscribe to lighting feeds and register message handlers
indoorLights->onMessage(indoorLightHandler);
outdoorLights->onMessage(outdoorLightHandler);


// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(".");
delay(500);
}

// we are connected
Serial.println();
Serial.println(io.statusText());

// initalize the Si7021 sensor
if (!sensor.begin()) {
Serial.println("Did not find Si7021 sensor!");
while (true);
}
Serial.println("Si7021 sensor set up!");

// initalize the neopixel strip and jewel.
strip.begin();
jewel.begin();

// set all neopixels on the strip and jewel to `off`.
strip.show();
jewel.show();
}

void loop() {
// io.run(); is required for all sketches.
// it should always be present at the top of your loop
// function. it keeps the client connected to
// io.adafruit.com, and processes any incoming data.
io.run();

temperatureData = sensor.readTemperature() * 1.8 + 32;
humidityData = sensor.readHumidity();


Serial.print("-> Sending Temperature to Adafruit IO: ");
Serial.println(temperatureData);
Serial.print("-> Sending Humidity to Adafruit IO: ");
Serial.println(humidityData);

// send the state of the feed to adafruit io
temperature->save(temperatureData);
humidity->save(humidityData);

// delay the loop to avoid flooding Adafruit IO
delay(1000*TEMP_DELAY);
}

void indoorLightHandler(AdafruitIO_Data *data) {
Serial.print("-> indoor light HEX: ");
Serial.println(data->value());

long color = data->toNeoPixel();

// set the color of each NeoPixel in the jewel
for(int i=0; i<JEWEL_PIXEL_COUNT; ++i) {
jewel.setPixelColor(i, color);
}
// 'set' the neopixel jewel to the new color
jewel.show();
}

void outdoorLightHandler(AdafruitIO_Data *data) {
Serial.print("-> outdoor light HEX: ");
Serial.println(data->value());

long color = data->toNeoPixel();

// set the color of each NeoPixel in the strip
for(int i=0; i<STRIP_PIXEL_COUNT; ++i) {
strip.setPixelColor(i, color);
}
// 'set' the neopixel strip to the new color
strip.show();
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit IO Arduino
version=2.7.16
version=2.7.17
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Arduino library to access Adafruit IO.
Expand Down

0 comments on commit 3a05cfc

Please sign in to comment.