supplierdeeply

Rpi GPIO controlled relay sometimes failing

  • 19 Replies
  • 1048 Views
*

Offline Sdack

  • ***
  • 169
Rpi GPIO controlled relay sometimes failing
« on: 28 / January / 2018, 00:00:22 »
Advertisements
Hi guys,

I've had my extended time-lapse rig running for about a month with mostly stellar and robust performance.  I've nearly got all the kinks out of my remote management, which I'll share with you in the near future but I'm writing to see if anyone has an insight into why I am getting the odd drop out of progress from time to time.

The rig is controlled by a Raspberry Pi Zero W.  It's plugged into mains power and connected to the wireless network of the school where it's situated, to document the build of some new classrooms.  The Rpi stays on continually and camera is powered up at 7:30am each day for nine hours, taking one image a minute (450 shots a day), using the awesome Multilapse script.

A couple of times in the last week or two I've checked the progress thumbnails on my web gallery and found that the rig has stopped working.  So, one time I went over to the school and found that the Rpi was working fine, with Multilapse looping but not connecting to the camera despite the fact that the camera was booting up each time the GPIO switched the poewr on.  The relay was simply flicking off again in a matter of seconds, which made me wonder if there wasn't enough power to keep it fully on.

However a simple reboot of the Rpi rectified the situation, which got me wondering if it might be an electrical build up of some kind over the several (hot, Australian Summer), days we've been having.

As a total novice I am intrigued by the idea of voltage equating to water pressure and, when I first set up the relay and measured the output, I was surprised to see that even when off, there was some voltage between it and the device it was supplying power to.  It made me think of a garden hose, once you turn off the tap, there's not as much pressure in the pipe, but if the water's got no open end to flow out of, some pressure will stay in there.

Because the camera is powering up, even when the rig isn't fully functioning, the problem seems to me to be in the control side of the relay rather than the 3.7v output to the camera.

Could this be the problem?

I've taken to rebooting the camera each day via a cron job and so far, so good, it's been three days working solidly.

Any ideas?

Cheers

Sdack



*

Offline Sdack

  • ***
  • 169
Re: Rpi GPIO controlled relay sometimes failing
« Reply #1 on: 12 / March / 2018, 19:15:31 »
Quick update...

I solved this issue with a reboot, so now I have a daily, middle of the night, cron job rebooting my raspberry pi and haven't had a problem since.

All good!

Re: Rpi GPIO controlled relay sometimes failing
« Reply #2 on: 12 / March / 2018, 19:33:44 »
The relay was simply flicking off again in a matter of seconds, which made me wonder if there wasn't enough power to keep it fully on.
Can you post a schematic diagram of how you have this wired up? If you are using an electromatic relay (i.e. one with a coil that closes contacts magnetically) there are some simple things you need to do to prevent issues from back EMF.

Quote
However a simple reboot of the Rpi rectified the situation, which got me wondering if it might be an electrical build up of some kind over the several (hot, Australian Summer), days we've been having. As a total novice I am intrigued by the idea of voltage equating to water pressure and,
Ummmm .. no.  Electricity doesn't work that way.

Quote
when I first set up the relay and measured the output, I was surprised to see that even when off, there was some voltage between it and the device it was supplying power to.
I'd need to see a wiring diagram that indicated where you were measuring the voltage to comment here.

Quote
It made me think of a garden hose, once you turn off the tap, there's not as much pressure in the pipe, but if the water's got no open end to flow out of, some pressure will stay in there.
You can charge a capacitor and sort of create something equivalent to your analogy.  But that's almost certainly not what is happening here.

Quote
Because the camera is powering up, even when the rig isn't fully functioning, the problem seems to me to be in the control side of the relay rather than the 3.7v output to the camera.
As mentioned earlier, I really need to see a wiring diagram / schematic.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline Sdack

  • ***
  • 169
Re: Rpi GPIO controlled relay sometimes failing
« Reply #3 on: 13 / March / 2018, 01:58:50 »
Hi Waterwingz,

