Skip to content

Commit 9910c2f

Browse files
Bumping version to 1.2.0
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.
1 parent 69ac859 commit 9910c2f

26 files changed

+754
-1870
lines changed

examples/CheerLights/CheerLights.ino

Lines changed: 51 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,64 @@
55
On Spark core, the built in RGB LED is used
66
Visit http://www.cheerlights.com for more info.
77
8-
ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for prototyping
9-
systems that collect, analyze, and react to their environments.
8+
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and
9+
analyze live data streams in the cloud.
1010
11-
Copyright 2015, The MathWorks, Inc.
11+
Copyright 2016, The MathWorks, Inc.
1212
1313
Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed.
1414
See the accompaning licence file for licensing information.
1515
*/
1616

17-
#ifdef SPARK
18-
#include "ThingSpeak/ThingSpeak.h"
19-
#else
20-
#include "ThingSpeak.h"
21-
#endif
17+
#include "ThingSpeak.h"
18+
2219

2320
// ***********************************************************************************************************
2421
// This example selects the correct library to use based on the board selected under the Tools menu in the IDE.
25-
// Yun, Wired Ethernet shield, wi-fi shield, esp8266, and Spark are all supported.
26-
// With Uno and Mega, the default is that you're using a wired ethernet shield (http://www.arduino.cc/en/Main/ArduinoEthernetShield)
27-
// If you're using a wi-fi shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the line below
22+
// Yun, Ethernet shield, WiFi101 shield, esp8266, and MXR1000 are all supported.
23+
// With Yun, the default is that you're using the Ethernet connection.
24+
// If you're using a wi-fi 101 or ethernet shield (http://www.arduino.cc/en/Main/ArduinoWiFiShield), uncomment the corresponding line below
2825
// ***********************************************************************************************************
29-
//#define USE_WIFI_SHIELD
26+
27+
//#define USE_WIFI101_SHIELD
28+
//#define USE_ETHERNET_SHIELD
29+
30+
#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266)
31+
#error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD"
32+
#endif
33+
3034

3135
// Make sure that you put a 330 ohm resistor between the arduino
3236
// pins and each of the color pins on the LED.
3337
int pinRed = 9;
3438
int pinGreen = 6;
35-
int pinBlue = 5;
39+
int pinBlue = 3;
3640

37-
#ifdef ARDUINO_ARCH_AVR
38-
#ifdef ARDUINO_AVR_YUN
41+
#if defined(ARDUINO_AVR_YUN)
3942
#include "YunClient.h"
4043
YunClient client;
41-
#else
42-
43-
#ifdef USE_WIFI_SHIELD
44-
#include <SPI.h>
45-
// 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
46-
// If you get "multiple definition of `WiFi'" -- comment out the line below.
47-
#include <WiFi.h>
48-
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
49-
char pass[] = "<YOURPASSWORD>"; // your network password
50-
int status = WL_IDLE_STATUS;
51-
WiFiClient client;
44+
#else
45+
#if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266)
46+
// Use WiFi
47+
#ifdef ARDUINO_ARCH_ESP8266
48+
#include <ESP8266WiFi.h>
5249
#else
53-
// Use wired ethernet shield
5450
#include <SPI.h>
55-
#include <Ethernet.h>
56-
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
57-
EthernetClient client;
51+
#include <WiFi101.h>
5852
#endif
53+
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
54+
char pass[] = "<YOURPASSWORD>"; // your network password
55+
int status = WL_IDLE_STATUS;
56+
WiFiClient client;
57+
#elif defined(USE_ETHERNET_SHIELD)
58+
// Use wired ethernet shield
59+
#include <SPI.h>
60+
#include <Ethernet.h>
61+
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
62+
EthernetClient client;
5963
#endif
6064
#endif
6165

62-
#ifdef ARDUINO_ARCH_ESP8266
63-
#include <ESP8266WiFi.h>
64-
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
65-
char pass[] = "<YOURPASSWORD>"; // your network password
66-
int status = WL_IDLE_STATUS;
67-
WiFiClient client;
68-
#endif
69-
70-
#ifdef SPARK
71-
TCPClient client;
72-
#endif
73-
7466

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

