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.
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.
So I bought the next set.
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 ...)
** 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
** 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.
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.
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.
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.
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.
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.
-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