My name is Ryosuke Kamei and I am an IT consultant based on the idea of "gentle IT"! Currently, in my work, I am doing upstream processes focusing on requirements analysis and requirements definition, but I also write programs! As part of our friendly IT activities, we will introduce "Raspberry Pi 3" (commonly known as Raspberry Pi), which has the philosophy of "providing inexpensive PCs that can be programmed for education"!
This time, we will detect the brightness! It is a temperature sensor that uses an analog temperature sensor and an A / D converter! [Razpai Magazine-June 2016 Issue Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 13 Can Use Inexpensive Temperature Sensors](https://www.amazon.co.jp/ Razpai Magazine-June 2016 Issue -Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? Ie = UTF8 & dpID = 61P3o6Agz + L & dpSrc = sims & preST = _OU09__BG0,0,0,0_FMpng_AC_UL160_SR120,0_FMpng_AC_UL160_SR120 It is based on 18fd04738627edef8d6fffd6c9b8f9c2).
The wiring diagram is [Razpai Magazine-June 2016 Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 13 You can use an inexpensive temperature sensor](https://www.amazon.co.jp/ Razpai Magazine-2016 June issue-Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? Ie = UTF8 & dpID = 61P3o6Agz + L & dpSrc = sims & preST = OU09__BG0,0,0,0_FMpng_AC_UL160 sr2smail-22 & linkId = 18fd04738627edef8d6fffd6c9b8f9c2) As it is.
If you get an image like this, referring to the picture of the circuit
Text version From the Raspberry Pi side
--Raspberry Pi Pin 1 (3.3V) --AD Converter 8 Vdd --Raspberry Pi 2nd pin (5V) --Analog temperature sensor left side --Raspberry Pi 19th pin (MOSI) --AD converter 5 MOSI --Raspberry Pi 21st pin (MISO) --AD converter 6 MISO --Raspberry Pi 23rd pin (SCLK) --AD converter 7 CLK --Raspberry Pi 24th pin (CE0) --AD converter 1 CS --Raspberry Pi 6th pin (GND) --AD converter 4 Vss --Raspberry Pi 6th pin (GND) --Analog temperature sensor right side
From AD converter (difference only)
--AD converter pin 2 (CH0) --Analog temperature sensor center
Program is also [Razpai Magazine-June 2016 Issue Special Feature 1 Akiba's Popular Parts Wiring Diagram Best 17 13 Can Use Inexpensive Temperature Sensor](https://www.amazon.co.jp/ Razpai Magazine-2016 6 Monthly issue-Nikkei BP PC Best Mook-Nikkei Linux-ebook / dp / B01EH2RX42 / ref = as_li_ss_tl? Ie = UTF8 & dpID = 61P3o6Agz + L & dpSrc = sims & preST = _OU09__BG0,0,0,0_FMpng_AC_UL160_SR120 22 & linkId = 18fd04738627edef8d6fffd6c9b8f9c2) is referred to.
The source is uploaded to GitHub, so please use it as you like.
Clone with git
$ git clone https://github.com/RyosukeKamei/raspberrypi3.git
temperature_sensor.py
#Library to control GPIO
import wiringpi
#Timer library
import time
# MCP3002(A/Specify the channel to which the D converter) is connected
SPI_CH = 0
#MCP3002 to be read (A/Specify the analog input channel of the D converter)
READ_CH = 0
#SPI initialization
wiringpi.wiringPiSPISetup( SPI_CH, 1000000 )
while True:
# MCP3002(A/Create data to send to D converter)
buffer = 0x6800 | ( 0x1800 * READ_CH )
buffer = buffer.to_bytes( 2, byteorder='big' )
#Get the value of CH0 using SPI
wiringpi.wiringPiSPIDataRW( SPI_CH, buffer )
#The values are sent in 2 bytes, so combine them into one value.
input_value = ( buffer[0] * 256 + buffer[1] ) & 0x3ff
#Convert input value to voltage
volt = input_value * 3.3 / 1023
#Multiply the acquired voltage by 100 to get the temperature
temperature = volt * 100
#display
print ("temperature: ", temperature, "Voltage: ", volt)
#Detected by 1 second
time.sleep(1)
I recorded the video of how it is moving.
Activate the temperature sensor
$ sudo python3 temperature_sensor.py
Install Raspberry Pi 3 → Wireless LAN → Japanese input / output → Operate from Mac
Install Docker on RaspberryPi3 Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Easy construction] Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Trial and error]
Make an air conditioner integrated PC "airpi" with Raspberry Pi 3!
Programming with Node-RED programming with Raspberry Pi 3 and programming normally Light the LED with python on Raspberry Pi 3 (Hello World) Detect switch status on Raspberry Pi 3 Run a servo motor using python on Raspberry Pi 3 Control the motor with a motor driver using python on Raspberry Pi 3! Detect slide switch using python on Raspberry Pi 3! Detect magnet switch using python on Raspberry Pi 3! Detect temperature using python on Raspberry Pi 3! Sound the buzzer using python on Raspberry Pi 3! Detect analog signals with A / D converter using python on Raspberry Pi 3! Detect "brightness" using python on Raspberry Pi 3! Detect "temperature (using A / D converter)" using python on Raspberry Pi 3! Output to "7-segment LED" using python on Raspberry Pi 3!
Coding rules "Let's write gentle code" (FuelPHP) Naming convention "Friendly to yourself, team-friendly, and unseen members after 3 months"
PHP environment + Eclipse is linked to Apache using Docker Building FuelPHP development environment using Docker Create CRUD skeleton using initial settings of FuelPHP development environment using Docker and scaffold FuelPHP database migration
Recommended Posts