09
Oct 15

Official ThingSpeak Library for Arduino and Particle

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.

Tags: , , , , ,

13 comments

  1. I have 1.6.5r5 installed and there is no ThingSpeak library when checking manage libraries.

    • 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

  2. Hi all,

    There some good conversations and common issues that people encounter over in the forums:

    http://community.thingspeak.com/forum/arduino/thingspeak-communication-library-for-arduino/

  3. 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!

  4. 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

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

  6. 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.

  7. 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.

  8. I cant read the value from ReadLastTemperature. It alway show 0 value

  9. 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

  10. 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.

  11. 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?

  12. 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.

Leave a comment