Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)

Introduction

It is a memorandum until an amateur such as Raspberry Pi or an electronic circuit connects a temperature sensor and acquires it with Python. In addition, since most of the content is diverted from other articles, it may be easier to understand if you look at the reference site as it is.

The first thing to do

Of course, I bought a Raspberry Pi. A quick look at this area shows that at this point (early February 2017), the Raspberry Pi 3 Model B looks good. Buy properly, really properly at Amazon. If you look more closely, the price may be reduced, but it's okay.

Amazon.co.jp |Raspberry Pi3 Model B Board & Case Set 3ple Decker Compatible(Element 14 version, Black) | Physical Computing Lab |Motherboard

So I bought the next set. image

Also, I hadn't decided what I wanted for the sensor, so I bought the next set. There are some sensors that I don't use, so it's a big division height, but it's okay. Amazon.co.jp: Best sensor module kit 20 types set

As a Prime member, I ordered with the default express delivery and it arrived within 24 hours. (Is this good or bad ...)

When the Raspberry Pi arrives, write the OS image to the SD card

** 1. SD card connection ** As for the SD card, there was a PC with an SD card slot as it is, so I will use that. If you don't have one, you'll need some kind of adapter.

** 2. Downloading software for writing images to SD card ** Download DD for Windows Ver.0.9.9.8 for writing to SD card from the following. DD for Windows - Tech Info

** 3. OS Download ** Download the Lite version of Raspbian (raspbian_lite-2017-01-10) from the following. Index of /pub/raspberrypi/raspbian_lite/images

** 4. Write image to SD card with DD ** Since my environment is Windows 7, when I run DDWin.exe, I right-click and select [Run as administrator] to start it. After starting, select the img file and write it.

** 5. Support for SSH connection ** For SSH connection, a file called ssh is required in the boot partition, so create it. (Create a file by creating a new text file and name it ssh)

** 6. Download software for SSH connection ** We will use PuTTY for the SSH connection. If not, download it from the following. PuTTY Gotta Boiled Edition

Start Raspberry Pi and check Python

** 1. Ready to connect ** Insert the SD card into the Raspberry Pi, connect the LAN cable, and connect the power supply. It seems that Raspberry Pi will start now.

** 2. Check the settings for connection ** If you do not know the IP address, you will not be able to connect, so check it using the method required for your environment. This time I checked the IP address from the management screen on the router, but there seem to be several methods such as ʻarp -a` at the command prompt.

** 3. Connect from PuTTY ** It's the most exciting place, isn't it? However, when I could see the IP address, I knew that something was working, but I was able to connect properly. image

Log in with the initial user: pi and password: raspberry.

** 4. Check Python ** There are a lot of things to do first, but let's get Python working for now. After all, Python is also an amateur. image

I found that it works quickly.

** 5. Settings that should be made ** At first, I'm skipping this area because I only do the minimum things I want to do.

Connect the sensor and see the movement

As expected, it took a lot of time here. In the first place, I didn't even know how to connect because I had too little knowledge. GPIO, ʻI2C, 1-Wire, and finally SPI. It was quick enough to light an LED with GPIO`, but the method of getting that value from a sensor that outputs some value does not work.

I tried it while referring to various articles, but the manufacturer who purchased the sensor? There was an article on how to use it properly on the site, so I tried it as it was and it worked.

** 1. Connect the DS18B20 temperature sensor ** Connect directly. As for the pins to be connected, I connected the DQ pin to GPIO4, the VDD pin to 3.3V, and the GND pin to GND as in the article I referred to. image The figure was created by obtaining the tool from Fritzing Download. At first I thought it was strange because the wiring was dragged and dropped and nothing responded, but when I created a new file, it was done normally. There are various articles here as well, but it's so easy that you can do it without looking.

** 2. Install 1-line communication libary **

sudo modprobe w1-gpio
sudo modprobe w1_therm

** 3. Modify /boot/config.txt **

sudo nano /boot/config.txt

/boot/config.txt


dtoverlay=w1-gpio

** 4. Restart Raspberry Pi **

sudo reboot

** 5. Check if the sensor is recognized **

ls /sys/bus/w1/devices/

If there is something that starts with 28-, it should be.

** 6. Sensor testing **

cat /sys/bus/w1/devices/28-xxxx/w1_slave

The xxxx part differs depending on the environment, so if you type in 28-, you can complete it with Tab </ kbd>.

** 7. Run in Python **

Sample code almost normal


