# Connecting the MAX31855 Thermocouple Amplifier breakout to an Electric Imp

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/010/894/medium800/microcontrollers_assembled_circuit.png?1378859272)

If you are interested in Internet of Things projects, this tutorial is a simple and very practical way to get started. The Electric Imp platform was created specifically for Internet of Things devices, and measuring temperature is a great way to learn.  
  
In this tutorial, we will be connecting an Electric Imp to the Adafruit MAX31855 Thermocouple Amplifier breakout board using one of the Serial Peripheral Interface Buses (SPI) available on the Electric Imp. Then we will connect a K-type thermocouple, and send the data to Xively and Twitter.  
  
Our maker objectives:

- Assemble the breakout boards. 
- Breadboard the circuit, and attach the thermocouple.
- Load the Electric Imp device code, and log temperature data in the Web IDE.
- Create a Xively.com developer account, and a Feed and Channel to push data to.
- Load/Configure the Electric Imp agent code for Xively, and push temperature data.
- Optionally, download the iPhone app "Pitchfork", and subscribe to our Xively Feed.
- Create a Twitter developer application and configure it to tweet from the Imp.
- Load/Configure the Electric Imp agent code for Twitter and tweet our temperature data.

Our learning objectives:  

- Understand how to configure and use SPI on the Electric Imp.
- Electric Imp pin configuration: [http://devwiki.electricimp.com/doku.php?id=imppinmux](http://devwiki.electricimp.com/doku.php?id=imppinmux)
- Read up on SPI here: [http://en.wikipedia.org/wiki/Serial\_Peripheral\_Interface\_Bus](http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus)  
- Understand how to connect to and read from the MAX31855 thermocouple amplifier.  
- MAX31855 datasheet: [http://www.adafruit.com/datasheets/MAX31855.pdf](http://www.adafruit.com/datasheets/MAX31855.pdf)
- Understand how thermocouples work. [http://learn.adafruit.com/thermocouple/overview](http://learn.adafruit.com/thermocouple/overview)
- Learn how to create a Xively feed and push data to it.
- Learn how to create a Twitter developer application and tweet from the Electric Imp.

Thermocouples are really great for extreme temperatures! Here are some projects ideas.  

- BBQ/Grill/Smoker temperature monitor  
- Oven temperature monitor  
- Homebrewing temperature monitor (Mashing, chilling, boiling, fermenting, ect)  
- SMT reflow oven temperature monitor/control  
- Fridge/Freezer/Kegerator temperature monitor
- Soldering Iron temperature monitor

# Connecting the MAX31855 Thermocouple Amplifier breakout to an Electric Imp

## Breadboarding the circuit

Let's get started creating our Internet of Things temperature monitor!

### 

Yes. Pictured below are the imp001 on the left, and the imp002 on the right. The imp001 fits into most SD card sockets and contains all of the hardware to "Blink-Up" or connect to your wireless network. The imp002 is a solder down version and allows the developer to create a custom "Blink-Up" circuit. All 12 pins are available with the imp002. We will be using the imp001 for this tutorial, since it contains all of the circuitry to get us going.

http://youtu.be/tjy_8eNdAjY

Danger: 

Danger: 

### 

Any device or breakout board that is powered by an Electric Imp is called an "impee". The April impee is one of the reference designs created by Electric Imp for developer use. You can check out the other designs here:  
  
[http://devwiki.electricimp.com/doku.php?id=boards:start](http://devwiki.electricimp.com/doku.php?id=boards:start "Link: http://devwiki.electricimp.com/doku.php?id=boards:start")  
  
These designs also include a Bill of Materials (BOM) and Gerber files, in case you want to try your hand at printing and assembling the boards yourself.

The Electric Imp has two sets of pins for SPI. Those sets are pins 1,8 & 9, and pins 2,5 & 7. For this tutorial we will be using SPI189 as it is referred to in hardware configuration. When you configure SPI189 you get the following pin configuration in the Electric Imp.

- PIN 1 - CLK or Clock
- PIN 8 - MOSI (Microcontroller Out/Sensor In)
- PIN 9 - MISO (Microcontroller In/Sensor Out) or Data Out

This line of code configures SPI189 in the device:  
  
**hardware.spi189.configure(MSB\_FIRST | CLOCK\_IDLE\_LOW , 1000);**  
  
Since we will only be reading data from the MAX31855 board (sensor), we only need to connect the MISO pin, which is pin 9, and not MOSI. We also need Pin 1 to provide a clock signal, and one more pin to act as a Chip Select (CS) pin. In order to tell the MAX31855 that we want to read SPI data, we pull the CS pin LOW, read the data, and then set the pin back to HIGH. We can configure any of the other pins as a CS pin, so we will use Pin 2, since it is directly across from the CS pin.   
  
This code reads SPI data from the chip that is connected to Pin 2:  
  
**hardware.pin2.write(0); //pull CS LOW to start the transmission of temp data**  
**local temp32=hardware.spi189.readblob(4);//SPI read is totally completed here**  
**hardware.pin2.write(1); // pull CS HIGH**  
  
Note: You can read as many chips as you like from a single SPI bus, as long as you have a Chip Select Pin for each. Using just the April board, you could read up to four MAX31855 chips. This is very handy for a project with multiple thermocouples.  
  
To complete the wiring, connect these pins as shown above.  
  
**April - MAX31855**  
**PIN1 - CLK**  
**PIN2 - CS**  
**PIN9 - DO**  
 **3V3 - 3Vo**  
**GND - GND**

# Connecting the MAX31855 Thermocouple Amplifier breakout to an Electric Imp

## Get the Device code

 **Electric Imp: The agent and the device**  
  
One of the really interesting things about the Electric Imp is that you are able to program both the device, and something called an "agent", which is a secure, programmable web service that you use to interface with your Electric Imp device. If you are coming from a platform like Arduino, you may be wondering why you can't talk directly to the Electric Imp itself. That question is beyond the scope of this tutorial, but I have found that the agent is a very handy service to have. Here are a few great features of agents:  

- Communicate using HTTPS
- Additional memory and processing power for code
- If you device goes offline, your agent will continue to execute code and can inform you. 

As an example of the last point, if you use an Electric Imp in a security system, and a thief disables your connection or the device, your agent can still alert you that there is a problem.  
  
The device can operate without any programming in the agent, so the first thing we need to do is program the device to read data from our thermocouple amplifier via SPI.  
  
Log into your Electric Imp account and open the Web IDE. Find the Electric Imp that you will be using by its hardware address in the list of your Devices on the left hand side. Mouse over it, and click the gear symbol to create new Device Settings. Click the down arrow beside associated model, and then type a new model name, such as "MAX31855".  
![](https://cdn-learn.adafruit.com/assets/assets/000/010/844/medium800/microcontrollers_new_device.png?1378844632)

Info: 

The Electric Imp code for this tutorial is available at the GitHub page listed below. Typically, you store code for the device in a file called " **device.nut**", and code for the agent in a file called " **agent.nut**" The Electric Imp programming language, "ImpOS" is a slightly modified version of the Squirrel programming language.  
  
[https://github.com/joel-wehr/Tutorial\_Electric\_Imp\_MAX31855](https://github.com/joel-wehr/Tutorial_Electric_Imp_MAX31855 "Link: https://github.com/joel-wehr/Tutorial\_Electric\_Imp\_MAX31855")  
  
_ **Credit for this code goes to a number of members of the Electric Imp forum community as well as members of the Electric Imp team. Big thanks to beardedinventor, bodinegl, rivers, and mjkuwp94. Check out the Electric Imp GitHub page for example and reference code.** _

[Download the .zip archive.](https://github.com/joel-wehr/Tutorial_Electric_Imp_MAX31855/archive/master.zip)
Copy the code from device.nut into the Device panel in the web IDE.

![](https://cdn-learn.adafruit.com/assets/assets/000/010/809/medium800/microcontrollers_IDE_device_code.png?1378424297)

Click "Build and Run"  
  
If all is well, you should see the Imp download the new code, and start logging data every 10 seconds like this:  
  
2013-09-04 21:33:28 UTC+4: [Status] Downloading new code  
2013-09-04 21:33:28 UTC+4: [Status] Device configured to be "MAX31855"  
2013-09-04 21:33:28 UTC+4: [Device] 24.5°C  
2013-09-04 21:33:28 UTC+4: [Device] 76.1°F

Nice! The Electric Imp is reading our thermocouple data over SPI!

If you haven't read through LadyAda's tutorial on thermocouples, amplifiers and the Seebeck effect, I highly recommend that you do. Working with thermocouples will make much more sense.

[http://learn.adafruit.com/thermocouple/overview](http://learn.adafruit.com/thermocouple/overview "Link: http://learn.adafruit.com/thermocouple/overview")

Info: 

Info: 

# Connecting the MAX31855 Thermocouple Amplifier breakout to an Electric Imp

## Configure the Agent for Xively

Info: 

The Electric Imp is a really great microcontroller in a tiny package, but its true purpose is to connect devices to the Internet, so lets get to it!  
  
It seems that there are new services to push your data to every week! One of those has been around for a while and is now called Xively. You may have known it when it was Cosm, or Pachube. Let's set it up to log and graph our data.  
  
If you haven't already, go to [https://xively.com/signup/](https://xively.com/signup/ "Link: https://xively.com/signup/") and create a free developer account.  
  
After you are set up and logged in, Click the DEVELOP tab, and +Add Device.  
  
Give your device a name, a description, and then choose a privacy setting. For now, choose Private Device as we will be working with API keys.  
  
Click Add Device.

![](https://cdn-learn.adafruit.com/assets/assets/000/010/840/medium800/microcontrollers_xively_create_new_device.png?1378842148)

Take a look around at your new Xively feed. The first thing we need to do is create a channel to push our thermocouple data to. Click the blue "+ Add Channel" bar.  
  
Fill out the channel information.   
  
To type the degree symbol **"°"** :  
  
**On a Mac type:** Shift+Option+8 for the degree symbol   
**On a PC numeric keypad type:** Alt+0176.  
  
(or just copy and paste the character above!)  
  
Save the channel.  
  
If you like, you can set a Location, and Metadata.

![](https://cdn-learn.adafruit.com/assets/assets/000/010/841/medium800/microcontrollers_xively_channel_info.png?1378842540)

Now we need to configure the Electric Imp's agent to talk to our Xively channel. Copy the code from the " **agent.nut**" file that you downloaded from the GitHub tutorial repo. Then open the Electric Imp Web IDE and paste the code into the Agent panel for your MAX31855 Imp.

There are three sections in the agent code. The top section is code to talk to the Xively.com API. The next section is code to talk to the Twitter API, as well as SHA1 encryption code. Finally, at the bottom is a function that will be run each time the device executes the agent.send() function.  
  
You'll need to enter three items from your Xively account into the agent code. Under the API Keys panel in your Xively developer workbench, copy the entire auto-generated API Key, and paste it inside the quotes for the API-Key variable at the top of the agent Xively code. Then find the Feed ID above the API Key, and copy and paste it to its variable. Lastly, type or paste the name of your channel into the Channel\_ID variable. My channel was named "Thermocouple". This section of code looks like:  
  
**API\_Key \<- "YOUR API KEY"; //Type your Xively API Key**  
**Feed\_ID \<- "YOUR FEED ID" //Type your Feed ID**  
**Channel\_ID \<- "YOUR CHANNEL ID"; //Type your Channel ID**  
  
The Xively API Key sections looks like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/010/899/medium800/microcontrollers_Screen_Shot_2013-09-10_at_10.52.57_PM.png?1378868034)

Now, in the Device code panel, uncomment line 81 or the line that has this code:  
  
**agent.send("Xively", farenheit); //Uncomment this line to send Xively data**  
  
Build and Run your code, and you should see something like this:  
  
2013-09-04 22:44:21 UTC+4: [Status] Device booting  
2013-09-04 22:44:21 UTC+4: [Status] Device configured to be "MAX31855"  
2013-09-04 22:44:21 UTC+4: [Device] 24.5°C  
2013-09-04 22:44:21 UTC+4: [Device] 76.1°F  
2013-09-04 22:44:21 UTC+4: [Agent] { "id": "Thermocouple", "current\_value": 76.1 }

Take a look at your Xively channel. You should see the Electric Imp begin sending data to the feed in the Request Log, and the data should show up in your channel and on the graph.  
  
Nice! You are sending thermocouple data to Xively!  
Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/010/906/medium800/microcontrollers_Screen_Shot_2013-09-10_at_11.45.01_PM.png?1378871208)

# Connecting the MAX31855 Thermocouple Amplifier breakout to an Electric Imp

## Configure the Agent for Twitter

Next, let's set up our Electric Imp to tweet its temperature! You'll need a Twitter account, so go ahead and create one of you haven't already. In order to tweet from our Imp's agent, we will need to access the Twitter Developer Center. [https://dev.twitter.com/apps/new](https://dev.twitter.com/apps/new)  
  
Fill out the Name, Description, and Website information. Agree to the terms and conditions, and complete the Captcha. If all is well, Twitter will create an new application for you.

![](https://cdn-learn.adafruit.com/assets/assets/000/010/900/medium800/microcontrollers_Screen_Shot_2013-09-10_at_11.02.22_PM.png?1378868591)

Take a look at what is on the page. At the bottom, click "Create my Access Token". Twitter will create Access tokens for you.

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/010/901/medium800/microcontrollers_Screen_Shot_2013-09-10_at_11.05.45_PM.png?1378868777)

The token created is read-only, and we need to give it write access. Click on the Settings tab at the top. Scroll down to Application Type, and check "Read and Write". Then click "Update this Twitter application's settings" at the bottom. Make sure it updates to "Read and Write".

![](https://cdn-learn.adafruit.com/assets/assets/000/010/902/medium800/microcontrollers_Screen_Shot_2013-09-10_at_11.08.04_PM.png?1378868983)

Now go back to the Details tab. We need to update our Access Token. Click "Recreate my access token" at the bottom. Make sure it says "Read and Write" after you update it.

![](https://cdn-learn.adafruit.com/assets/assets/000/010/903/medium800/microcontrollers_Screen_Shot_2013-09-10_at_11.17.47_PM.png?1378869491)

We now have all the information we need to tweet. From the Details tab in your Twitter application page, carefully copy the appropriate information into the variables near the bottom of your Agent code in the Electric Imp Web IDE. You'll need to fill out these variables:  
  
**\_CONSUMER\_KEY \<- "YOUR KEY"**  
**\_CONSUMER\_SECRET \<- "YOUR SECRET"**  
**\_ACCESS\_TOKEN \<- "YOUR TOKEN"**  
**\_ACCESS\_SECRET \<- "YOUR SECRET"**  
  
Paste your information inside the quotes.

![](https://cdn-learn.adafruit.com/assets/assets/000/010/904/medium800/microcontrollers_Screen_Shot_2013-09-10_at_11.19.13_PM.png?1378869609)

![](https://cdn-learn.adafruit.com/assets/assets/000/010/905/medium800/microcontrollers_Screen_Shot_2013-09-10_at_11.20.16_PM.png?1378869642)

Finally, uncomment this line near the end of the Agent code:  
  
**//twitter.update\_status("The temperature is: " + v + "F.");**

Info: 

**imp.wakeup(10, readChip189); //Wakeup every 10 second and read data.**  
  
Click "Build and Run" in the web IDE. Check the log, if you don't see any errors you have tweeted successfully. Check your Twitter account for the message.  
  
If you do see error messages, check all of your keys and tokens for accuracy, and try again.  
  
Congrats! Your Electric Imp can tweet! Don't forget to send a tweet to @adafruit and @electricimp!  
  
Stay tuned for an upcoming tutorial on building a dual probe thermocouple temperature monitor with LCD readout using the Adafruit Arduino enclosure.
## Featured Products

### Electric Imp

[Electric Imp](https://www.adafruit.com/product/1129)
What is the electric imp? In essence, the Imp provides an easy, integrated way to connect almost any hardware device both to other devices and to internet services. It's more than just a WiFi card, or even a WiFi module with processing built in - it's an integrated platform that deals...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1129)
[Related Guides to the Product](https://learn.adafruit.com/products/1129/guides)
### Electric Imp April: Basic prototyping

[Electric Imp April: Basic prototyping](https://www.adafruit.com/product/1130)
The April is a handy companion for your Electric Imp card. This breakout board provides just the bare minimum for Imp life support - a socket, an ID chip, and a 3.3v buck power supply for high power efficiency. Small and cheap, it's easy to integrate into products for demos or even use in...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1130)
[Related Guides to the Product](https://learn.adafruit.com/products/1130/guides)
### Thermocouple Amplifier MAX31855 breakout board (MAX6675 upgrade)

[Thermocouple Amplifier MAX31855 breakout board (MAX6675 upgrade)](https://www.adafruit.com/product/269)
Thermocouples are very sensitive, requiring a good amplifier with a cold-compensation reference. The MAX31855K does everything for you, and can be easily interfaced with any microcontroller, even one without an analog input. This breakout board has the chip itself, a 3.3V regulator with 10uF...

Out of Stock
[Buy Now](https://www.adafruit.com/product/269)
[Related Guides to the Product](https://learn.adafruit.com/products/269/guides)
### Thermocouple Type-K Glass Braid Insulated

[Thermocouple Type-K Glass Braid Insulated](https://www.adafruit.com/product/270)
Thermocouples are best used for measuring temperatures that can go above 100 °C. This is a bare wires bead-probe which can measure air or surface temperatures. Most inexpensive thermocouples have a vinyl covering which can melt at around 200 °C, this one uses a fiberglass braid so it...

Out of Stock
[Buy Now](https://www.adafruit.com/product/270)
[Related Guides to the Product](https://learn.adafruit.com/products/270/guides)
### Tiny Premium Breadboard

[Tiny Premium Breadboard](https://www.adafruit.com/product/65)
This is a tiny little breadboard... half the size of a half-size breadboard!&nbsp;

**As of Sep 8, 2022** - This Tiny breadboard has been updated to make plugging and un-plugging boards and headers a buttery-smooth&nbsp;operation. Updated design also includes a metal...

In Stock
[Buy Now](https://www.adafruit.com/product/65)
[Related Guides to the Product](https://learn.adafruit.com/products/65/guides)
### 5V 1A (1000mA) USB port power supply - UL Listed

[5V 1A (1000mA) USB port power supply - UL Listed](https://www.adafruit.com/product/501)
Need a USB jack for charging or powering a project, but don't want to lug around a computer? This switching supply gives a clean regulated output at up to 1000mA! 110 or 240 input, so it works in any country. The plugs are "US 2-prong" style so you may need a plug adapter, but...

In Stock
[Buy Now](https://www.adafruit.com/product/501)
[Related Guides to the Product](https://learn.adafruit.com/products/501/guides)
### USB cable - A/MiniB

[USB cable - A/MiniB](https://www.adafruit.com/product/260)
This here is your standard A-miniB USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Teensy v2, USB Lipo charger w/Mini B connector, among other things.

Approximately 3 feet / 1 meter long

Color may vary!

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/260)
[Related Guides to the Product](https://learn.adafruit.com/products/260/guides)
### Breadboarding wire bundle

[Breadboarding wire bundle](https://www.adafruit.com/product/153)
75 flexible stranded core wires with stiff ends molded on in red, orange, yellow, green, blue, brown, black and white. These are a major improvement over the "box of bent wires" that are sometimes sold with breadboards, and faster than stripping your own solid core wires. Makes...

In Stock
[Buy Now](https://www.adafruit.com/product/153)
[Related Guides to the Product](https://learn.adafruit.com/products/153/guides)

## Related Guides

- [CircuitPython I2C and SPI Under the Hood](https://learn.adafruit.com/circuitpython-basics-i2c-and-spi.md)
- [Adafruit 1-Wire Thermocouple Amplifier - MAX31850K](https://learn.adafruit.com/adafruit-1-wire-thermocouple-amplifier-max31850k.md)
- [Adafruit FT232H With SPI & I2C Devices](https://learn.adafruit.com/adafruit-ft232h-with-spi-and-i2c-libraries.md)
- [CircuitPython Libraries on Linux and the 96Boards DragonBoard 410c](https://learn.adafruit.com/circuitpython-libraries-on-linux-and-the-96boards-dragonboard-410c.md)
- [ Analog IC Insights On-the-Go by Maxim Integrated](https://learn.adafruit.com/maxim-app.md)
- [MicroPython Hardware: SPI Devices](https://learn.adafruit.com/micropython-hardware-spi-devices.md)
- [MAX31855 Thermocouple](https://learn.adafruit.com/thermocouple.md)
- [Google Docs Sensor Logging From Your PC](https://learn.adafruit.com/gdocs-sensor-logging-from-your-pc.md)
- [Adding a Single Board Computer to Blinka](https://learn.adafruit.com/adding-a-single-board-computer-to-blinka.md)
- [MAX31855 Thermocouple Sensor Python Library](https://learn.adafruit.com/max31855-thermocouple-python-library.md)
- [Calibrating Sensors](https://learn.adafruit.com/calibrating-sensors.md)
- [Adafruit Metro ESP32-S3](https://learn.adafruit.com/adafruit-metro-esp32-s3.md)
- [Fake TV Light for Engineers](https://learn.adafruit.com/fake-tv-light-for-engineers.md)
- [I2C Addresses and Troublesome Chips](https://learn.adafruit.com/i2c-addresses.md)
- [Adafruit CH552 QT Py](https://learn.adafruit.com/adafruit-ch552-qt-py.md)
