Very simple relay/switch - General Discussion and Assistance - CHDK Forum

Very simple relay/switch

  • 1 Replies
  • 243 Views
Very simple relay/switch
« on: 16 / April / 2024, 22:35:29 »
Advertisements
Can anyone give me any pointers on using a relay/switch with the GPIO pins?

What I have is a camera (Canon camera running CHDK) connected to my RPi. I have a script on the RPi running every minute which basically does this...

Takes photo
Downloads photo from camera
Deletes photo from camera
Resizes photo
Uploads photo

The problem is that the camera every so often crashes or dies for some reason, generally requiring me to press the power button. I've stabilised the script as much as I can which has improved things a lot. Getting hours of capture rather than minutes. I've also designed the script to detect whether the camera is turned on or off. If it is off the capture part of the script doesn't run and it outputs a message to a log.

The camera is running on 5V and I'd like to have some way to connect the GPIO to the camera on/off switch so when the script detects that the camera is turned off (this is simple via lsusb) it flips the switch and the camera turns on again.

Am I right in thinking a relay is the correct item for the job?
If so, any pointers, tips or advice on how to do what I want?

*

Offline reyalp

  • ******
  • 14082
Re: Very simple relay/switch
« Reply #1 on: 17 / April / 2024, 15:12:34 »
Can anyone give me any pointers on using a relay/switch with the GPIO pins?

What I have is a camera (Canon camera running CHDK) connected to my RPi. I have a script on the RPi running every minute which basically does this...

Takes photo
Downloads photo from camera
Deletes photo from camera
Resizes photo
Uploads photo

The problem is that the camera every so often crashes or dies for some reason, generally requiring me to press the power button. I've stabilised the script as much as I can which has improved things a lot. Getting hours of capture rather than minutes. I've also designed the script to detect whether the camera is turned on or off. If it is off the capture part of the script doesn't run and it outputs a message to a log.
FWIW, if you get the romlog (https://chdk.fandom.com/wiki/Debugging#Camera_crash_logs_(romlog)) and tell us a little more about the setup (which camera, details of the script) we may be able to help stabilize it further.

However, having reboot capability is generally a very good idea for something like this in any case.

Quote
The camera is running on 5V and I'd like to have some way to connect the GPIO to the camera on/off switch so when the script detects that the camera is turned off (this is simple via lsusb) it flips the switch and the camera turns on again.

Am I right in thinking a relay is the correct item for the job?
If so, any pointers, tips or advice on how to do what I want?
FWIW, you might get better answers on an RPi or other general electronics forum, since it doesn't really matter what the load is, just that it's ~5 volts and draws a few amps at most.  Google certainly turns up a lot of results for using relays or MOSFETs to control loads like that with an RPi. (edit: to be clear, asking / discussing here is completely welcome, I'm not saying your post is OT, just that non-CHDK specific resources should also be applicable)

That said, I believe @manoweb has run a quite similar setup for many years (see first links on this post https://chdk.setepontos.com/index.php?topic=14302.msg145505#msg145505), so maybe they'll comment if they're still on here.
« Last Edit: 17 / April / 2024, 17:58:10 by reyalp »
Don't forget what the H stands for.

 

Related Topics