Pico Quad Expander Board - ConnectionError: read failed: [Errno 6] Device not configured)

Hi, I’m trying to use a PIR motion sensor to control a 12V solenoid valve.

Prototype equipment:

Raspberry Pi Pico W
Dual Channel Relay Pico HAT
Pico Quad Expander Board
PIR Motion Sensor Module
DC 12V power supply

Code:

from machine import Pin
import utime

relay1 = Pin(6, Pin.OUT)

while True:
    relay1(1) 
    print("Relay on")
    utime.sleep(3)
    
    relay1(0)
    print("Relay off")
    utime.sleep(3)

The code runs as expected without the power source connected to the relay hat (without controlling the actual Solenoid). It fails when connecting the 12V power source. This seems to happen when it’s attempting to turn the relay back on.

Output

MPY: soft reboot
Relay on
Relay off
PROBLEM IN THONNY'S BACK-END: Exception while handling 'Run' (ConnectionError: read failed: [Errno 6] Device not configured).
See Thonny's backend.log for more info.
You may need to press "Stop/Restart" or hard-reset your MicroPython device and try again.


Process ended with exit code 1.
Unable to connect to /dev/cu.usbmodem2101: [Errno 2] could not open port /dev/cu.usbmodem2101: [Errno 2] No such file or directory: '/dev/cu.usbmodem2101'



Process ended with exit code 1.

Everything works as expected without the Pico Quad Expander Board (using jumper cables). I’ve tried another Pico Quad Expander Board thinking it could be the issue as the first one arrived falling out of the box. Unfortunately, they both have the exact same issue.

Any help is appreciated.

What ‘Dual Channel Relay Pico HAT’ is it? Can’t spot it on the site (but I might just be searching badly!)

Hi ahnlak

This one

Hmm, something odd there; it shouldn’t make any difference whether or not there’s a load on the relay, because the whole point of them is that they’re electrically isolated from the controller.

Does it fail with nothing else attached to the expander (i.e. without the PIR attached)? Trying to imagine if there’s some interference there somehow…

Yep, I’ve completely isolated it to the expander board. I only attach the Raspberry Pi Pico and the relay hat. I only get that error the moment I add a power supply. It occasionally manages to switch on, then off, then back on temporarily before receiving that error. So far I’ve tried different different Pimoroni boards, different slots on the board, different Picos and different 12V power supplies. I haven’t tried a different relay hat.

If I move everything over to a bread board, connecting the same relay to the same pin (GP6), it switches on and off without issue.