Real-time Graphing With the Raspberry Pi




Introduction: Real-time Graphing With the Raspberry Pi

Time for some Raspberry Pi + Plotly Streaming fun!

Recently we completed an Instructable for visualizing temperature and humidity data using an Arduino and, a free online collaborative graphing tool. Now it's time to extend that fun to all Raspberry Pi users!

The Raspberry Pi is a fantastic platform for software experimentation, allowing kids, amateurs and professionals alike to hack away without fear of breaking an expensive computer system. I'm a huge fan, and have done a few projects with my Raspberry Pi, from setting up a web server in our workshop, to using it as a desktop PC when my laptop was in the shop.

Raspberry Pi fun isn't limited only to software activities though! In addition to its other great features, the Raspberry Pi has some GPIO (General Purpose IN/OUT) pins, which you can use to read data from!

The purpose of this Instructable is to take some temperature data read from a TMP36 sensor, and visualize it using real-time streaming using the Plotly Python API!

Here is an example of our final product:

Step 1: What You'll Need

  • Raspberry Pi

  • MCP3008 DIP-package ADC converter chip

  • Analog Temperature Sensor TMP-36

  • Breadboard

  • Some Hookup wire

  • Some Software Packages (Details in later steps)

For the solderless option :

For the more permanent shield option:

You'll need a Account. Head over to:

  • to sign up.
  • Once you have signed up, head over to the SETTINGS page and write down your API key and Stream Token. You'll need these later!

Step 2: SSH Into Your Pi

Hopefully you've got your Raspberry Pi hooked up to your local network. If you do, SSH right into it and you're ready for the next step!

If not, check out this link, it's a great primer on getting started with SSH on your Pi:

Once you're logged in, head over to the next stop and run the command listed there.

We used this guide to get SSH working over our Laptop's WIFI. All you need is an ethernet cable. It works well for testing, and when everything is ready you can hook it up to your Router.

Step 3: Software Setup - Run All of These Commands in Your Terminal

sudo apt-get install python-dev
sudo apt-get install python-pip
sudo pip install rpi.gpio
sudo pip install plotly

Step 4: More Software

Download the Raspberry Pi Getting Started Script

  • OR

Clone the Repo from Github:

Change to the new directory

cd rasperrypi

Step 5: Advanced Users: Plotly Python Library

Should you want to deviate from the Quickstart method, you can of course just use the Python Library like you would on any other system. Take a look inside the included Quickstart Scripts to see whats going on under the hood and get started writing your own personalized scripts!

All of the normal Python library functions work on the Raspberry Pi as well!

Step 6: Hardware Hookup

The Raspberry Pi does have GPIO, however without some extra help from a MCP3008 Chip, it cannot read analog inputs.
No problem, just breadboard your MCP3008, and connect your Pi Cobbler, or Solder it directly onto your Prototype Shield. You'll be slingin' some analog data in no time!

Connect the following pins from the Raspberry Pi's GPIO pins the MCP chip:

MCP3008 VDD (PIN16) : 3.3V
MCP3008 VREF (PIN15) : 3.3V
MCP3008 AGND (PIN14) : GND
MCP3008 CLK (PIN13) : #18
MCP3008 DOUT (PIN12) : #23
MCP3008 DIN (PIN11): #24
MCP3008 CS (PIN10): #25

Connect the following pins from the TMP36 :
(Flat Face Forward, Left to Right)

Pin1 : 3.3V
Pin2 : MCP3008 CH0 (PIN 1)
Pin3 : GND

Step 7: Firing It Up

Now, if you have everything connected properly, and you've downloaded the getting started script, go ahead and execute it! Thanks to's streaming capabilities, all of your sensor data will automatically update on the graph!

Make sure you update the credentials in the script with your own! (Obtained in previous step)

username = 'your_plotly_username'
api_key = 'your_api_key'
stream_token = 'your_stream_token'
Then, run the script! (You have to sudo to access the GPIO pins)
sudo python

In this script, you will enter in your desired graph information, as well as API Key and Stream Token (Obtained earlier).

Now you can cruise right over to the URL provided from the script! Paste it right into your browser if you're using the Raspberry Pi in a Graphical Environment, or fire up your browser on your main computer to see your work!

Once you've opened your graph, feel free to click on "Save and Edit" (don't worry, your graph will be saved regardless) to edit the style and change the titles in the GUI.

Happy Streaming!!

Here is an example graph made with streamed data from a Raspberry Pi:

