Switching power to components from a MCU?


(Filip) #1

Hi,

I have some cheapo OLED displays which have been so cost-optimised that they omit the reset pin in favour of expecting the user to toggle the power to the display off and on again in order to reset it. Now, when prototyping I can do that by just removing and replacing the wire, but I want to be able to switch it off and on again on MCU reset. What’s the best solution to this? I don’t think I can power the display directly from a GPIO pin on the ESP32.

I probably need a transistor. Which type is best to use here and why?

Filip


(electrotech) #2

I don’t know how much of a deep sleep, low power mode you’re aiming for but perhaps just blanking the oled display is enough?

Or trying

https://lexus2k.github.io/ssd1306/oled__ssd1306_8c_source.html#l00118
ssd1306_sendCommand(SSD1306_DISPLAYOFF)
This should allow it to sleep and be woken with displayon.

The esp32 can source about 14mA safely.
Adafruit basically stated their oled modules are around 20mA consumption.

This person has attempted to graph power consumption based on switched on pixels

I would say you can likely get away with using a gpio to drive the oled module. Just keep in mind brightness and percent of pixels illuminated.

The transistor to use really doesn’t matter much. A common transistor like bc547 or 2n2222 etc. Youre not driving a particularly big load nor is it inductive therefore almost anything will work fine and won’t be many components.

Good luck and report back.


(Filip) #3

I thought of that but this particular module seems to need a reset when the MCU resets too - otherwise it doesn’t work. I’ll investigate more. Thanks for the in-depth reply!


(electrotech) #4

That sounds annoying. Hmmmm…

Anyway sure no problem, good luck. Lol


(Alexander Baxevanis) #5

I used a BC337 which I found in the box of electronic components in the space to drive a motor.

This has a lot of details about the actual calculations, but for something like what you’re building it won’t matter too much: https://teachmetomake.wordpress.com/how-to-use-a-transistor-as-a-switch/


(Andrea Campanella) #6

You should chose your transistor to fullfil the power requirements of your oled.
But be careful, if you chose a BJT they do consume power even when they are not powered


(Calum Nicoll) #7

What do you mean by that? Not something I was aware of - are you meaning leakage current (in the region of nanoamps for many transistors).


(Filip) #8

Thanks for all the replies everyone. What I ended up doing was connecting the display’s ground line through the transistor (see schematic) - which seems like a common arrangement for transistors, I’m guessing because of that leakage current which has to go somewhere?
image

Also for some reason this module seems to need me to toggle the connection twice for a reliable reset. Oh well, I guess that’s what I get for being a cheapskate when it comes to parts.


(Calum Nicoll) #9

I’d suggest you switch the power (+Vcc) line instead - cutting the ground while the rest of the circuit is powered may lead to issues, some of which may be difficult to diagnose. What chip is on the oled, SSD1306?

Also you definitely want a resistor on the transistor gate to limit the current - if you’ve connected this to your microcontroller directly as in schematic this is effectively shorting it to ground. Do you have a fuller schematic?


(Andrea Campanella) #10

yes, switch the power off, I saw oleds working with power disconnected before, using the low level of the spi as ground…weird stuff.


(Filip) #11

Full schematic looks something like this:


And yeah it’s a SSD1306 based module.

…I’m gonna use the “well nothing blew up” defence, but that’s a good point