My school classroom construction time lapse rig is still working happily, now approaching 50 days without a hitch.  I do still feel that I may be running under beginners luck though and really appreciate your interest.

Here's a diagram of the power supply (the physical power button is constantly depressed in this set up)

http://motioncircus.com/temp/RaspberryPi_RelayPowerCamera.jpg

I hope I've covered everything in your questions.

I look forward to your thoughts.

Sdack
PS. I've just ordered some N channel mosfets to replace the relay because I'm trying to pack everything into the housing of a cheap waterproof work light and the relay takes up a lot of room.

My latest rig uses a 12 volt supply into the enclosure, split into two 5v 2.5a USB outputs via a car cigarette lighter.  I have a cheap electric usage meter monitoring its power draw and I'm pleased to report that it's averaging around 8.5 watts.  I've got a 4G USB dongle in the enclosure, so this unit should be good for off-grid.  I only need to figure out a solar topped up battery supply and I'm good to go.


*

Offline Sdack

  • ***
  • 169
Re: Rpi GPIO controlled relay sometimes failing
« Reply #4 on: 16 / March / 2018, 04:10:06 »
Hey Waterwingz,

I've just been reading about using Mosfet's as logic level switches driving higher voltages and I am slowly (I think) starting to get my head around the workings of pull-down resistors and snubber diodes.

Please correct me if I'm wrong but, to use a dodgy water-based analogy again, a pull-down resistor is like a small relief valve in a length of hose pipe which, when the tap is open and the pressure is high, hardly makes any difference at all to the throughput of water.  However, when the tap is closed, assuming for the sake of illustration that the remaining water in the pipe is unable to run freely out of the open end of the hose, the pull-down resistor then allows the remaining water and therefore pressure in the pipe to dissipate completely.

Am I closer?

The 'missing thing' I've been vaguely thinking my system was lacking was based on stuff I've read but barely understood about floating signals or the 'back EMF' you mention in your previous post.  My rig, lacking a pull-down resistor 'somewhere' in the control signal from the GPIO, definitely has something of a 'floating' current in the relay control circuit but I don't think that's been the source of the problem I've been having because my relay only activates once a day, to turn the camera on in the morning, after which it stays on all day.

My rig failed again this afternoon.. here's a sample output from the multilapse.log file showing the error..

Code: [Select]
Sleeping 40s
sh: 1: cannot create /sys/class/leds/led1/brightness: Directory nonexistent
Temperature: sensor = 54 optics = 37
SSTT,20180316-131200,54,37
Checking brightness level
BV = 827 try_focus = 0 i = 40
Remote shoot!
nil
Resizing image...
image.jpg
5152x2896 -> 1024x576
5851741 bytes -> 160658 bytes

1 processed in 9.7541 seconds.
Uploading image...
Sleeping 41s
sh: 1: cannot create /sys/class/leds/led1/brightness: Directory nonexistent
Temperature: sensor = 54 optics = 37
SSTT,20180316-131300,54,37
Checking brightness level
*** *** *** Pre-shooting error
Turning camera OFF
ERROR: I/O error
ERROR: Could not close session!
Waiting 5s...
Making sure camera is OFF
Waiting 5s...
Turning camera ON
Waiting 5s for boot...
Connecting
ERROR: no matching devices found

You may notice the very high temperatures.. it was a hot one today here in the down under.  The camera is actually shaded where it's situated under the eaves of a building.  I did a test a couple of days back and another camera was reporting 10 degrees (Centigrade) hotter, in the Sun!

I need to get to the bottom of this

*** *** *** Pre-shooting error

Cheers
Sdack



Re: Rpi GPIO controlled relay sometimes failing
« Reply #5 on: 16 / March / 2018, 18:33:33 »
Here's a diagram of the power supply (the physical power button is constantly depressed in this set up)
http://motioncircus.com/temp/RaspberryPi_RelayPowerCamera.jpg
Can you give me a link to where you got the relay board and the dc-dc converter board?  There is enough circuitry on the relay board to suggest it has good surge and  back-EMF protection.  I'm also curious about the peak current output capability of the DC-DC converter.

