Hello!
I’m new to Cayenne and quite a noob in Python. For my latest project I put a Pimoroni Grow HAT mini and BME680 on a Raspberry Pi Zero. The BME680 I got working with Cayenne thanks to this post.
Now I’m stuck with the code for the Grow HAT mini, I’d like to connect the 3 moisture sensors with Cayenne, but the example monitor.py is quite complicated, copy/paste gives me this error:
Traceback (most recent call last):
File “grow.py”, line 33, in
from grow import Piezo
File “/home/pi/Cayenne-MQTT-Python/examples/grow.py”, line 33, in
from grow import Piezo
ImportError: cannot import name ‘Piezo’ from ‘grow’ (/home/pi/Cayenne-MQTT-Python/examples/grow.py)
So I know it has to do something with importing things, but I wonder how to get rid of them, because with the BME680 I didn’t need to do those things.
Any idea what to do?
from where did you get the python code for Grow Hat ? and have you named your project file grow.py?
then rename it to something else.
Thanks for the response! I got it from Pimoroni’s Github, so it’s the official code. I indeed called it grow.py, renamed it and now I get:
Traceback (most recent call last):
File “sensor2.py”, line 55, in
icon_drop = Image.open(“icons/icon-drop.png”).convert(“RGBA”)
File “/usr/lib/python3/dist-packages/PIL/Image.py”, line 2634, in open
fp = builtins.open(filename, “rb”)
FileNotFoundError: [Errno 2] No such file or directory: ‘icons/icon-drop.png’
I see that the directory with icons was not copied while installing the Grow HAT, but since I only have an tablet atm, I will try it tomorrow, because this way it’s horrible to do things like this.
can you share the link to it.
So I checked for the folder which contains the icons, and added the path in my code, but still I get the same kind of error:
Traceback (most recent call last):
File “sensor2.py”, line 55, in
icon_drop = Image.open(“Pimoroni/growhat/examples/icons/icon-drop.png”).convert(“RGBA”)
File “/usr/lib/python3/dist-packages/PIL/Image.py”, line 2634, in open
fp = builtins.open(filename, “rb”)
FileNotFoundError: [Errno 2] No such file or directory: 'Pimoroni/growhat/examples/icons/icon-drop.png
Do I have to change something in the image.py code? A lot of the grow code is because it has a tiny display and buttons and stuff, which are usefull for “normal” use but not for use with Cayenne, but I’m not able to see what is important for my use case and what not, that’s why I put the complete code.
First of all, I could suggest trying to delete the Grow directory and reinstall it as a fresh. Then get the Grow example to work. Then we can move to cayenne code.
Did a fresh install, and also found out that this example exists, which is enough for what I want now. So I put the following code:
/usr/bin/env python3
import cayenne.client
import time
import logging
Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
MQTT_USERNAME = “working”
MQTT_PASSWORD = “working”
MQTT_CLIENT_ID = “working”
client = cayenne.client.CayenneMQTTClient()
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, loglevel=logging.INFO)
For a secure connection use port 8883 when calling client.begin:
client.begin(MQTT_USERNAME, MQTT_PASSWORD, MQTT_CLIENT_ID, port=8883, loglevel=logging.INFO
#general
timestamp = 0
loop_delay = 15 #seconds
reading_delay = 60
from grow.moisture import Moisture
print(“”“moisture.py - Print out sensor reading in Hz
Press Ctrl+C to exit!
“””)
m1 = Moisture(1)
m2 = Moisture(2)
m3 = Moisture(3)
while True:
print(f""“1: {m1.moisture}
2: {m2.moisture}
3: {m3.moisture}
“””)
time.sleep(1.0)
It’s showing the desired output in the terminal, on Cayenne it appears to be online, but I don’t get any data on the dashboard. What did I do wrong?
you need to pass the moisture value to cayenne using
client.virtualWrite(1, m1.moisture)
1 Like