Hans on IoT

ThingSpeak, MATLAB, and the Internet of Things

Official ThingSpeak Library for Arduino and Particle 18

Posted by Hans Scharler,

We are thrilled to announce the official ThingSpeak Communication Library for Arduino and Particle devices. This library enables an Arduino or other compatible hardware to write or read data to or from ThingSpeak, an open data platform for the Internet of Things with built-in MATLAB analytics and visualization apps.

Arduino IDE Installation

In the Arduino IDE, choose Sketch/Include Library/Manage Libraries. Click the ThingSpeak Library from the list, and click the Install button.

Particle / Spark IDE Installation

In the Particle/ Spark Web IDE, click the libraries tab, find ThingSpeak, and choose “Include in App”.

Compatible Hardware

  • Arduino or compatible using an Ethernet or Wi-Fi shield (we have tested with Uno and Mega)
  • Arduino Yun running OpenWRT-Yun Release 1.5.3 (November 13th, 2014) or later.
  • Particle Core or Photon (Formally Spark)

ThingSpeak Examples

The library includes several examples to help you get started.

  • CheerLights: Reads the latest CheerLights color on ThingSpeak, and sets an RGB LED.
  • ReadLastTemperature: Reads the latest temperature from the public MathWorks weather station in Natick, MA on ThingSpeak.
  • ReadPrivateChannel: Reads the latest voltage value from a private channel on ThingSpeak.
  • ReadWeatherStation: Reads the latest weather data from the public MathWorks weather station in Natick, MA on ThingSpeak.
  • WriteMultipleVoltages: Reads analog voltages from pins 0-7 and writes them to the 8 fields of a channel on ThingSpeak.
  • WriteVoltage: Reads an analog voltage from pin 0, converts to a voltage, and writes it to a channel on ThingSpeak.

Complete source code and examples for the ThingSpeak Library are available on GitHub.

18 CommentsOldest to Newest

I’ve found that sometimes the Arduino IDE caches this info, and then doesn’t always update. Assuming you’re using windows, if you go to the AppData/Arduino15 directory, there’s a file called library_index.json. Quit the Arduino IDE, delete that file, and start it up again, and you should be all set.
On my computer, this file is at:
C:\Users
purser\AppData\Roaming\Arduino15
-Rob

John Laird replied on : 4 of 18

In the Particle Photon Library I can’t get the last two examples WriteMultipleVoltages and WriteVoltage (the ones I need) to compile. I get the following error:

In function `ThingSpeakClass::convertFloatToChar(float, char*)’: ThingSpeak/ThingSpeak.h:1444: undefined reference to `dtostrf(double, signed char, unsigned char, char*)’

The other examples compile fine. Can you fix this?

Thanks!

Hi all,

Version 1.1.0 of these libraries now supports ESP8226 devices, the Particle Electron (coming soon!).

You can use these libraries directly from within the Arduino and Particle IDEs.

All the best,
-Rob

Muscluman replied on : 6 of 18

This library is great. I only miss thinghttp support. Is there an easy way to extend this to cover thinghttp?

cybericius replied on : 7 of 18

No, not compatible with ESP8266 client. Got this error:

WARNING: library ThingSpeak claims to run on [avr] architecture(s) and may be incompatible with your current board which runs on [esp8266] architecture(s).

WeatherStationDemo.ino:33:33: warning: extra tokens at end of #include directive [enabled by default]
WeatherStationDemo.ino:34:34: warning: extra tokens at end of #include directive [enabled by default]
In file included from WeatherStationDemo.ino:36:0:
C:\Users\x\Documents\Arduino\libraries\ThingSpeak\src/ThingSpeak.h:81:8: error: #error Only Arduino Yun, Uno/Mega/Due with either Wired or wi-fi Ethernet shield, and Spark Core/Photon are supported.
#error Only Arduino Yun, Uno/Mega/Due with either Wired or wi-fi Ethernet shield, and Spark Core/Photon are supported.
^
C:\Users\x\Documents\Arduino\libraries\ThingSpeak\src/ThingSpeak.h: In member function ‘bool ThingSpeakClass::writeHTTPHeader(const char*)’:
C:\Users\x\Documents\Arduino\libraries\ThingSpeak\src/ThingSpeak.h:1357:28: error: ‘TS_USER_AGENT’ was not declared in this scope
if (!this->client->print(TS_USER_AGENT)) return false;
^
Error compiling.

