Skip to content

Commit

Permalink
Bumping version to 1.2.0
Browse files Browse the repository at this point in the history
Added support for WiFi101 shield
Added support for MKR1000
Removed support for the original WiFi shield
Fixed a bug in the Cheerlights example
Removed code related to Particle device.  There is a separate library for Particle.
  • Loading branch information
jasontwinters authored Aug 24, 2016
1 parent 69ac859 commit 9910c2f
Show file tree
Hide file tree
Showing 26 changed files with 754 additions and 1,870 deletions.
117 changes: 51 additions & 66 deletions examples/CheerLights/CheerLights.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,64 @@
On Spark core, the built in RGB LED is used
Visit http://www.cheerlights.com for more info.
ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping
systems that collect, analyze, and react to their environments.
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and
analyze live data streams in the cloud.
Copyright 2015, The MathWorks, Inc.
Copyright 2016, The MathWorks, Inc.
Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed.
See the accompaning licence file for licensing information.
*/

#ifdef SPARK
#include "ThingSpeak/ThingSpeak.h"
#else
#include "ThingSpeak.h"
#endif
#include "ThingSpeak.h"


// ***********************************************************************************************************
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported.
// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield)
// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below
// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported.
// With Yun, the default is that you're using the Ethernet connection.
// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below
// ***********************************************************************************************************
//#define USE_WIFI_SHIELD

//#define USE_WIFI101_SHIELD
//#define USE_ETHERNET_SHIELD

#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266)
#error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD"
#endif


// Make sure that you put a 330 ohm resistor between the arduino
// pins and each of the color pins on the LED.
int pinRed = 9;
int pinGreen = 6;
int pinBlue = 5;
int pinBlue = 3;

#ifdef ARDUINO_ARCH_AVR
#ifdef ARDUINO_AVR_YUN
#if defined(ARDUINO_AVR_YUN)
#include "YunClient.h"
YunClient client;
#else

#ifdef USE_WIFI_SHIELD
#include <SPI.h>
// ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes
// If you get "multiple definition of `WiFi'" -- comment out the line below.
#include <WiFi.h>
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
char pass[] = "<YOURPASSWORD>"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#else
#if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266)
// Use WiFi
#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFi.h>
#else
// Use wired ethernet shield
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
#include <WiFi101.h>
#endif
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
char pass[] = "<YOURPASSWORD>"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#elif defined(USE_ETHERNET_SHIELD)
// Use wired ethernet shield
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
#endif
#endif

#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFi.h>
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
char pass[] = "<YOURPASSWORD>"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#endif

#ifdef SPARK
TCPClient client;
#endif


/*
This is the ThingSpeak channel number for CheerLights
Expand All @@ -80,32 +72,29 @@ int pinBlue = 5;
unsigned long cheerLightsChannelNumber = 1417;

void setup() {
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
#ifdef ARDUINO_AVR_YUN
Bridge.begin();

#ifdef ARDUINO_AVR_YUN
Bridge.begin();
#else
#if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000)
WiFi.begin(ssid, pass);
#else
#if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266)
WiFi.begin(ssid, pass);
#else
Ethernet.begin(mac);
#endif
Ethernet.begin(mac);
#endif
#endif

ThingSpeak.begin(client);

#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
pinMode(pinRed,OUTPUT);
pinMode(pinGreen,OUTPUT);
pinMode(pinBlue,OUTPUT);
#endif
pinMode(pinRed,OUTPUT);
pinMode(pinGreen,OUTPUT);
pinMode(pinBlue,OUTPUT);
}

void loop() {
// Read the latest value from field 1 of channel 1417
String color = ThingSpeak.readStringField(cheerLightsChannelNumber, 1);
setColor(color);

// Check again in 5 seconds
delay(5000);
}
Expand Down Expand Up @@ -137,16 +126,12 @@ void setColor(String color)
{
// When it matches, look up the RGB values for that color in the table,
// and write the red, green, and blue values.
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
analogWrite(pinRed,colorRGB[iColor][0]);
analogWrite(pinGreen,colorRGB[iColor][1]);
analogWrite(pinBlue,colorRGB[iColor][2]);
#endif
#ifdef SPARK
RGB.control(true);
RGB.color(colorRGB[iColor][0], colorRGB[iColor][1], colorRGB[iColor][2]);
#endif

analogWrite(pinRed,colorRGB[iColor][0]);
analogWrite(pinGreen,colorRGB[iColor][1]);
analogWrite(pinBlue,colorRGB[iColor][2]);

return;
}
}
}
}
115 changes: 54 additions & 61 deletions examples/ReadLastTemperature/ReadLastTemperature.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,59 @@
https://thingspeak.com/channels/12397 on ThingSpeak, and prints to
the serial port debug window every 30 seconds.
ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for building
systems that collect, analyze, and react to their environments.
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and
analyze live data streams in the cloud.
Copyright 2016, The MathWorks, Inc.
Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed.
See the accompaning licence file for licensing information.
*/

