RPi 2/3, I2C, Analog Sensor

 
RPi 2
/3
, I2C, Analog Sensor
 
jyheo0@gmail.com
 
I
2
C (I-squared-C)
 
Serial computer bus invented by Philips Semiconductor
Typically used for attaching lower-speed peripheral ICs to processors and
microcontrollers
 
A sample schematic with one master (a microcontroller),
three slave nodes (an ADC, a DAC, and a microcontroller),
and pull-up resistors Rp
 
https://en.wikipedia.org/wiki/I%C2%B2C
 
ADC, DAC
 
ADC - Analog to Digital Converter
DAC - Digital to Analog Converter
PCF8591t
3 ADC, 1 DAC
value range: 0~255
YL-40 board with PCF8591t
 
AOUT
AIN0
AIN1
AIN2
AIN3
 
SCL
SDA
GND
VCC
 
P4
P5
P6
 
Jumper P4 for AIN1: R6 thermister
Jumper P5 to AIN0: R7 photocell
Jumper P6 to AIN3: The single turn 10K ohm
resistance
 
Removing a jumper allows an input channel to be fed
from one of the external pins, labelled accordingly.
 
Enable I2C in RP
i
 
Enable I2C in raspi-config
$ sudo
 
raspi-config
Interfacing Options 
선택 
> I2C 
선택
 
Enable I2C in RPi
 
Check if the I2C kernel module is loaded
$ lsmod
i2c-dev, i2c-bcm
????
 must be listed!
Test
$ i2cdetect -y 1
 
Wiring RPi and YL-40
 
 
Photocell on YL-40
 
$ python
3
 
 
yl40.py 
 
0
 
import
 smbus
import
 time
import
 sys
 
bus 
=
 smbus.SMBus(
1
)
address 
=
 
0x
48
 
if
 
len
(sys.argv) 
==
 
2
:
 
i 
=
 
int
(sys.argv[
1
])
 
input_addr 
=
 
0x
40 
+
 i
else
:
 
input_addr 
=
 
0x
40
 
while
 
True
:
 
bus.write_byte(address, input_addr)
 
bus.read_byte(address)
 
aread 
=
 bus.read_byte(address)
 
print
(
aread
)
 
time.sleep(
0.2
)
 
# AIN0 0x40: photocell
# AIN1 0x41: thermister
# AIN3 0x43: registance
 
https://github.com/jyheo/rpi2/blob/master/yl40.py
 
Temperature Sensor - LM35
 
Wiring
LM35 1 to RPi 3V3
OUT to YL-40 AIN2
GND to RPi GND
$ python
3
 
 
yl40.py 
 
2
 
https://github.com/jyheo/rpi2/blob/master/yl40.py
 
Vibration Sensor
 
Wiring
One leg of Vibration Sensor to RPi 3V3
The other leg to YL-40 AIN2
$ python
3
 
 
yl40.py 
 
2
 
https://github.com/jyheo/rpi2/blob/master/yl40.py
 
IR Receiver
 
Wiring
Longer leg of 
IR
 Sensor to RPi 3V3
The other leg to YL-40 AIN2
$ python
3
 
 
yl40.py 
 
2
IR Receiver can be used to detect motion
 
https://github.com/jyheo/rpi2/blob/master/yl40.py
 
Analog OUT
 
$ python
3
 
 
yl40w.py 
 
255
Turn on green LED of YL-40
$ python
3
 
 
yl40w.py 
 
0
Turn off the LED
 
import
 smbus
import
 time
import
 sys
bus 
=
 smbus.SMBus(
1
)
address 
=
 
0x
48
if
 
len
(sys.argv) 
==
 
2
:
 
v 
=
 
int
(sys.argv[
1
])
 
bus.write_byte_data(address, 
0x
40, v)
else
:
 
print
(
sudo python yl40w.py 0~255
’)
 
https://github.com/jyheo/rpi2/blob/master/yl40w.py
 
Exercise
 