import time
while 1:
	tempfile = open ("/sys/bus/w1/devices/28-XXXX/w1_slave") 
	thetext = tempfile.read()
	tempfile.close()
	tempdata = thetext.split("\n")[1].split(" ")[9]
	temperature = float(tempdata[2:])
	temperature = temperature /1000
	print temperature

Rewrite the XXX part.

Execution result. image

I tried covering the place where the temperature changed on the way with my hand or blowing on it. Compared to a normal thermometer, it seems to be measured 2 to 3 degrees higher.

With this kind of feeling, I was able to realize what I wanted to do at least for the time being.

For example, you can connect this with a VPN so that you can check the temperature, or an infrared transmission module? I think there are various ways to adjust the temperature of the air conditioner using Nari.

Reference site

-I bought a Raspberry Pi 3, installed necessary items and OS, etc. | Junki's leisure hobby blog -Activate temperature sensor on Raspberry Pi | osoyoo.com

Recommended Posts

Raspberry Pi --1 --First time (Connect a temperature sensor to display the temperature)
[Don't refer to 04.02.17] Display the temperature sensor on a real-time graph with rasberry pi 3.
A memo to simply use the illuminance sensor TSL2561 with Raspberry Pi 2
I connected the thermo sensor to the Raspberry Pi and measured the temperature (Python)
Connect to the console of Raspberry PI and display local IP and SD information
Try using the temperature sensor (LM75B) on the Raspberry Pi.
Using the 1-Wire Digital Temperature Sensor DS18B20 from Python on a Raspberry Pi
I tried using the DS18B20 temperature sensor with Raspberry Pi
Connect two USB cameras to Raspberry Pi 4
Use the Grove sensor on the Raspberry Pi
Display the signal strength RSSI of a specific SSID (raspberry pi (linux))
How to use MkDocs for the first time
Display CPU temperature every 5 seconds on Raspberry Pi 4
Connect your Raspberry Pi to your smartphone using Blynk
Connect to MySQL with Python on Raspberry Pi
Try posting to Qiita for the first time
Let's display a simple template that is ideal for Django for the first time
How to make a Raspberry Pi that speaks the tweets of the specified user
Use Raspberry Pi Python to TMP36 analog temperature sensor and MCP3008 AD converter
Realize a super IoT house by acquiring sensor data in the house with Raspberry Pi
Register a task in cron for the first time
Display images taken with the Raspberry Pi camera module
I want to create a lunch database [EP1] Django study for the first time
I want to create a lunch database [EP1-4] Django study for the first time
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
[Raspberry PI & Garmin GLO] Until you connect Bluetooth GPS to Raspberry Pi
Detect "temperature (using A / D converter)" using python on Raspberry Pi 3!
The first step to creating a serverless application with Zappa
Create a partition and then install the Raspberry Pi OS
I tried to display the time and today's weather w
Display the time in Django according to the user's region (UTC)
To write a test in Go, first design the interface
I tried to automate [a certain task] using Raspberry Pi
I made a surveillance camera with my first Raspberry PI.
[Python] The first step to making a game with Pyxel
Change the message displayed when logging in to Raspberry Pi
Creating a temperature / humidity monitor with Raspberry Pi (pigpio version)
How to get temperature from switchBot thermo-hygrometer using raspberry Pi
I want to create a Dockerfile for the time being.
Is there a secret to the frequency of pi numbers?
Connect Raspberry Pi to Alibaba Cloud IoT Platform with Python
How to connect the contents of a list into a string
I sent the data of Raspberry Pi to GCP (free)
Introduced python3-OpenCV3 to Raspberry Pi
Kaggle for the first time (kaggle ①)
I talked to Raspberry Pi
Introducing PyMySQL to raspberry pi3
Kaguru for the first time
Install a tact switch on the Raspberry Pi to make daily "Good morning Yosoro !!" tweets comfortable
Send the temperature, humidity, etc. measured by SensorTag to Ambient via Raspberry Pi 3 and graph it.
Introduction to Deep Learning for the first time (Chainer) Japanese character recognition Chapter 3 [Character recognition using a model]
About the error I encountered when trying to use Adafruit_DHT from Python on a Raspberry Pi
I want to record the execution time and keep a log.
Control the motor with a motor driver using python on Raspberry Pi 3!
I tried to automate the watering of the planter with Raspberry Pi
Make a simple CO2 incubator using Raspberry PI and CO2 sensor (MH-Z14A)
I want to run the Python GUI when starting Raspberry Pi
Use python on Raspberry Pi 3 to illuminate the LED (Hello World)
The first time a programming beginner tried simple data analysis by programming
[Python3] Define a decorator to measure the execution time of a function