tlfong01 wrote: ↑
Thu Jun 14, 2018 5:43 am
Now I am using a python program to test KY-019 NPN HIgh Level trigger module. The program can control KY-019 Type 1 and 2 modules using Rpi GPIO pin 17 at 3.3V, without any logical level driver.
However, Type 3 and Type 4 modules are not responding.
I know the reason is that the modules are not responding to Rpi's 3.3V GPIO signal, because the modules are designed for Arduino's 5V GPIO signals. So I need a logical level converter to convert Rpi's 3.3V signal to Arduino compatible 5V signals. I remember there is a get around of setting Rpi GPIO to input to turn of the relay, but this get around has itself some problems. So I will not use it now.
Now I read one of my old forum posts to refresh my memory on level converter.
Notes on Logical Level Converters
There are many ways to do level shifting. I first learnt the idea from NXP
NXP I2c Logic Level Shifting Notes
https://www.nxp.com/docs/en/application ... N10441.pdf
Then I assembled a I2C bidirectional level shifter as suggested by NXP, using 2N7000. It was a good learning experience. But the soldering work is boraing. So I will not try it again.
Anyway, if you have an I2C level converter, then the next step is to try the MCP23017 IO expander, wtih 16 IO port to control 16 relay modules.
MCP23017 IO Expander
I tried the MCP23017 io expander, and mux 4 of them, so that I could control 64 relays at the same time.
i2c mcp23017 notes
https://electronics.stackexchange.com/q ... are-active
The above are a bit challenging and might take you weeks to catch up. If you are in a hurry, I would suggest you AdaFruit or SparkFun's MCP23017 tutorials for beginners. They also sell newbie friendly modules to help you jump start.
Logical level shifting using HCT125
I2C stuff is hard, an easier method is HCT125. Adafruit has a good tutorial, and rpi example. I have been using HCT125 in some of my projects, using 4 chips to up shift 16 rpi gpio pin signals. You can use OE to disable and mux to as many pins as you like. One good thing of HCT125 when comparing to other source or sink driver is that it can both drive and sink. One bad thing is that the HCT125 wiring and soldering is a bit messy.
74AHCT125 - Quad Level-Shifter (3V to 5V)
Logic Level Up Shifting using HC04
Different approaches have different pros and cons, and you need to make an engineering trade off, or cost benefit analysis. If you wish to control 128 relays placed far far away, I2C MCP23017 is good; if you want to Mux/OE (Output enable/disable) the relay modules, then HCT125 is good; if you wish to up shift to different levels (not just 3v3 to 5v0, but 3v3 or 5v0 to 12/24/36V, then HC04 Quad Open Drain NAND gate is good. I once tried HC04 for a 817c photocoupler driven relay module and found it working OK.
Up shifter using 2N2222
And if you want to entertain only one relay module, then the 4 shifters in 1 chip HCT125/HC04 is a waste or overkill. Then you may consider single transistors (such as BJT NPN 2N2222, MosFet 2N7000). I tried 2N2222 the other day and found it OK.
DIY your own module using 2N2222
If you are a DIYer or maker, and you want to build everything yourself, then you can start with a bare Songle relay and use 2N2222 to drive it.
Built Your Own 5V Relay Module [using 2N2222, driven by rpi] - Nick Momrik 2017jul05