I've just been reading about using Mosfet's as logic level switches driving higher voltages and I am slowly (I think) starting to get my head around the workings of pull-down resistors and snubber diodes.
Based on my answer above, going the MOSFET route might be solving a problem that you don't have.

Quote
Please correct me if I'm wrong but, to use a dodgy water-based analogy again, a pull-down resistor is like a small relief valve in a length of hose pipe which, when the tap is open and the pressure is high, hardly makes any difference at all to the throughput of water.  However, when the tap is closed, assuming for the sake of illustration that the remaining water in the pipe is unable to run freely out of the open end of the hose, the pull-down resistor then allows the remaining water and therefore pressure in the pipe to dissipate completely. Am I closer?
Hmmm .. technically a "pull-down" resistor is just a resistor with one end connected to ground/earth/0V.  Just like a "pull-up" resistor has one end going to Vcc/5V/12V. Either type can have multiple different purposes. Your analogy is to a discharge bleed application - not the most common application and not relevant here but technically valid.

Quote
The 'missing thing' I've been vaguely thinking my system was lacking was based on stuff I've read but barely understood about floating signals or the 'back EMF' you mention in your previous post.  My rig, lacking a pull-down resistor 'somewhere' in the control signal from the GPIO, definitely has something of a 'floating' current in the relay control circuit but I don't think that's been the source of the problem I've been having because my relay only activates once a day, to turn the camera on in the morning, after which it stays on all day.
Back EMF is usually handled with a diode across the relay coil.  I suspect the device you are using has one of these installed.

Quote
My rig failed again this afternoon.. here's a sample output from the multilapse.log file showing the error..
Code: [Select]
sh: 1: cannot create /sys/class/leds/led1/brightness: Directory nonexistent
Might be a good idea to fix this but I suspect it's not related to your current problem. More like the author trying to dim the LED's on a standard (not zero) Pi? Comment out line 156 that says :
Code: [Select]
os.execute('echo 0 >/sys/class/leds/led1/brightness')
Quote
Checking brightness level
*** *** *** Pre-shooting error
Turning camera OFF
From what I can understand about the code, this error happens if the camera can't get a focus/exposure lock (lines 46-65) after three tries - where each try waits three seconds after doing a "half press" for the lock to happen.

But when that happens, the code tries to turn off the camera via the external relay and restart everything.   The Pi continues to run but it can't reconnect to the camera.  Despite removing the power and reconnecting. That's very strange - I must be missing something here.



Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline Sdack

  • ***
  • 169
Re: Rpi GPIO controlled relay sometimes failing
« Reply #6 on: 16 / March / 2018, 23:41:34 »
Hey Waterwingz,

Thanks so much for your support and insights.  I'm constantly amazed at the generosity and knowledge of the people on this forum.  You rock!
Quote
Can you give me a link to where you got the relay board and the dc-dc converter board?  There is enough circuitry on the relay board to suggest it has good surge and  back-EMF protection.  I'm also curious about the peak current output capability of the DC-DC converter.
This is the DC - DC buck converter..
https://www.ebay.com.au/itm/DC-DC-Step-Up-Down-LM2577S-LM2596S-Power-Boost-Buck-Voltage-Converter-Module/222836929873?epid=24008511053&hash=item33e21db551:g:cNcAAOSwttVaRKAM
It claims the following "Output current:maximum 3A", which should be enough considering it's only powering the camera.  The Rpi has it's own separate 5v input.  On this school based rig these two 5volt supplies are output from a single 220 V AC USB wall wart, which claims a 5A maximum output.
Quote
Based on my answer above, going the MOSFET route might be solving a problem that you don't have.
Aside from my naive thinking that a mosfet would consume less power than the magnetic coil in a relay, I'm trying to build a new rig inside the, reasonably weather-resitant, lamp housing of one of these a cheap work lights


