Try to visualize the room with Raspberry Pi, part 1

Introduction

Production process

Ringo who joined a web company for some reason from April I ended up touching Laravel, MySQL, and Ansible, which I had never touched in training. So, after studying, I will visualize the room using the Raspberry Pi and the sensor that were in the room. It seems that you did something similar with the title Making a temperature monitoring bot with ESP8266 and Raspberry Pi.

Determine specifications

Roughly, I will try to meet the following conditions.

--Monitor temperature, humidity, and atmospheric pressure ――I want to be able to see it not only from inside the house but also from the outside ――I want to graphically display not only the current data but also changes in the day.

Constitution

What to use

--Raspberry Pi, I used 3b + in this article --Temperature / humidity sensor BME280 --0.96 inch OLED

overall structure

image.png

Consider the configuration based on the specifications. The sensor and OLED are connected by I2C communication by piercing the breadboard. The acquired data will be saved in Raspberry Pi and thrown to the instance set up on CONOHA. The processing procedure is as follows.

  1. Acquisition & processing of data from sensor
  2. Display on LCD
  3. Save to csv
  4. Throw data into the cloud
  5. Save to DB
  6. Display on web page

I will make a process according to the procedure of. In this article, I will explain 1-3.

sensor

wiring

Since it is I2C communication, just connect SDI and SCK, and the module is 3.3V, so be careful. ʻI2cdetect -y 1` If it is confirmed and recognized, it's okay image.png

In the image, there are other connections, but 0x3C is the OLED address and 0x76 is the BME280 address.

In I2C, there are various things such as pull-up is necessary, but I will proceed assuming that it is on the board on the sensor side. However, I2C communication itself is not resistant to noise, so it may be better not to stretch it too much.

Get value

The library used the SWITCH CIENCE sample. SWITCHSCIENCE/BME280 It's written for Python2, so I'll edit it a bit. As a change

--Rewrite the writing method of the print part for Python3 --Changed so that it can be acquired as a return value so that it is easy to use what was printed in the function that corrects the acquired raw data.

The edited code will be here. You will also need smbus to run it. image.png

I was able to confirm the acquisition of the value on the terminal.

Display on LCD

The liquid crystal used is an OLED module equipped with SSD1306. I can't write because I don't remember where I bought it, but I think it's almost the same no matter where I bought it. I used the library published by Adafruit. adafruit/Adafruit_Python_SSD1306

I need some tips to move it. Move the sample code of the organic EL display on Raspberry Pi Refer to the article above and install the necessary libraries on pyenv so that you can use OLED. Add the processing of bme280 by referring to Adafruit_Python_SSD1306 / examples / stats.py.

#Clear screen
draw.rectangle((0,0,width,height), outline=0, fill=0)
sensor_data = bme280.readData() #Acquisition of sensor data
temp = "%6.2f" % (sensor_data[0])
draw.text((x, top), "Temp =" + temp + " °C", font = font, fill = 255)
press = "%7.2f" % (sensor_data[1])
draw.text((x, top + 8), "Press = " + press + " hPa", font = font, fill = 255)
hum = "%6.2f" % (sensor_data[2])
draw.text((x, top + 16), "Hum =" + hum + " %", font = font, fill = 255)
#Screen display
disp.image(image)
disp.display()

Extracted the processing in the while loop. As for the content of the process, the data is acquired from the sensor and displayed line by line.

image.png

I was able to display the acquired data on the OLED.

Save to csv

I said save to the cloud, but I will save it to csv for the time being.

#File writing process
date = str(datetime.date.today())
nowtime = datetime.datetime.now()
#Overwrite the file if it exists
if(os.path.exists(path + date +".csv")):
    f = open(path + date +".csv", 'a')
    f.write(str(nowtime.hour) + ':' + str(nowtime.minute) + ':' + str(nowtime.second) + ',')
    f.write(temp + ',' + press + ',' + hum + ' \n')
    f.close()
#Generate if not
else:
    f = open(path + date +".csv", 'w')
    f.write("date,Temp,Press,Hum\n")
    f.write(str(nowtime.hour) + ':' + str(nowtime.minute) + ':' + str(nowtime.second) + ',')
    f.write(temp + ',' + press + ',' + hum + ' \n')
    f.close()

I wrote the process so that it is separated by date and saved in csv. When the output graph is displayed in Excel, it looks like this.

image.png

in conclusion

The final program is posted on gist. raspi_logger.py Next time, I will try to create an API using Laravel and the cloud and display the graph on the browser.

Recommended Posts

Try to visualize the room with Raspberry Pi, part 1
Try to detect an object with Raspberry Pi ~ Part 1: Comparison of detection speed ~
Try to use up the Raspberry Pi 2's 4-core CPU with Parallel Python
Try L Chika with raspberry pi
Try moving 3 servos with Raspberry Pi
Play with the Raspberry Pi Zero WH camera module Part 1
I tried to automate the watering of the planter with Raspberry Pi
Try fishing for smelt with Raspberry Pi
Quickly try to visualize datasets with pandas
Try Object detection with Raspberry Pi 4 + Coral
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
Use python on Raspberry Pi 3 to light the LED with switch control!
Try to solve the man-machine chart with Python
How to try the friends-of-friends algorithm with pyfof
Observe the Geminids meteor shower with Raspberry Pi 4
Connect to MySQL with Python on Raspberry Pi
GPGPU with Raspberry Pi
DigitalSignage with Raspberry Pi
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
I tweeted the illuminance of the room with Raspberry Pi, Arduino and optical sensor
[Verification] Try to align the point cloud with the optimization function of pytorch Part 1
Try to solve the programming challenge book with python3
Easy IoT to start with Raspberry Pi and MESH
Display images taken with the Raspberry Pi camera module
Try to solve the internship assignment problem with Python
How to use the Raspberry Pi relay module Python
Try debugging Python on Raspberry Pi with Visual Studio.
Try to operate DB with Python and visualize with d3
Try using the temperature sensor (LM75B) on the Raspberry Pi.
Take the value of SwitchBot thermo-hygrometer with Raspberry Pi
Measure temperature and humidity with Raspberry Pi3 and visualize with Ambient
Log the value of SwitchBot thermo-hygrometer with Raspberry Pi
Try to get the contents of Word with Golang
[Neo4J] ④ Try to handle the graph structure with Cypher
Try to specify the axis with PyTorch's Softmax function
When I tried to do socket communication with Raspberry Pi, the protocol was different
Introduced python3-OpenCV3 to Raspberry Pi
I talked to Raspberry Pi
Introducing PyMySQL to raspberry pi3
Easy introduction to home hack with Raspberry Pi and discord.py
Update Python for Raspberry Pi to 3.7 or later with pyenv
Try to play with the uprobe that supports Systemtap directly
[Part.2] Crawling with Python! Click the web page to move!
I tried using the DS18B20 temperature sensor with Raspberry Pi
Try to automate the operation of network devices with Python
Change the message displayed when logging in to Raspberry Pi
Try to decipher the garbled attachment file name with Python
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
I sent the data of Raspberry Pi to GCP (free)
Try to extract the features of the sensor data with CNN
I wanted to run the motor with Raspberry Pi, so I tried using Waveshare's Motor Driver Board
Make a note of what you want to do in the future with Raspberry Pi
I tried to move ROS (Melodic) with the first Raspberry Pi (Stretch) at the beginning of 2021
It was great to edit the Python file in the Raspberry Pi with Atom's remote function
Try to visualize the nutrients of corn flakes that M-1 champion Milkboy said with Python
Port FreeRTOS to Raspberry Pi 4B
[Raspberry Pi] Stepping motor control with Raspberry Pi
Control the motor with a motor driver using python on Raspberry Pi 3!
Use vl53l0x with Raspberry Pi (python)
raspberry pi 1 model b, node-red part 17
Servo motor control with Raspberry Pi