Page 2 of 2

Re: STICKY: Common Pitfalls for Beginners

Posted: Sun Oct 22, 2017 12:10 pm
by mahjongg

Many people who tried to use a relay module with a raspberry PI has had difficulties getting it working, often finding what happened counterintuitive. like always going on, even when programming it as off, then doubting their software instead of the module. The main reason is that these modules are designed to work with a control system (like an Arduino) that uses 5V signalling, and the designers of these modules have not considered what would happen when one would try to use the module with 3.3V signalling, nor do the sellers of these modules care.
Lets look at a typical schematic of such a module:
typical sainsmart relay module schematic.jpg
typical sainsmart relay module schematic.jpg (17.52 KiB) Viewed 22732 times
this module contains an opto-isolator, (U1) which is great as it prevents any dangerous voltages that may occur when a current that is running through a coil (the relay coil) is forced off suddenly. This will create a very large voltage (called the EMF voltage, which can be hundreds of volts) in opposite direction of the current flow. This voltage is normally dissipated (shorted) into a "snubber", "flyback" or "back EMF" diode, but if this diode fails, the transistor might be destroyed, and the high voltage might end up at the base of the transistor (on R2) which can destroy the controller without the opto-isolator in place.

In the case of the above schematic the relay control circuit is wired to be "active low", that is a low voltage (compared to the relay control supply voltage, on pin 2 of the left connector block) will light up the LED in U1, which will send current trough R2, this will make the photo transistor in U1 conductive, which will open the transistor Q1, thus powering the relay coil.
However there are problems with this design;
normally the opto-isolator is powered with 5V on pin 2 (and GND to pin 1), and the IN0 input is expected to either go to 0V (GND) or 5V.

When grounded a current will flow through both LED's and the relay coil will be powered, and when 5V is put on the IN0 input there is no voltage over the R1-LED_of_U1-green LED string so both LEDs are off.

But if you put 3V3 on the IN0 pin, this isn't true! there will still be 5V-3.3V = 1,7Volt across both LED's, so a small current might still flow, maybe just enough to dimly light the LED in U1, lighting the photo transistor so that a small current trickles to R2, and the relay coil might get just enough energy to keep drawing in the relay armature, (metal plate that is attracted by the magnetic field) and so the relay may still keep its energized condition. A relay needs much less energy to magnetize the relay so much that the armature keeps stuck, than the energy needed to pull in the armature.

one could program the IN0 GPIO so that it becomes high-ohmic, and that would turn the relay off, but the downfall of that approach is that there might appear a voltage on the GPIO larger than 4V, and this might cause the dreaded "latch up" phenomenon as the GPIO's of a PI are NOT 5V TOLERANT! See for an explanation of what might happen. Just maybe the two diodes (LED's) might prevent latchup in practice, so it might work, but your mileage might vary!

The obvious solution to this problem would be to lower the voltage on pin 2 of the left connector block to 3.3V (but still leave 5V or perhaps 12V on pin 3 for the relay) but then you would notice another problem! To spare the need (price) for an extra resistor for the green LED, the designer of these modules has simply put the two LED's (the green signaling LED and the LED in the opto-isolator) in series, but that means that you need more than the sum of the two forward voltages of the two diodes (a LED is a diode) to get any amount of current running through them, that is to say (with the typical forward voltages of LED's, with a color from red to green, of about 2 Volt) we will need more than 2 x 2 = 4Volt, so 3.3Volt is not enough to light up the two LED's!

This renders these relay modules very hard to use with a 3.3V based system like a raspberry PI.
This problem is exacerbated by the fact that the seller of these devices (especially on e-bay) almost never let you see the schematic of the relay modules you can buy.

One solution would be to keep pin-2 on 3.3V but short out the indicator LED, but that means soldering ( a skill that anyone calling himself an electronic engineer cannot go without by the way, and its not as hard as it looks, just mind not to touch any of the metal of the soldering iron during use).

The best solution would be to keep the pin-2 voltage at 5V, and use another transistor (and base resistor) to turn on and off the LED current.

or simply buy a better suitable relay board, something simple without an opto-isolator like this will work fine:
you can also use this design with a 12V relay without problems.

Test without software control, before adding software control!
To test if a relay board works with 3.3V signaling, simply connect the control input directly (manually) to either 3V3 (3.3Volt) or GND, and see if it works as expected, after that you can worry about controlling it with software. Also, you can use a LED to test your software before connecting the relay board, if you have doubts about your software.

Re: STICKY: Common Pitfalls for Beginners

