Weatherhat not fully responsive with "RuntimeError: Failed to add edge detection"

Hi,
I’ve just received a WeatherHat to complement my two existing Enviropi setups.
The problem is that while the examples for buttons & lcd work, all the others give output like this
‘’'pi@weatherpi-garden:~/Pimoroni/weatherhat/examples$ python3 BME280.py

BME280.py - Print raw readings from the BME280 weather sensor.
Press Ctrl+C to exit!

Traceback (most recent call last):
File “BME280.py”, line 9, in
sensor = weatherhat.WeatherHAT()
File “/home/pi/.local/lib/python3.7/site-packages/weatherhat/init.py”, line 81, in init
self._ioe.on_interrupt(self.handle_ioe_interrupt)
File “/home/pi/.local/lib/python3.7/site-packages/ioexpander/init.py”, line 521, in on_interrupt
self._gpio.add_event_detect(self._interrupt_pin, self._gpio.FALLING, callback=callback, bouncetime=1)
RuntimeError: Failed to add edge detection’’’

Is it me or you?
The accompanying PiZero to which it is attached came without soldered headers, so I added them myself. Then tried reflowing those connections after one of the buttons wasn’t working (and now is).
The OS is a clone of one of my enviropi’s, so I would assume the BME280 should work as both HAT’s have one?
I’m assuming the edge detection that isn’t working is the rising/falling config for the gpio it’s trying to talk to.
I found the pinout here https://cdn.shopify.com/s/files/1/0174/1800/files/weather_hat_schematic.pdf?v=1643203877

Thanks,
Sean

Ahoy!

It sounds like you might have an old version of io-expander - we added some new interrupt stuff in to handle the counting of signals from the wind and rain sensors (and even though the BME280 example doesn’t use those, they’re called when you init weatherhat).

It’s probably easiest to start with a fresh Raspberry Pi OS install, or you could try updating io-expander to the most recent version via whatever package manager you used to install it?

It’s on Raspbian 10.
I did also try the hat on another pi zero with the same result (so it’s probably not a hardware problem).

1 pi@weatherpi-garden:~/Pimoroni/weatherhat/examples$ pip3 install pimoroni-ioexpander
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pimoroni-ioexpander in /home/pi/.local/lib/python3.7/site-packages (0.0.3)
Requirement already satisfied: smbus2 in /home/pi/.local/lib/python3.7/site-packages (from pimoroni-ioexpander) (0.4.1)
pi@weatherpi-garden:~/Pimoroni/weatherhat/examples$ python3 weather.py 
Traceback (most recent call last):
  File "weather.py", line 740, in <module>
    main()
  File "weather.py", line 709, in main
    sensordata = SensorData()
  File "weather.py", line 649, in __init__
    self.sensor = weatherhat.WeatherHAT()
  File "/home/pi/.local/lib/python3.7/site-packages/weatherhat/__init__.py", line 81, in __init__
    self._ioe.on_interrupt(self.handle_ioe_interrupt)
  File "/home/pi/.local/lib/python3.7/site-packages/ioexpander/__init__.py", line 521, in on_interrupt
    self._gpio.add_event_detect(self._interrupt_pin, self._gpio.FALLING, callback=callback, bouncetime=1)
RuntimeError: Failed to add edge detection
1 pi@weatherpi-garden:~/Pimoroni/weatherhat/examples$ python3 BME280.py

BME280.py - Print raw readings from the BME280 weather sensor.
Press Ctrl+C to exit!

Traceback (most recent call last):
  File "BME280.py", line 9, in <module>
    sensor = weatherhat.WeatherHAT()
  File "/home/pi/.local/lib/python3.7/site-packages/weatherhat/__init__.py", line 81, in __init__
    self._ioe.on_interrupt(self.handle_ioe_interrupt)
  File "/home/pi/.local/lib/python3.7/site-packages/ioexpander/__init__.py", line 521, in on_interrupt
    self._gpio.add_event_detect(self._interrupt_pin, self._gpio.FALLING, callback=callback, bouncetime=1)
RuntimeError: Failed to add edge detection

Hmm, curious. I think IO-expander v0.0.3 is the newest version, so you should be good in that regard.

Have you got any other Python scripts running in a crontab or a screen that might be using the same pins?

Yeah, github shows it’s the latest version.
Given this sd card was a clone of what I’m using for the Enviropi’s, it did have the kootnet-sensors thing and the enviro-web installed, but I’ve already removed them.
So nothing is currently running via cron or anything else on intervals that would be tying up the gpio pins…
I’ll try a clean install later and see if that helps.

OK, I’ve done a fresh install of what-is-now-called Raspberry Pi OS Lite (Debian 11 bullseye).
Then running the install-bullseye.sh from the repo.
To get the lcd.py example working i had to add these

pip3 install numpy
sudo install libatlas-base-dev # for lbcblas.so.3

So now that all the examples work, I can have a go at hacking about the mqtt script (below) to get the data (eventually) into home assistant.
But also, are there any recommendations for boxes to put the device in when it’s sortof outside?
The idea is that it lives in my garden shed facing south so that it looks out of the shed window.
It’ll be powered by battery topped up with a solar panel.

Good stuff, glad to hear you got it going. I’ve tweaked the tutorial a bit to hopefully make it a bit more helpful to folks who want to use Lite.

I’ve hacked the Adafruit-IO example so it also posts data into Home Assistant via MQTT - the code is a bit scruffy but I can send it over if you’d like to take a look? Getting MQTT devices to auto-detect in HA (so you don’t need to manually set up the sensors in configuration.yaml) is the bit that requires most of the code, IIRC.

Sure, if you could send it over that’d be great! (then I don’t have to do it).
Linux is my day-job, so I’m great with bash, but my python is improving.
I have my 2 enviropi’s posting into home assistant using the Kootnet-sensors package, but I did have to set those items up manually. MQTT discovery only works if there’s a discovery item (or whatever it’s called) sent with the data.

Oh, also on a related note.
What’s the maximum voltage input for the ADC’s on the weatherhat?
I was hoping to be able to measure the supply battery voltage (12v) when it’s all solar powered, but I don’t want to blow it up.

Here’s my hacky code - hope it’s useful! You can probably dispense with the Dict stuff if you’re happy adding sensors manually.

The folks in engineering say that as the Nuvoton is powered from 3V3, you should only input 0V-3.3V on the ADCs, so you may need to incorporate some voltage divider shenanigans into your battery measuring.

I’ve managed to get it all working!
I had to rip the adafruit stuff out of that script though.
Here it all is in my garden shed.
I’ll put the ADC connector in later once I’ve found my hoard of resistors. :D
Thanks for the help!



1 Like