8274
void setup() {
83-
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
84-
#ifdef ARDUINO_AVR_YUN
85-
Bridge.begin();
75+
76+
#ifdef ARDUINO_AVR_YUN
77+
Bridge.begin();
78+
#else
79+
#if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000)
80+
WiFi.begin(ssid, pass);
8681
#else
87-
#if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266)
88-
WiFi.begin(ssid, pass);
89-
#else
90-
Ethernet.begin(mac);
91-
#endif
82+
Ethernet.begin(mac);
9283
#endif
9384
#endif
9485

9586
ThingSpeak.begin(client);
9687

97-
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
98-
pinMode(pinRed,OUTPUT);
99-
pinMode(pinGreen,OUTPUT);
100-
pinMode(pinBlue,OUTPUT);
101-
#endif
88+
pinMode(pinRed,OUTPUT);
89+
pinMode(pinGreen,OUTPUT);
90+
pinMode(pinBlue,OUTPUT);
10291
}
10392

10493
void loop() {
10594
// Read the latest value from field 1 of channel 1417
10695
String color = ThingSpeak.readStringField(cheerLightsChannelNumber, 1);
10796
setColor(color);
108-
97+
10998
// Check again in 5 seconds
11099
delay(5000);
111100
}
@@ -137,16 +126,12 @@ void setColor(String color)
137126
{
138127
// When it matches, look up the RGB values for that color in the table,
139128
// and write the red, green, and blue values.
140-
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
141-
analogWrite(pinRed,colorRGB[iColor][0]);
142-
analogWrite(pinGreen,colorRGB[iColor][1]);
143-
analogWrite(pinBlue,colorRGB[iColor][2]);
144-
#endif
145-
#ifdef SPARK
146-
RGB.control(true);
147-
RGB.color(colorRGB[iColor][0], colorRGB[iColor][1], colorRGB[iColor][2]);
148-
#endif
129+
130+
analogWrite(pinRed,colorRGB[iColor][0]);
131+
analogWrite(pinGreen,colorRGB[iColor][1]);
132+
analogWrite(pinBlue,colorRGB[iColor][2]);
133+
149134
return;
150135
}
151136
}
152-
}
137+
}

examples/ReadLastTemperature/ReadLastTemperature.ino