Posted: Mon Dec 25, 2017 11:52 am
by mahjongg

Often happens when you have changed the password from the default, and you have included some special characters like @ or # in the new password.
The cause is that the keyboard isn't giving out the characters you expect, due to localisation not being active or different than expected.
This is also true with some letters, notably the letter 'Z", when using a QWERTZ keyboard instead of a normal QWERTY keyboard.
You can check by entering the password when the system asks for the user name, so you can see what you are actually typing in.

Re: STICKY: Common Pitfalls for Beginners

Posted: Sun May 12, 2019 11:05 pm
by mahjongg

Besides obvious things like sledgehammers and acid baths, there are a number of electrical misconducts that will instantly destroy an RPI, and unfortunately with the introduction of the PI3B+ with its PMIC quad power supply chip, we have got one more to worry about.

Firstly: any voltage greater than about four (4.0) Volt applied to any of the GPIO pins will cause a latchup in the silicon of the RPI's SoC (system on a chip) that will burn up silicon around the GPIO's driver logic, causing a local short between the (3V3) power line and GND which overheats and burns up more silicon, which only ends when power is removed.

Secondly: prolonged drawing (much) more than 16mA into or out of a GPIO pin, or drawing more than 50 mA into or out of a combination of GPIO pins, will burn out internal metal traces inside the chip, which will disable the affected GPIO's, and if you are unlucky will overheat and cause internal shorts.

thirdly: exposing the 5V input to more than six volts will trigger an overvoltage protection diode, which acts like a triggered thyristor and will short the 5V line to ground. If you are lucky this will trigger the polyfuse, which will protect the diode, and after the polyfuse self-repairs the RPI might come back to life. If the input voltage was much more than six volt, and the supply used was "hard" (able to deliver lots of current) there might still have been (much) more than six volt on 5V powered devices, which might have been destroyed. If you have bypassed the polyfuse, the protection diode will probably burn to a crisp, but it's "self sacrifice" might have saved the rest of the RPI, plus 5V devices connected to it, and after replacing it with a new diode the RPI might live. Note that the new RPI4B no longer has a polyfuse, but still has the OVP diode, and that Zero's have neither polyfuses, nor OVP's.

forth: t he new PMIC smart quad switching supply has one weakness that older linear regulators didn't have (or were less susceptible to), and that is they don't tolerate much higher output voltages than the regulated output voltage on their outputs, In the old situation if you connected the 3V3 rail to 5V, you would put 5V on all 3V3 powered inputs, and if you did that for a few seconds, the 3V3 logic might be fatally damaged, but it might also survive. Not so for the PMIC, it will be instantly destroyed if you do this, and unlike a simple LDO the PMIC cannot be simply exchanged. It seems that this problem was fixed in later PMIC's, but don't coun't on it, expect that connecting 5V to the 3V3 rail will still be fatal, for the reasons given.

fifth: ESD (static electricity) can easily zap your PI, when during dry weather you walk over carpet (or some other surfaced) your body can be charged up to thousands of volts, if you then touch an RPI you can easily damage sensitive electronics. Its therefore best to put your PI in some kind of enclosure, or discharge yourself to earth before touching the RPI.

sixth: don't put your PI on a conductive surface, without isolating it from that surface, you will cause all kinds of shorts, which can damage your RPI easily

Several of the effects above can be brought about by plugging things in (on a breadboard) while the PI is powered up, so NEVER modify your breadboard, or plug things (including HAT's) into the GPIO, while the PI is ON!!!!

so be aware that if you do any of these things you can throw away your RPI, as its not economically feasible to repair them, especially if its the SoC that gets damaged.

TLDNR: don't do any of these things:
  • don't apply 5V to a GPIO
  • don't draw large currents from a GPIO
  • don't Power the PI with too much voltage
  • don't short the 3V3 output to the 5V input
  • be careful, but not paranoid, with static electricity
  • don't short the underside of the PI by placing the PI on a conductive surface
  • don't fiddle with things connected to the GPIO while the PI is ON!

Re: STICKY: Common Pitfalls for Beginners

Posted: Fri Sep 06, 2019 9:06 am
by mahjongg

An RPI4 has two HDMI outputs, a primary and a secondary, its not quite obvious which is the primary, and the secondary HDMI-1 is ONLY enabled when you already are using the primary HDMI-0 output.

The left HDMI output (closest to the power input) is the PRIMARY (HDMI-0) output.

Also, for now, the secondary HDMI output (HDMI-1) doesn't seem to support sound, although that might change in the future.