Openwrt GPIO + Expansion + Scripts

https://wiki.openwrt.org/doc/hardware/port.gpio

pic2.png

pic1.jpg

GPIOs are commonly used in router devices for buttons or leds. They only safely supply or sink (pull to GND) a maximum of 4mA aprox., and the voltage is usually 3.3V when active. Only two states are posible: high or low. Depending on how a device is activated by a GPIO, active low or active high is defined.

      Active high: the device is activated when the GPIO is HIGH
      Active low: the device is activated when the GPIO is LOW

Bi-Directional MOSFET Voltage Level Converter 3.3V to 5V

When connecting 3.3V devices and 5V devices voltage level conversion is required. The following circuit will allow this to be done bi-directionally

pic1.jpg

Low Side Control

When the low side (3.3V) device transmits a '1' (3.3V), the MOSFET is tied high (off), and the high side sees 5V through the R2 pull-up resistor.
When the low side transmits a '0' (0V), the MOSFET source pin is grounded and the MOSFET is switched on and the high side is pulled down to 0V.

High Side Control

When the high side transmits a '0' (0V) the MOSFET substrate diode conducts pulling the lowside down to approx 0.7V, this is also low enough to turn the MOSFET on, further pulling the low side down.
When the high side transmits a '1' (5V) the MOSFET source pin is pulled up to 3.3V and the MOSFET is OFF.

Note: This works with I2C and other open collector type gates

No 3.3V Supply?

If you dont have access to the 3.3V supply (maybe the 3.3V voltage regulator is on a breakout board) you can simply tie the gate to 3.3V via a simple voltage divider as in the diagram below

pic2.jpg

2N7000 MOSFET product page

Schottky Diode Logice Level Conversion

When connecting 3.3V devices and 5V devices voltage level conversion is required. The following circuit will allow this to be done bi-directionally using only a schottky diode and resistor. A schottky diode is used because it's forward voltage drop is less than a normal diode (~ 0.3V)

pic1.jpg

The diode protects the 3.3V side of the circuit from the higher 5V side by being reverse biased.

When the low voltage side is sending

When the high voltage side is sending
Note: This circuit is NOT suitable for I2C or SPI communication as the 3.3V (low) side cannot pull down the 5V (high) side

Labels: my.