Write a python program
To display temperature and light
Motion detection LED
Detect motion using IR receiver
Once detecting motion, keep turning LED on for 3 seconds
Slide Note
Embed
Share

This guide provides detailed information on connecting and utilizing I2C communication with analog sensors on Raspberry Pi. Learn about the I2C bus, ADC, DAC, enabling I2C, wiring diagrams for sensors like LM35 and vibration sensors, and sample Python scripts for sensor readings. Explore step-by-step instructions and sample schematics to set up your Raspberry Pi for analog sensor interfacing.

  • Raspberry Pi
  • I2C
  • Analog Sensor
  • Guide
  • Python Script

Uploaded on Feb 24, 2025 | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. RPi 2/3, I2C, Analog Sensor jyheo0@gmail.com

  2. I2C (I-squared-C) Serial computer bus invented by Philips Semiconductor Typically used for attaching lower-speed peripheral ICs to processors and microcontrollers A sample schematic with one master (a microcontroller), three slave nodes (an ADC, a DAC, and a microcontroller), and pull-up resistors Rp https://en.wikipedia.org/wiki/I%C2%B2C

  3. ADC, DAC ADC - Analog to Digital Converter DAC - Digital to Analog Converter PCF8591t 3 ADC, 1 DAC value range: 0~255 YL-40 board with PCF8591t Jumper P4 for AIN1: R6 thermister Jumper P5 to AIN0: R7 photocell Jumper P6 to AIN3: The single turn 10K ohm resistance AOUT AIN0 AIN1 AIN2 AIN3 P4 P5 P6 SCL SDA GND VCC Removing a jumper allows an input channel to be fed from one of the external pins, labelled accordingly.

  4. Enable I2C in RPi Enable I2C in raspi-config $ sudo raspi-config Interfacing Options > I2C

  5. Enable I2C in RPi Check if the I2C kernel module is loaded $ lsmod i2c-dev, i2c-bcm???? must be listed! Test $ i2cdetect -y 1

  6. Wiring RPi and YL-40 YL-40 RPi SCL SCL1 SDA SDA1 GND GND VCC 3V3

  7. import smbus Photocell on YL-40 import time import sys $ python3 yl40.py 0 bus = smbus.SMBus(1) address = 0x48 if len(sys.argv) == 2: # AIN0 0x40: photocell i = int(sys.argv[1]) # AIN1 0x41: thermister input_addr = 0x40 + i # AIN3 0x43: registance else: input_addr = 0x40 while True: bus.write_byte(address, input_addr) bus.read_byte(address) aread = bus.read_byte(address) print(aread) https://github.com/jyheo/rpi2/blob/master/yl40.py time.sleep(0.2)

  8. Temperature Sensor - LM35 Wiring $ python3 yl40.py 2 LM35 1 to RPi 3V3 OUT to YL-40 AIN2 GND to RPi GND https://github.com/jyheo/rpi2/blob/master/yl40.py

  9. Vibration Sensor Wiring $ python3 yl40.py 2 One leg of Vibration Sensor to RPi 3V3 The other leg to YL-40 AIN2 https://github.com/jyheo/rpi2/blob/master/yl40.py

  10. IR Receiver Wiring $ python3 yl40.py 2 IR Receiver can be used to detect motion Longer leg of IR Sensor to RPi 3V3 The other leg to YL-40 AIN2 https://github.com/jyheo/rpi2/blob/master/yl40.py

  11. Analog OUT $ python3 yl40w.py 255 Turn on green LED of YL-40 $ python3 yl40w.py 0 Turn off the LED import smbus import time import sys bus = smbus.SMBus(1) address = 0x48 if len(sys.argv) == 2: v = int(sys.argv[1]) bus.write_byte_data(address, 0x40, v) else: print( sudo python yl40w.py 0~255 ) https://github.com/jyheo/rpi2/blob/master/yl40w.py

  12. Exercise Write a python program To display temperature and light Motion detection LED Detect motion using IR receiver Once detecting motion, keep turning LED on for 3 seconds

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#