2 People Made This Project!


  • Big and Small Contest

    Big and Small Contest
  • Make It Bridge

    Make It Bridge
  • Game Design: Student Design Challenge

    Game Design: Student Design Challenge



3 years ago

I appreciate that I am coming late to this party, but the methods to download plotly are not working. Instead I get shunted off to Dash. Is Dash a substitute for plotly? Are there tutorials on how to use it?


Question 3 years ago on Step 2

Hi. When was this instructable written. I am trying to connect to the plotly libraries and information but I keep getting sent to dash. I dont think I need dash from what I have read about it to make a simple interactive plot with RPi. IS this isntructable out of date? WHow can I learn how to make a simple streaming plot with RPi and Python?


5 years ago

Hello, i´m doing this I really apreciate the information, but I got a problem in the tutorial on streaming with the raspberry pi, the link is a dead link.


5 years ago


Does anyone know if i can swap the recommended temperature sensor for a DS18B20
Temperature Sensor Cable or would this change the whole dynamics of the project? First time rashberry PI builder, could use all the help I can get.



6 years ago

help please! what i have to do?


7 years ago on Introduction

Curious about how this works under the hood.. does the pc act a client requesting data from the raspberry pi (web?) server?

I have an outdoor worm farm that I'd like to stream real-time data from (1Mbps+), could this be done with an arduino and a bluetooth or wifi shield? BT classic (2.1 edr) ftp profile would be fast enough, but seems everything is (slow) ble these days.

Or if using a wifi shield, what wifi layers/protocols would be needed for real-time data transfer?


Reply 7 years ago on Introduction

You could use Jython to pull data and write them to a database, but it all depends on your application. But, real time is difficult unless you have a pretty good understanding of network topology and could work with different interfaces. Unless someone has released something along the lines, to write you're own interpreter and broadcaster for bluetooth is a challenge on its own!


8 years ago on Introduction

I'm currently attempting to execute this project
using an I2C accelerometer from SparkFun. The sensor returns a value but I keep
getting a 411 error in addition to this

Traceback (most recent call last):
File "", line 277, in <module>
stream.write(dict(x=i, y=sensor_data[0]))
File "/usr/local/lib/python2.7/dist-packages/plotly/plotly/", line 501, in write
self._stream.write(jdata, reconnect_on=reconnect_on)
File "/usr/local/lib/python2.7/dist-packages/plotly/plotly/chunked_requests/", line 53, in write
Exception: Server responded with status code: 411
and message: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" ""> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>ERROR: The requested URL could not be retrieved</title> <style type="text/css"><!-- %l body :lang(fa) { direction: rtl; font-size: 100%; font-family: Tahoma, Roya, sans-serif; float: right; } :lang(he) { direction: rtl; float: right; } --></style> </head><body> <div id="titles"> <h1>ERROR</h1> <h2>The requested URL could not be retrieved</h2> </div> <hr> <div id="content"> <p><b>Invalid Request</b> error was encountered while trying to process the request:</p> <blockquote id="data"> <pre>POST / HTTP/1.1

assume this means that plotly is not accepting data I'm sending. My
username, apikey and token are all correct in the sensor code. There are
no syntax errors either. I am very new to, so I'm certain that
I'm missing something simple. Any help would be appreciated. The
tutorial is very well written and appreciated.


Reply 8 years ago on Introduction

Hey dauletle --
Thanks so much for trying it out!
Hm... I'm having trouble replicating this. Could you share with me your code? Are you using a Raspberry Pi? Which version of the Python library are you using? (import plotly; plotly.__version__)


Reply 8 years ago on Introduction

Hi plotlygraphs. I'm using Python 2.7.3 [GCC 4.6.3] on linux2, with plotly version 1.2.7

I'm using almost the same code as the example code posted in these instructions. The only things I really changed had to do with reading my sensor through I2C. The sensor is reading just fine, and everything looks like it's working up to the command

stream.write({'x': i, 'y': sensor_data})

where I'm getting this 411 error. I'm going to try to run this with Python 3, and get back to you you of any progress made.


9 years ago on Step 4

what modifications would I need to make to run plotty on a pcDuino, running linux ubuntu? it seems like the plotty code will install fine, but then how would I sample sensor data from the pcDuino? Is it just a matter of modifying example code? Since the pcDuino is a stand-alone linux PC would it be as simple as just installing plot ly ?


9 years ago

when I'm using ploty, possible to embed the image to other website?