Lines changed: 54 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,59 @@
55
https://thingspeak.com/channels/12397 on ThingSpeak, and prints to
66
the serial port debug window every 30 seconds.
77
8-
ThingSpeak ( https://www.thingspeak.com ) is a free IoT service for building
9-
systems that collect, analyze, and react to their environments.
8+
ThingSpeak ( https://www.thingspeak.com ) is an analytic IoT platform service that allows you to aggregate, visualize and
9+
analyze live data streams in the cloud.
1010
1111
Copyright 2016, The MathWorks, Inc.
1212
1313
Documentation for the ThingSpeak Communication Library for Arduino is in the extras/documentation folder where the library was installed.
1414
See the accompaning licence file for licensing information.
1515
*/
1616

17-
#ifdef SPARK
18-
#include "ThingSpeak/ThingSpeak.h"
19-
#else
20-
#include "ThingSpeak.h"
21-
#endif
17+
#include "ThingSpeak.h"
18+
2219

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

32-
#ifdef ARDUINO_AVR_YUN
27+
//#define USE_WIFI101_SHIELD
28+
//#define USE_ETHERNET_SHIELD
29+
30+
31+
#if !defined(USE_WIFI101_SHIELD) && !defined(USE_ETHERNET_SHIELD) && !defined(ARDUINO_SAMD_MKR1000) && !defined(ARDUINO_AVR_YUN) && !defined(ARDUINO_ARCH_ESP8266)
32+
#error "Uncomment the #define for either USE_WIFI101_SHIELD or USE_ETHERNET_SHIELD"
33+
#endif
34+
35+
36+
#if defined(ARDUINO_AVR_YUN)
3337
#include "YunClient.h"
3438
YunClient client;
35-
#else
36-
37-
#ifdef USE_WIFI_SHIELD
38-
#include <SPI.h>
39-
// 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
40-
// If you get "multiple definition of `WiFi'" -- comment out the line below.
41-
#include <WiFi.h>
42-
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
43-
char pass[] = "<YOURPASSWORD>"; // your network password
44-
int status = WL_IDLE_STATUS;
45-
WiFiClient client;
39+
#else
40+
#if defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000) || defined(ARDUINO_ARCH_ESP8266)
41+
// Use WiFi
42+
#ifdef ARDUINO_ARCH_ESP8266
43+
#include <ESP8266WiFi.h>
4644
#else
47-
// Use wired ethernet shield
4845
#include <SPI.h>
49-
#include <Ethernet.h>
50-
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
51-
EthernetClient client;
46+
#include <WiFi101.h>
5247
#endif
48+
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
49+
char pass[] = "<YOURPASSWORD>"; // your network password
50+
int status = WL_IDLE_STATUS;
51+
WiFiClient client;
52+
#elif defined(USE_ETHERNET_SHIELD)
53+
// Use wired ethernet shield
54+
#include <SPI.h>
55+
#include <Ethernet.h>
56+
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
57+
EthernetClient client;
5358
#endif
5459
#endif
5560

56-
#ifdef ARDUINO_ARCH_ESP8266
57-
#include <ESP8266WiFi.h>
58-
char ssid[] = "<YOURNETWORK>"; // your network SSID (name)
59-
char pass[] = "<YOURPASSWORD>"; // your network password
60-
int status = WL_IDLE_STATUS;
61-
WiFiClient client;
62-
#endif
63-
64-
// On Particle Core, Photon, and Electron the results are published to the Particle dashboard using events.
65-
// Go to http://dashboard.particle.io, click on the logs tab, and you'll see the events coming in.
66-
#ifdef SPARK
67-
TCPClient client;
68-
#endif
6961

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

8173
void setup() {
82-
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
83-
Serial.begin(9600);
84-
#ifdef ARDUINO_AVR_YUN
85-
Bridge.begin();
74+
75+
Serial.begin(9600);
76+
#ifdef ARDUINO_AVR_YUN
77+
Bridge.begin();
78+
#else
79+
#if defined(ARDUINO_ARCH_ESP8266) || defined(USE_WIFI101_SHIELD) || defined(ARDUINO_SAMD_MKR1000)
80+
WiFi.begin(ssid, pass);
8681
#else
87-
#if defined(USE_WIFI_SHIELD) || defined(ARDUINO_ARCH_ESP8266)
88-
WiFi.begin(ssid, pass);
89-
#else
90-
Ethernet.begin(mac);
91-
#endif
92-
#endif
82+
Ethernet.begin(mac);
83+
#endif
9384
#endif
94-
85+
9586
ThingSpeak.begin(client);
96-
87+
9788
}
9889

9990
void loop() {
10091
// Read the latest value from field 4 of channel 12397
10192
float temperatureInF = ThingSpeak.readFloatField(weatherStationChannelNumber, temperatureFieldNumber);
102-
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_ESP8266)
103-
Serial.print("Current temp is: ");
104-
Serial.print(temperatureInF);
105-
Serial.println(" degrees F");
106-
#endif
107-
#ifdef SPARK
108-
Particle.publish("thingspeak-lasttemp", String::format("Current temp %.1f degrees F",temperatureInF),60,PRIVATE);
109-
#endif
93+
94+
Serial.print("Current temp is: ");
95+
Serial.print(temperatureInF);
96+
Serial.println(" degrees F");
97+
11098
delay(30000); // Note that the weather station only updates once a minute
11199
}
100+
101+
102+
103+
104+

0 commit comments

Comments
 (0)