dinsdag 3 januari 2017

The Electronic Barometer

This goes beyond data journalism. It is a project about the Internet of Things, studying the relationship between measurement/observation, data and storing data, and finally retrieving, analyzing and visualizing data if possible real time. Here is the story.

The Raspberry Pi with a Sense Hat is a very good start. The Pi is a cheap mini computer running Linux and understanding Python code. The Sense Hat is a set-up board, loaded with different sensors, for example temperature, humidity and pressure. How can we make a graph out of the measurement, which shows changes in pressure over time: and electronic barometer?
The sensors in the Sense Hat read the pressure( in mV), this measurement is through a Python script transformed into data, a pressure in hPa. Together with a visualizing service like plot.ly, we can turn these data in a real time graph. Based on this tutorial I made some changes in the python script for the Sense Hat sensors. After registration at plot.ly and getting the details for setting up an API(Application Programming Interface), the data were plotting.
Here is the updated Python script:

import plotly.plotly as py
from plotly.graph_objs import Scatter, Layout, Figure
import time
username = 'peterverweij'

api_key = 'xxxxxxxxxxxxxxxx'
stream_token = 'xxxxxxxxxx'
py.sign_in(username, api_key)
trace1 = Scatter(

layout = Layout(
    title='Raspberry Pi Streaming Sensor Data'
fig = Figure(data=[trace1], layout=layout)
print py.plot(fig, filename='Raspberry Pi Streaming Example Values')

i = 0
stream = py.Stream(stream_token)
#the main sensor reading loop

from sense_hat import SenseHat
sense = SenseHat()
while True:
        pressure = sense.get_pressure()
        sensor_data = pressure
         stream.write({'x': datetime.datetime.now(), 'y': sensor_data})
        i += 1
# delay between stream posts

Geen opmerkingen:

Een reactie plaatsen

Opmerking: alleen leden van deze blog kunnen een reactie plaatsen.