Giter Site home page Giter Site logo

raspberrypi's Introduction

Raspberry Pi Realtime Streaming with Plot.ly

Plotly-imp

This is an example of a streaming graph: http://plot.ly/~streaming-demos/6/

Here is an example of how to hook up a TMP36 Temperature Sensor to your Pi!

This is a tutorial on streaming with the Raspberry Pi

First, install the required modules and dependencies:

sudo apt-get install python-dev
wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O - | sudo python
sudo easy_install -U distribute
sudo apt-get install python-pip
sudo pip install rpi.gpio
sudo pip install plotly

Create your sensor reading script, and start importing some modules in it!

import plotly.plotly as py # plotly library
from plotly.graph_objs import Scatter, Layout, Figure # plotly graph objects
import time # timer functions
import readadc # helper functions to read ADC from the Raspberry Pi

Make sure to update the credentials in the script with your own!

username = 'your_plotly_username'
api_key = 'your_api_key'
stream_token = 'your_stream_token'

If you don't know your credentials :

Sign up to plotly here: https://plot.ly/ssu View your API key and streaming tokens here: https://plot.ly/settings

Initialize a Plotly Object

py.sign_in(username, api_key)

Initialize your graph (not streaming yet)

trace1 = Scatter(
    x=[],
    y=[],
    stream=dict(
        token=stream_token,
        maxpoints=200
    )
)

layout = Layout(
    title='Raspberry Pi Streaming Sensor Data'
)

fig = Figure(data=[trace1], layout=layout)

print py.plot(fig, filename='Raspberry Pi Streaming Example Values')

Specify the connected channel for your sensor

sensor_pin = 0

Initialize the GPIO

readadc.initialize()

Initialize the Plotly Streaming Object

stream = py.Stream(stream_token)
stream.open()

Start looping and streamin'!

while True:
	sensor_data = readadc.readadc(sensor_pin, readadc.PINS.SPICLK, readadc.PINS.SPIMOSI, readadc.PINS.SPIMISO, readadc.PINS.SPICS)
	stream.write({'x': datetime.datetime.now(), 'y': sensor_data})
	time.sleep(0.1) # delay between stream posts

Your graph will be visible in your plotly account (https://plot.ly/plot) and at your_graph_url, the value assigned by the py.plot call above.

Contact

Questions? Suggestions? Something not look right? Get in touch!

raspberrypi's People

Contributors

alexander-daniel avatar chriddyp avatar

Watchers

João Pedro Taveira avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.