Comments (6)
thanks @Gadgetoid for merging my PRs 👍
from enviroplus-python.
this is the contents of that python file:
print("starting up")
import datetime as dt
import ST7735
from PIL import Image, ImageDraw, ImageFont
import time
from bme280 import BME280
time.sleep(10)
print("i have slept 10s")
try:
from smbus2 import SMBus
except ImportError:
from smbus import SMBus
# Create LCD class instance.
disp = ST7735.ST7735(
port=0,
cs=1,
dc=9,
backlight=12,
rotation=270,
spi_speed_hz=10000000
)
# Initialize display.
disp.begin()
# Width and height to calculate text position.
WIDTH = disp.width
HEIGHT = disp.height
# New canvas to draw on.
img = Image.new('RGB', (WIDTH, HEIGHT), color=(0, 0, 0))
draw = ImageDraw.Draw(img)
# Text settings.
font_size = 15
font = ImageFont.truetype("/home/pi/AIY-projects-python/enviroplus-python/examples/fonts/Asap/Asap-Bold.ttf", font_size)
text_colour = (255, 255, 255)
back_colour = (0, 170, 170)
import time
from pms5003 import PMS5003, ReadTimeoutError
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)
pms5003 = PMS5003()
t = 0
print("just before while loop:")
while True:
t = (t + 1) % 2
readings = pms5003.read()
r1 = readings.pm_ug_per_m3(1)
r2 = readings.pm_ug_per_m3(2.5)
r10 = readings.pm_ug_per_m3(10)
time.sleep(1.0)
t = bme280.get_temperature()
h = bme280.get_humidity()
message = "1/2.5/10ug:{}/{}/{}\n".format(r1, r2, r10)
message += "temp:{}C hum:{}%\n".format(round(t, 2), round(h, 1))
message += "{}".format(str(dt.datetime.now())[:19])
size_x, size_y = draw.textsize(message, font)
# Calculate text position
x = (WIDTH - size_x) / 2
y = (HEIGHT / 2) - (size_y / 2)
# Draw background rectangle and write text.
draw.rectangle((0, 0, 160, 80), back_colour)
draw.text((x, y), message, font=font, fill=text_colour)
disp.display(img)
from enviroplus-python.
Might be worth wrapping the call to pms5003.read()
in a try/catch and handling the exception gracefully until it settles and starts working (assuming it does!).
try:
readings = pms5003.read()
r1 = readings.pm_ug_per_m3(1)
r2 = readings.pm_ug_per_m3(2.5)
r10 = readings.pm_ug_per_m3(10)
except pms5003.ReadTimeoutError:
r1 = 0
r2 = 0
r10 = 0
However, this is still bizarre. Are you sure you don't have any other services running at startup and using the GPIO?
from enviroplus-python.
in my plays/tests data = pms5003.read() almost always gives a (very first) read timeout
as @Gadgetoid suggested, you @koaning should protect all read()'s with try's ;-)
for instance enviroplus-python/examples/luftdaten.py shows proper defensive programming
from enviroplus-python.
See the updates all-in-one.py
(thanks to @cipy) for an example of how to trap a read timeout on the pms5003
without your entire script bailing out.
@cipy I took the liberty of replacing the pass
with a logging.warn
- we might as well make good use of logging while we have its awesome power!
from enviroplus-python.
I believe pimoroni/pms5003-python#3 might be relevant to this issue and the fix - pending merge here: pimoroni/pms5003-python#5 - probably applies also. By reading the SOF bytes one at a time, we should see fewer instances of read timeouts where the sensor isn't nicely synchronised should.
Closing for now, but please feel free to re-open if this is ongoing.
from enviroplus-python.
Related Issues (20)
- NumPy Error when working with LCD HOT 1
- Install script does not install all required python libraries HOT 4
- all_in_one (and combined) needs to recalculate humidity based on compensated temperature HOT 3
- Gas sensor not returning values HOT 3
- Migrate Lufdaten.py to Sensors Community (luftdaten.py) HOT 1
- Install script is missing a of dependencies and simply does not work HOT 3
- PMS5003 best use HOT 6
- light.py sample fails to run on new Enviro+ HOT 3
- BME280 - Pressure / Humidity Incorrect Readings HOT 3
- Failed to read PMS5003 (fresh latest install) HOT 1
- Pillow 10 compatibility HOT 1
- install.sh not working when trying to install over SSH HOT 6
- Installing enviroplus-python library and running lcd.py does not work HOT 3
- Error `/usr/bin/raspi-config: 2909: do_serial_cons: not found` when running install.sh HOT 1
- Will not install. Tried multiple methods and multiple pi's and multiple pi os versions. HOT 7
- Suddenly not starting, reporting an issue with `get_pin` HOT 1
- GPIO24: not found HOT 7
- (pms5003) Not working on Pi Zero / Bookworm HOT 5
- pms5003 on bookworm - Raspberry Pi 2 HOT 3
- LCD does not show anything only backlight is on HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enviroplus-python.