[Don't refer to 04.02.17] Display the temperature sensor on a real-time graph with rasberry pi 3.

I'm sorry. I happened to browse this article related to massives I couldn't do it, so I will stop browsing once.

This time, I combined the temperature sensor of rasberry pi 3 and 20 kinds of sensors, Challenge real-time graphs with python.

I bought a raspberry pi 3 and 20 types of sensors

To get the wiring procedure and data procedure, go to the URL below.

https://colo-ri.jp/develop/2016/05/raspberry-pi-ds18b20.html

Next is the wiring method: Here, the DQ pin is connected to GPIO4, the VDD pin is connected to 3.3V, and the GND pin is connected to GND. Then, pull up between the DQ pin and the VDD pin with a 10KΩ resistor.

Later, personally, I wanted to make a real-time graph of the values, so I created the following code. When executed, it is as shown in the image below (* It is a little difficult to see, but the real-time graph is displayed in the upper left and the real-time sensor etc. is displayed in the lower left. Ignore the prompt for the capture shot in the upper right.) temp.PNG

================================= ↓ Copy from here

#-*- coding: utf-8 -*-
#http://denshi.blog.jp/arduino/temperature-graph
import numpy as np
import matplotlib.pyplot as plt
import pygame
from pygame.locals import *
import serial
import sys
import os
import glob
from time import sleep

os.system('modprobe w1-gpio')
os.system('modprobe w1-gpio')

base_dir = '/sys/bus/w1/devices/'
device_folder = glob.glob(base_dir + '28*')[0]
device_file = device_folder + '/w1_slave'
def read_temp_raw():
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines


def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
sleep(0.2)
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos + 2:]
temp_c = float(temp_string) / 1000.0
return temp_c
def main():

temps = [0]*100 #Temperature storage
t = np.arange(0,100,1)
plt.ion()
pygame.init() #Initialize Pygame
screen = pygame.display.set_mode((200, 200)) #Screen creation(100×100)
pygame.display.set_caption("Tilt angle") #Title bar
font = pygame.font.Font(None, 50) #Character setting

while True:
screen.fill((0,0,0)) #Clear screen
deviceTemp = read_temp()
print(read_temp())
temp = str(deviceTemp) # \Read up to n(\n is deleted)
text = font.render(temp + "[C]", False, (255,255,255)) #Setting of characters to be displayed
screen.blit(text, (10, 10)) #Render, display position
pygame.display.flip() #Refresh the screen to reflect the changes
#Updated list of temperature data
temps.pop(99)
temps.insert(0,float(temp))
#Graph display settings
line, = plt.plot(t, temps, 'r-',label="Temperature[C]") #Y-axis update
line.set_ydata(temps)
plt.title("Real-time temperature")
plt.xlabel("Time [s]")
plt.ylabel("Temperature [Celsius]")
plt.legend()
plt.grid()
plt.xlim([100,1])
plt.ylim([0,40])
plt.draw()
plt.clf()
#print(read_temp())
for event in pygame.event.get():
#End processing when the end button is pressed
if event.type == QUIT:
pygame.quit()
ser.close()
plt.close()
sys.exit()


if __name__ == '__main__':
main()

Recommended Posts

[Don't refer to 04.02.17] Display the temperature sensor on a real-time graph with rasberry pi 3.
Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
Try using the temperature sensor (LM75B) on the Raspberry Pi.
Display / update the graph according to the input with PySimpleGui
I tried using the DS18B20 temperature sensor with Raspberry Pi
[Shell startup] I tried to display the shell on the TV with a cheap Linux board G-cluster
Control the motor with a motor driver using python on Raspberry Pi 3!
When generating a large number of graphs with matplotlib, I do not want to display the graph on the screen (jupyter environment)
Use the graphic LCD as a character LCD that can also display Chinese characters on the Rasberry Pi
Use python on Raspberry Pi 3 to light the LED with switch control!
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
I connected the thermo sensor to the Raspberry Pi and measured the temperature (Python)
Create a Python3 environment with pyenv on Mac and display a NetworkX graph
I tried to display the altitude value of DTM in a graph
[PyQt] Display a multi-axis graph with QtChart
Use the Grove sensor on the Raspberry Pi
Display the graph of tensorBoard on jupyter
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
How to publish a blog on Amazon S3 with the static Blog engine'Pelican'for Pythonista
How to draw a 2-axis graph with pyplot
Simply display a line graph on Jupyter Notebook
Introduction to Python with Atom (on the way)
Save the object to a file with pickle
Display CPU temperature every 5 seconds on Raspberry Pi 4
Connect to MySQL with Python on Raspberry Pi
How to set a shared folder with the host OS in CentOS7 on VirtualBOX
Put Scipy + Matplotlib in Ubuntu on Vagrant and display the graph with X11 Forwarding
Control music playback on a smartphone connected to Raspberry Pi 3 and bluetooth with AVRCP
I want to plot the location information of GTFS Realtime on Jupyter! (With balloon)
A memo on how to overcome the difficult problem of capturing FX with AI
Draw a graph with PyQtGraph Part 5-Increase the Y-axis
Record temperature and humidity with systemd on Raspberry Pi
Using the digital illuminance sensor TSL2561 with Raspberry Pi
[Python] How to draw a line graph with Matplotlib
Display images taken with the Raspberry Pi camera module
Try to visualize the room with Raspberry Pi, part 1
Display the integrated temperature for each field with Z-GIS
Make a breakpoint on the c layer with python
[Neo4J] ④ Try to handle the graph structure with Cypher
Transit to the update screen with the Django a tag
Display the graph while changing the parameters with PySimpleGUI + Matplotlib
Make a note of what you want to do in the future with Raspberry Pi
I don't tweet, but I want to use tweepy: just display the search results on the console
How to plot a lot of legends by changing the color of the graph continuously with matplotlib