mirror of
https://github.com/easytarget/MQ-Pro-IO.git
synced 2025-10-14 01:35:52 +01:00
demo script and readme
This commit is contained in:
parent
d98ed556e5
commit
d4856665b8
16
GPIO-demo.py
16
GPIO-demo.py
@ -32,13 +32,21 @@ bus = SMBus(i2c_bus)
|
|||||||
bme280 = BME280(i2c_addr=bme280_addr, i2c_dev=bus)
|
bme280 = BME280(i2c_addr=bme280_addr, i2c_dev=bus)
|
||||||
bme280.setup()
|
bme280.setup()
|
||||||
|
|
||||||
while True:
|
def read_sensor():
|
||||||
t = round(bme280.get_temperature(),1)
|
t = round(bme280.get_temperature(),1)
|
||||||
h = round(bme280.get_humidity(),1)
|
h = round(bme280.get_humidity(),1)
|
||||||
p = round(bme280.get_pressure())
|
p = round(bme280.get_pressure())
|
||||||
out = ' Temp: {}°C\n Humi: {}%\n Pres: {}mb'.format(t,h,p)
|
return t, h, p
|
||||||
|
|
||||||
|
# initial reading settles sensor
|
||||||
|
_, _, _ = read_sensor()
|
||||||
|
|
||||||
|
# loop
|
||||||
|
while True:
|
||||||
|
sleep(1)
|
||||||
|
temp, humi, pres = read_sensor()
|
||||||
|
out = ' Temp: {}°C\n Humi: {}%\n Pres: {}mb'.format(temp, humi, pres)
|
||||||
with canvas(device) as draw:
|
with canvas(device) as draw:
|
||||||
draw.rectangle(device.bounding_box, outline="white", fill="black")
|
draw.rectangle(device.bounding_box, outline="white", fill="black")
|
||||||
draw.text((26, 12), out, fill="white")
|
draw.text((26, 12), out, fill="white")
|
||||||
print('{} : {}°C, {}%, {}mb'.format(ctime(),t,h,p)
|
print('{} :: {}°C, {}%, {}mb'.format(ctime(),temp, humi, pres))
|
||||||
sleep(1)
|
|
||||||
|
@ -3,6 +3,11 @@ This guide assumes you have a correctly installed and set up board, with the cor
|
|||||||
|
|
||||||
*Caveat:* notes here are biased towards Python usage, since that is what I will be using in my projects.
|
*Caveat:* notes here are biased towards Python usage, since that is what I will be using in my projects.
|
||||||
|
|
||||||
|
## Common
|
||||||
|
```
|
||||||
|
$ sudo apt install gpiod
|
||||||
|
```
|
||||||
|
|
||||||
## General Purpose GPIO (digital read/write)
|
## General Purpose GPIO (digital read/write)
|
||||||
**You do not need to use a custom Device Tree in order to use digital IO**
|
**You do not need to use a custom Device Tree in order to use digital IO**
|
||||||
* The 'default' device tree for the MQ pro has 26 free pins to use!
|
* The 'default' device tree for the MQ pro has 26 free pins to use!
|
||||||
@ -106,13 +111,13 @@ You can see that interface `0` has a BME280 device at address`0x76`, and a SSD13
|
|||||||
# Python demo
|
# Python demo
|
||||||
The following is a demo of using I2C to read data from a BME280 Temperature, Humidity and Pressure sensor, and display ito on a SSD1306 OLED display.
|
The following is a demo of using I2C to read data from a BME280 Temperature, Humidity and Pressure sensor, and display ito on a SSD1306 OLED display.
|
||||||
- It will be expanded with lgpio PWM and pin input/interrupt code later.
|
- It will be expanded with lgpio PWM and pin input/interrupt code later.
|
||||||
- All the install steps here (both `apt` and `pip`) are tediously slow on the MQ Pro.
|
- All the install steps here (making the venv, `apt` and `pip`) are tediously slow on the MQ Pro.
|
||||||
|
|
||||||
For the demo we need to install some dependencies via `apt`.
|
For the demo we need to install some dependencies via `apt`.
|
||||||
* I am using a [virtual environment](https://docs.python.org/3/tutorial/venv.html), rather than installing the python libraries globally.
|
* I am using a [virtual environment](https://docs.python.org/3/tutorial/venv.html), rather than installing the python libraries globally.
|
||||||
```bash
|
```bash
|
||||||
# Dependencies needed by pip install.
|
# Dependencies needed by pip install.
|
||||||
$ sudo apt install python3-venv python3-dev python3-lgpio libjpeg-dev liblgpio-dev build-essential
|
$ sudo apt install python3-venv python3-dev libjpeg-dev liblgpio-dev swig build-essential
|
||||||
|
|
||||||
# Create virtualenv at './env' and activate it
|
# Create virtualenv at './env' and activate it
|
||||||
# - exit with `deactivate`
|
# - exit with `deactivate`
|
||||||
@ -124,12 +129,14 @@ $ source env/bin/activate
|
|||||||
(env) $ pip install --upgrade pip
|
(env) $ pip install --upgrade pip
|
||||||
(env) $ pip install --upgrade pimoroni-bme280
|
(env) $ pip install --upgrade pimoroni-bme280
|
||||||
(env) $ pip install --upgrade luma.oled
|
(env) $ pip install --upgrade luma.oled
|
||||||
|
# Not yet used in demo: (env) $ pip install --upgrade lgpio
|
||||||
|
|
||||||
# Run the demo
|
# Run the demo
|
||||||
(env) $ python GPIO-demo.py
|
(env) $ python GPIO-demo.py
|
||||||
```
|
```
|
||||||
....WIP...
|
#### Work In Progress ####
|
||||||
I still need to upload he demo script..
|
Demo runs but still needs expanding to demo lgpio and pwm control
|
||||||
|
|
||||||
|
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user