#ifdef SPARK
#include "ThingSpeak/ThingSpeak.h"
#else
#include "ThingSpeak.h"
#endif
#include "ThingSpeak.h"


// ***********************************************************************************************************
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported.
// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield)
// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below
// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported.
// With Yun, the default is that you're using the Ethernet connection.
// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below
// ***********************************************************************************************************
//#define USE_WIFI_SHIELD
#ifdef ARDUINO_ARCH_AVR

#ifdef ARDUINO_AVR_YUN
//#define USE_WIFI101_SHIELD
//#define USE_ETHERNET_SHIELD


#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266)
#error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD"
#endif


#if defined(ARDUINO_AVR_YUN)
#include "YunClient.h"
YunClient client;
#else

#ifdef USE_WIFI_SHIELD
#include <SPI.h>
// ESP8266 USERS -- YOU MUST COMMENT OUT THE LINE BELOW. There's a bug in the Arduino IDE that causes it to not respect #ifdef when it comes to #includes
// If you get "multiple definition of `WiFi'" -- comment out the line below.
#include <WiFi.h>
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
char pass[] = "<YOURPASSWORD>"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#else
#if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266)
// Use WiFi
#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFi.h>
#else
// Use wired ethernet shield
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
#include <WiFi101.h>
#endif
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
char pass[] = "<YOURPASSWORD>"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#elif defined(USE_ETHERNET_SHIELD)
// Use wired ethernet shield
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
EthernetClient client;
#endif
#endif

#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFi.h>
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
char pass[] = "<YOURPASSWORD>"; // your network password
int status = WL_IDLE_STATUS;
WiFiClient client;
#endif

// On Particle Core, Photon, and Electron the results are published to the Particle dashboard using events.
// Go to http://dashboard.particle.io, click on the logs tab, and you'll see the events coming in.
#ifdef SPARK
TCPClient client;
#endif

/*
This is the ThingSpeak channel number for the MathwWorks weather station
Expand All @@ -79,33 +71,34 @@ unsigned long weatherStationChannelNumber = 12397;
unsigned int temperatureFieldNumber = 4;

void setup() {
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
Serial.begin(9600);
#ifdef ARDUINO_AVR_YUN
Bridge.begin();

Serial.begin(9600);
#ifdef ARDUINO_AVR_YUN
Bridge.begin();
#else
#if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000)
WiFi.begin(ssid, pass);
#else
#if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266)
WiFi.begin(ssid, pass);
#else
Ethernet.begin(mac);
#endif
#endif
Ethernet.begin(mac);
#endif
#endif

ThingSpeak.begin(client);

}

void loop() {
// Read the latest value from field 4 of channel 12397
float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber);
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
Serial.print("Current temp is: ");
Serial.print(temperatureInF);
Serial.println(" degrees F");
#endif
#ifdef SPARK
Particle.publish("thingspeak-lasttemp", String::format("Current temp %.1f degrees F",temperatureInF),60,PRIVATE);
#endif

Serial.print("Current temp is: ");
Serial.print(temperatureInF);
Serial.println(" degrees F");

delay(30000); // Note that the weather station only updates once a minute
}





Loading

0 comments on commit 9910c2f

Please sign in to comment.