0

Apologies if this is not a pico question, not sure where the problem lies...

I have a small hobby motor (5v) mounted with a hobby fan:

Fan/Etc

that is connected to Normally Open on a relayRelay and 5V Wall Power supply (via a barrel/terminal block adapter. I also hooked up an oled and a temp probe:

All Components

On the input side, the relay connections are:

  • VCC to Pi Pico 3.3V/pin 36
  • GND to GND
  • input pin to GPIO 15

Relay to Pico

Everything works well as I am pursing a small thermostat project following these links:

https://www.youtube.com/watch?v=mj2kMD0LCR4&ab_channel=CoreElectronics

https://xilent.co.uk/2021/02/19/pi-pico-thermostat/

However, after triggering the relay to turn on the fan, OR after about 10 loops of just turning the relay on / off with a delay of 5 seconds, Thonny no longer prints to the screen and can no longer connect to /dev/ttyACM0.

Here's the simple test code:

import time
from machine import Pin, I2C

from oled_runner import lcd i2c0_sda = Pin(12) i2c0_scl = Pin(13) i2c0 = I2C(0, sda=i2c0_sda, scl=i2c0_scl)

from dht20 import DHT20 dht20 = DHT20(0x38, i2c0)

relay = Pin(15, Pin.OUT) relay.value(1) relay_sleep=5

count=0 measurements=0

def run_relay(): global count print('sleep before turn on relay') time.sleep(relay_sleep) relay.value(0) print('sleep before turn off led') time.sleep(relay_sleep) relay.value(1) count+=1 print(count)

def thermo_stat(): if fahrenheit > 77: #If on, turn off (relay.value(0) sets GPIO high) if relay.value() == 1: print("Turning on the fan via the relay") relay.value(0) else: print("Relay value already", relay.value()) else: print("Turning off the fan via the relay") relay.value(1)

def oled_show(): lcd.fill(0) lcd.show() lcd.text(f"Temp: {fahrenheit} F",0,0) lcd.show()

def thermometer(): global fahrenheit measurements = dht20.measurements celcius = measurements['t'] fahrenheit = (celcius * 1.8) + 32 fahrenheit = round(fahrenheit, 2) print(f"Temp: {fahrenheit} °F, humidity: {measurements['rh']} %RH")

while True: thermometer() oled_show() print("Wait...") time.sleep(5) gc.collect() thermo_stat() #run_relay() - toggle this on/of per testing ... sleep(5)

The pico continues to 'be a thermostat' if the temp goes up/down and can still turn the relay on/off, it's just Thonny can't talk to the Pico at all anymore. The Linux PC powering the USB connection can see the pico via 'lsusb'. I don't see any obvious errors in the backend.log on Thonny.

I noticed this only happens when the relay is turned on, otherwise if the temp never trips the relay Thonny/Pico still communicate.

Suggestions? It seems like a Thonny problem but it more seems like the pico becomes unresponsive on the usb once the relay is triggered.

james6125
  • 103
  • 3
  • may be a duplicate of https://raspberrypi.stackexchange.com/questions/144383/why-does-5v-make-this-relay-not-work-properly-vs-3-3-v-on-the-pi-pico – jsotola Sep 20 '23 at 01:19

1 Answers1

1

How much current does your relay draw?

You are running the relay off the Pico 3.3V (even though it is rated at 5V and is unlikely to be reliable).

You also have other devices apparently also powered by the Pico.

The 3.3V regulator is rated at 300mA so it likely this is a power problem.

The Pico is not designed to power peripherals and the high transient current when the relay operates is likely to drop voltage causing connection to drop.

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • What path should I check to see how much current the relay draws? Do you mean from it's own VCC to it's own ground? The components should be well under 300 ma per their datasheets, and I feel like lots of other people are powering components like this, and maybe they (links above) are incorrect to do so), but you have good point worthy to track down. I suppose I could get a second breadboard and power supply to see what happens...thanks for the thought.. – james6125 Sep 19 '23 at 03:22
  • Frankly I would power the relay from 5V, but then I would't use a relay to run a small motor - it just seems like an unnecessary complication. You could measure relay current with a multimeter - measuring transient is another matter but this is not an EE forum. – Milliways Sep 19 '23 at 03:55
  • OK thank you - perhaps this is more of an EE problem, but one never knows. Thanks for your comments. – james6125 Sep 19 '23 at 12:54
  • The problem is also that the inrush current can cause a short but very high current consumption. That can cause a short voltage drop that will cause the Pico to restart. To prevent this you could use a filter, a decoupling capacitor or its own PSU. Remember that all devices/PSU MUST share the same ground if you don't do any isolation (Thats another topic). Ref. https://en.wikipedia.org/wiki/Inrush_current – MatsK Sep 20 '23 at 09:31