User Tools

Site Tools


charlieplexing_on_the_esp32

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
charlieplexing_on_the_esp32 [2020/09/01 22:04]
49.180.4.219
charlieplexing_on_the_esp32 [2021/02/02 01:24] (current)
Line 2: Line 2:
  
 The ESP32 has a stack of GPIO pins allowing you to attach a whole bunch of LEDs. But it's a neat practice to try using fewer pins with several LEDs using Charlieplexing. There'​s quite a few things you can learn along the way. The ESP32 has a stack of GPIO pins allowing you to attach a whole bunch of LEDs. But it's a neat practice to try using fewer pins with several LEDs using Charlieplexing. There'​s quite a few things you can learn along the way.
 +
 +For all experiments in this article, I'll be using pins 21, 22 and 23 on the ESP32.
  
 Going back to basics, a simple single LED on a GPIO pin would be like this: Going back to basics, a simple single LED on a GPIO pin would be like this:
Line 36: Line 38:
 {{ :​charlieplexing:​schematic-2-pin.png?​nolink |}} {{ :​charlieplexing:​schematic-2-pin.png?​nolink |}}
  
-Although not pictured, both pins reduce the voltage to the LEDs using a resistor each. If we set the pin 21's mode to ''​OUTPUT''​ and set the pin itself to ''​HIGH'',​ voltage will be supplied from the pin. If pin 22's mode is also set to ''​OUTPUT'',​ but the pin is set to ''​LOW'',​ this is effectively making the pin become ''​GND'',​ providing a voltage potential drop, meaning that voltage will flow from pin 21, through the first LED and into pin 22.+Although not pictured, both pins reduce the voltage to the LEDs using a resistor each. If we set the pin 22's mode to ''​OUTPUT''​ and set the pin itself to ''​HIGH'',​ voltage will be supplied from the pin. If pin 23's mode is also set to ''​OUTPUT'',​ but the pin is set to ''​LOW'',​ this is effectively making the pin become ''​GND'',​ providing a voltage potential drop, meaning that voltage will flow from pin 22, through the first LED and into pin 23.
  
 This lights the first LED. LEDs being a diode means that the current cannot flow through the second LED. This lights the first LED. LEDs being a diode means that the current cannot flow through the second LED.
Line 42: Line 44:
 This concept of the pins being ''​OUTPUT''​ pins, one being ''​HIGH''​ and the other ''​LOW''​ is one of the important principles of Charlieplexing. This concept of the pins being ''​OUTPUT''​ pins, one being ''​HIGH''​ and the other ''​LOW''​ is one of the important principles of Charlieplexing.
  
-If pin voltages are swapped, pin 21 becoming ''​LOW''​ and pin 22 becoming ''​HIGH'',​ the reverse situation is created. Current will flow the other way around and light the second LED, but not able to pass through the first LED. +If pin voltages are swapped, pin 22 becoming ''​LOW''​ and pin 23 becoming ''​HIGH'',​ the reverse situation is created. Current will flow the other way around and light the second LED, but not able to pass through the first LED. 
  
 Let's build this onto the breadboard. The wiring is fairly simple so the breadboard layout is: Let's build this onto the breadboard. The wiring is fairly simple so the breadboard layout is:
Line 51: Line 53:
  
 <code c> <code c>
-#define LED_PIN_A ​21 +#define LED_PIN_A ​22 
-#define LED_PIN_B ​22+#define LED_PIN_B ​23
  
 #define DELAY 400  #define DELAY 400 
Line 104: Line 106:
 {{ :​charlieplexing:​schematic-3-pin.png?​nolink |}} {{ :​charlieplexing:​schematic-3-pin.png?​nolink |}}
  
-Notice there are now two groups of two LEDs, plus two more bridging across at the bottom. This arrangement lets us use lots of pin mode combinations to get all the LEDs to light up one at a time.+Notice there are now two groups of two LEDs, plus two more bridging across at the bottom. This arrangement lets us use lots of pin mode combinations to get each LED to light up on it's own.
  
 We'll trace the schematic to see what is needed to light LED1. If we set pin 21 to be ''​OUTPUT''​ and ''​HIGH''​ to supply voltage, and on pin 22, we set to ''​OUTPUT''​ and ''​LOW''​ to act as ''​GND'',​ then we can be pretty sure that current will happily flow on that path and LED1 will light up. We'll trace the schematic to see what is needed to light LED1. If we set pin 21 to be ''​OUTPUT''​ and ''​HIGH''​ to supply voltage, and on pin 22, we set to ''​OUTPUT''​ and ''​LOW''​ to act as ''​GND'',​ then we can be pretty sure that current will happily flow on that path and LED1 will light up.
Line 166: Line 168:
 | LED6 | OUTPUT LOW  | INPUT       | OUTPUT HIGH | | LED6 | OUTPUT LOW  | INPUT       | OUTPUT HIGH |
  
-Now it is time to breadboard the schematic. This can be tricky. I like to take the existing schematic and stretch it out to be as similar as possible ​as how it will be on a breadboard. I used KiCad to move the existing schematic to be laid out like this:+Now it is time to breadboard the schematic. This can be tricky. I like to take the existing schematic and stretch it out to be as similar as possible ​to how it will be on a breadboard. I used KiCad to move the existing schematic to be laid out like this:
  
 {{ :​charlieplexing:​3-pin-schem-stretched.png?​nolink |}} {{ :​charlieplexing:​3-pin-schem-stretched.png?​nolink |}}
Line 290: Line 292:
  
 Hope that helps you work through Charlieplexing on ESP32. Let me know if it helped and send me a pic of your breadboard. I'll post it on this page. Hope that helps you work through Charlieplexing on ESP32. Let me know if it helped and send me a pic of your breadboard. I'll post it on this page.
 +
 +Here's my lovely effort cramming everything on a small breadboard and using a 10-LED block:
 +
 +{{ :​charlieplexing:​charlieplexed-led-bar.jpg?​nolink |}}
charlieplexing_on_the_esp32.1598997873.txt.gz · Last modified: 2021/02/02 01:24 (external edit)