Dömemeter 2.0
Kábelezés:
Érintés (V+) | 1 | 3,3V | 5V | 2 | Motor (V+) |
Érintés (SDA) | 3 | SDA | 5V | 4 | Iránytű (V+) |
Érintés (SCL) | 5 | SCL | GND | 6 | Iránytű (GND) |
Kalózrádió (jel) | 7 | GPIO4 | GPIO14 | 8 | |
Érintés (GND) | 9 | GND | GPIO15 | 10 | Motor (1) |
11 | GPIO17 | GPIO18 | 12 | Motor (2) | |
13 | GPIO27 | GND | 14 | Motor (GND) | |
15 | GPIO22 | GPIO23 | 16 | Motor (3) | |
Hőmérő (V+) | 17 | 3,3V | GPIO24 | 18 | Motor (4) |
Hőmérő (jel) | 19 | GPIO10 | GND | 20 | Hőmérő (GND) |
21 | GPIO9 | GPIO25 | 22 | ||
Iránytű (SDA) | 23 | GPIO11 | GPIO8 | 24 | Iránytű (SCL) |
25 | GND | GPIO7 | 26 |
DHT szenzor
Előkészületek:
sudo apt-get install python3-pip
sudo pip3 install Adafruit_Python_DHT
Kód:
import Adafruit_DHT
DHT_SENSOR = Adafruit_DHT.DHT22
DHT_PIN = 10
while True:
humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN)
if humidity is not None and temperature is not None:
print("Temp={0:0.1f}*C Humidity={1:0.1f}%".format(temperature, humidity))
else:
print("Failed to retrieve data from humidity sensor")
Eredmény:
Temp=22.6*C Humidity=55.0%
Érintés szenzor
Előkészületek:
sudo pip3 install adafruit-circuitpython-mpr121
sudo apt-get install python-smbus i2c-tools
sudo i2cdetect -y 1
Ezek után ezt kell látnod:
0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- 5a -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Kód:
import time
import board
import busio
import adafruit_mpr121
i2c = busio.I2C(board.SCL, board.SDA)
mpr121 = adafruit_mpr121.MPR121(i2c)
while True:
for i in range(12):
if mpr121[i].value:
print("Input {} touched!".format(i))
time.sleep(0.25)
Eredmény (ha megérinted a 11-es pöcköt):
sudo python3 erintes.py
Input 11 touched!
Több I2C
sudo nano /boot/config.txt
add hozzá ezt:
dtoverlay=i2c-gpio,bus=3,i2c_gpio_delay_us=1,i2c_gpio_sda=11,i2c_gpio_scl=8
reboot után nézd meg működik-e:
sudo i2cdetect -y 3
0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 1e -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 70: -- -- -- -- -- -- -- --
Iránytű
Előkészületek:
git clone https://github.com/quick2wire/quick2wire-python-api
sudo apt-get install python-virtualenv
export QUICK2WIRE_API_HOME=/home/pi/quick2wire-python-api
export PYTHONPATH=$PYTHONPATH:$QUICK2WIRE_API_HOME
cd quick2wire-python-api
sudo python3 setup.py install
git clone https://bitbucket.org/thinkbowl/i2clibraries.git
Kód: (A mágneses elhajlás Törökbálinton 5 fok 20 perc és a 3-as I2C portot használjuk)
from i2clibraries import i2c_hmc5883l
hmc5883l = i2c_hmc5883l.i2c_hmc5883l(3)
hmc5883l.setContinuousMode()
hmc5883l.setDeclination(5,20)
print(hmc5883l)
Eredmény:
Axis X: 369.84
Axis Y: -87.4
Axis Z: -578.68
Declination: 0° 6'
Heading: 346° 42'
Billentyűzet
Előkészületek:
sudo modprobe -i uinput
sudo pip3 install python-uinput
sudo pip install readchar
Kód:
Comments are closed.