Falyn YOung replied on : 8 of 18

Hello,

I am wondering if there is a way to set the parameters for the time for seconds instead of minutes for more data points.

Thanks.

wheato22 replied on : 10 of 18

Thanks for the examples. My current project is to use ThingSpeak to log and visualize my residential water use. I’m stuck trying to find or create a Sketch that will enable my Ardunio with Ethernet to write a single byte Field1 representing my water use in gallon every 20 seconds.

I Attempted to use the Write Voltage example but I’m having a problem making ThingSpeak.writeField work with the output of my counter Sketch which is a Volatile Byte data type. I am using digital pin 2 as my sensor input and tried to success no but n I try to wheserialwrite to a serial

Jose replied on : 11 of 18

Hi,

I am trying to install the ThingSpeak arduino library, but it is not listed in the arduino IDE’s “manage libraries.” I am using arduino IDE version 1.6.7 under Windows. I searched for the “library_index.json” file, but there is not such file in my system. Is there any other way to install this library?
Thanks.

Rachel replied on : 12 of 18

Hi,

I’m trying to install the library with an Arduino Mega and CC3000 wifi shield … but i get lots of errors if I put this in the code: #include “ThingSpeak.h” (I’ve not made any calls yet)

\Documents\Arduino\libraries\thingspeak\src/ThingSpeak.h:86:8: error: #error Only Arduino Yun, Uno/Mega/Due with either Wired or wi-fi Ethernet shield, ESP8266, and Spark Core/Photon/Electron are supported.

\Documents\Arduino\libraries\thingspeak\src/ThingSpeak.h:1469: error: integer constant is too large for ‘long’ type
\Documents\Arduino\libraries\thingspeak\src/ThingSpeak.h:1469: error: integer constant is too large for ‘long’ type

etc…

Is it just not compatible?

Paul replied on : 13 of 18

Is there any way to check that writing data to TS was successful? I’ve got two ESP8266 based boards reporting temperatures to the same channel with a 180 second delay. Due to hardware timing inaccuracies they slowly drift until one is trying to write data within 15 seconds of the other causing it to fail with gaps in my data.

viru409 replied on : 14 of 18

I used above code to read analog data using ethernet with arduino at thingspeak but following error occurs:

Connecting Arduino to network…

Arduino connected to network using DHCP

Connection to ThingSpeak failed (1)

Connection to ThingSpeak failed (2)

Connection to ThingSpeak failed (3)

Connection to ThingSpeak failed (4)
……..

how can I solve this issue

viru409 replied on : 15 of 18

I want to read analog data using ethernet with arduino at thingspeak but following error occurs:

Connecting Arduino to network…

Arduino connected to network using DHCP

Connection to ThingSpeak failed (1)

Connection to ThingSpeak failed (2)

Connection to ThingSpeak failed (3)

Connection to ThingSpeak failed (4)

how to solve this issue

Venkatesh replied on : 16 of 18

Hi ,

I am a first time user of ThingSpeak. I use Arduino Mega 2560 with IDE version 1.0.6. It does not show ThingSpeak library. How do I update ?

Kindly suggest.

Regards.

Jason Winters replied on : 17 of 18

The ThingSpeak library isn’t visible by default. You will first need to add it by going to Sketch -> Include Library -> Manage Libraries. Search for ThingSpeak and install the latest library from there.

Robert replied on : 18 of 18

Hi Venkatesh,

Version 1.0.6 is really old, please update to a more recent version of the Arduino IDE.

Regards

Add A Comment

What is 1 + 5?

Preview: hide