and the relay was the bulkiest item in the enclosure.  I've just managed to get a new version working and it's a lot neater with the mosfet laying flat against the perfboard base.

Quote
Hmmm .. technically a "pull-down" resistor is just a resistor with one end connected to ground/earth/0V.  Just like a "pull-up" resistor has one end going to Vcc/5V/12V. Either type can have multiple different purposes. Your analogy is to a discharge bleed application - not the most common application and not relevant here but technically valid.
D'oh!  [slaps own forehead]
Code: [Select]
sh: 1: cannot create /sys/class/leds/led1/brightness: Directory nonexistent
Fixed this one up, thanks.

Quote
Checking brightness level
*** *** *** Pre-shooting error
Turning camera OFF
Quote
From what I can understand about the code, this error happens if the camera can't get a focus/exposure lock (lines 46-65) after three tries - where each try waits three seconds after doing a "half press" for the lock to happen.
Would setting a manual focus help here do you think?  I know the command or setting it with my camera, just not exactly where I should put it in the multilapse.lua script.
[/quote]
But when that happens, the code tries to turn off the camera via the external relay and restart everything.   The Pi continues to run but it can't reconnect to the camera.  Despite removing the power and reconnecting. That's very strange - I must be missing something here.
[/quote]
Code: [Select]
Turning camera OFF
ERROR: I/O error
Is it possible that the turnoff GPIO script is failing here, so the camera power isn't fully switched off and therefore isn't rebooting cleanly?
Shooting in the dark here.. wondering if there's a way to add a log output to confirm relay functionality?

Cheers
Sdack

Re: Rpi GPIO controlled relay sometimes failing
« Reply #7 on: 16 / March / 2018, 23:56:50 »
It claims the following "Output current:maximum 3A", which should be enough considering it's only powering the camera.
Assuming it can do that for the current spike after each shot, that should be plenty.

Quote
I'm trying to build a new rig inside the, reasonably weather-resitant, lamp housing of one of these a cheap work lights
Nice.  Keep an eye on internal heat buildup though.

Quote
Checking brightness level
*** *** *** Pre-shooting error
Turning camera OFF
it's late here so I can't test now but two things occur to me. The first is to blindly double all delays in the script. And the other is to add code to log stuff on the camera itself. See if that tells you where things are actually dying. 

Ported :   A1200    SD940   G10    Powershot N    G16


*

Offline Sdack

  • ***
  • 169
Re: Rpi GPIO controlled relay sometimes failing
« Reply #8 on: 17 / March / 2018, 00:03:59 »
Thanks again,

Your suggestions are very sensible.. I could probably manage the delay doubling but the error checking is almost certainly beyond my means.

nighty night..

Sdack

Re: Rpi GPIO controlled relay sometimes failing
« Reply #9 on: 17 / March / 2018, 14:27:41 »
Your suggestions are very sensible.. I could probably manage the delay doubling but the error checking is almost certainly beyond my means.
I took a look at what I assume is the script you are using?

multilapse.lua

Does it always fail exactly at this point in the log you posted ?

Sleeping 41s
sh: 1: cannot create /sys/class/leds/led1/brightness: Directory nonexistent
Temperature: sensor = 54 optics = 37
SSTT,20180316-131300,54,37
Checking brightness level
*** *** *** Pre-shooting error
Turning camera OFF
ERROR: I/O error
ERROR: Could not close session!


If so, we can look for some specific coding error or interaction.  If not then it's more likely a general hardware problem.

There is not a lot of documentation on what @reyalp implemented with the con:execwait_pcall( ) used here :

Code: [Select]
status, ts, to = con:execwait_pcall[[return get_temperature(1), get_temperature(0)]]
so I can't tell if when it returns nil for status, does that mean the script failed to run on the camera or the script did run and returned an error code?  What I would do next depends on the answer to that question.


Ported :   A1200    SD940   G10    Powershot N    G16

 

Related Topics