Dömemeter 2.0

Kábelezés:

Érintés (V+)13,3V5V2Motor (V+)
Érintés (SDA)3SDA5V4Iránytű (V+)
Érintés (SCL)5SCLGND6Iránytű (GND)
Kalózrádió (jel)7GPIO4GPIO148
Érintés (GND)9GNDGPIO1510Motor (1)
11GPIO17GPIO1812Motor (2)
13GPIO27GND14Motor (GND)
15GPIO22GPIO2316Motor (3)
Hőmérő (V+)173,3VGPIO2418Motor (4)
Hőmérő (jel)19GPIO10GND20Hőmérő (GND)
21GPIO9GPIO2522
Iránytű (SDA)23GPIO11GPIO824Iránytű (SCL)
25GNDGPIO726

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.