How to use PICO with OLED and MOSFET?

Posted on
  • Hi, I just want to ask about proper connection for Pico with OLED SSD1306 and Mosfet in VCC line for OLED.
    I want to save more current on the battery, yesterday I left OLED connected to PICO and li-po battery, OLED was cleared, and today battery is empty, thought to use Mosfet to steering VCC supply line for OLED, but what I noticed is when I put (in my case B4) gate pin to 0 (digitalWrite(B4,0)) 0r (analogWrite(B4,0)) then my OLED still works. Screen isn't blank.

    any advice how to switch this Mosfet off to cut off current for OLED?
    I use IRFZ44N Mosfet

  • That MOSFET is 4.5v logic level. The Espruino is a 3.3v device. You can't fully turn it on with 3.3v

    That's an N-channel MOSFET. Yet you say you're using it to switch the Vcc side. In order to turn it on, you would need to apply a voltage 4.5v above the source voltage to the gate - meaning you'd somehow need to get and control 7.8v+ just to control the mosfet.

    You need a P-channel logic level MOSFET if you want to switch the positive side, and you need it to be rated for Vgs < 3.3, otherwise you can't turn it on.
    Alternately, you can use an N-channel logic level MOSFET, and switch ground side, but you still want one with RDSon spec'ed for Vgs under 3.3v

    Actually, I think you may have to use N-channel fet and switch low side if it's I2C, because if you switched the high side, it would draw current through the pullups - probably not enough to work, but enough to waste power.

  • I would look at the OLED's datasheet (and/or google)

    While it isn't exposed in the driver, you can turn the OLED off using software, and it'll save you a lot of power.

    For instance the fitness watch I disassembled uses a SSD1306 and can last for a very long time on a charge - it doesn't add a MOSFET to control it, but instead just uses software to turn it off.

  • Tnx Lads, Gordon do you know the command for SSD1306 to switch it off and on again?
    would that be for OFF 0xae and for ON 0xaf ?
    should I use it in that form you made it in your watch code like that "cmd(0xaf);" ?

  • The watch code was actually really nasty because I was trying to squeeze it down really small, but yes, 0xAE/0xAF are the commands you want.

    I'd add a function called setPower or something if I were you (rather than using cmd directly). I guess it's possible you might be able to get the power consumption down even more with some other commands.

    It's a shame you can't easily extend the graphics lib at the moment... I think if you were going to commit a modified module for everyone else to use, using cmd would be a good idea though.

  • could you help with proper form for this command?
    cmd(0xae); isn't work when I tape it in Espruino Web IDE console,
    is there any example how to use commands in this case?

  • Did you just add:

    function cmd(c){cs.reset();dc.reset();spi.write(c­);cs.set();}
    function dispoff(){cmd(0xae);}
    function dispon(){cmd(0xaf);}

    If it doesn't work, my guess is because you haven't defined cs, dc, or spi variables?

    It might actually be you don't have a cs line, in which case you can reduce the whole command to spi.write(0xae,dc);

  • I have I2C OLED

  • Ok, then change cmd to send over I2C. I think i2c.writeTo(0x3C, [0,c]); should do it.

  • I tried this but won't work in my case, possibly code from is wrong?

    function i2c(c){i2c.writeTo(0x3C, [0,c]);}
        function dispoff(){i2c(0xae);}
        function dispon(){i2c(0xaf);}
  • I don't know what your code is, but chances are you actually want I2C1.writeTo, or whatever I2C port you're using.

  • this is the code

        function i2c1(c){I2C1.writeTo(0x3C, [0,c]);}
            function dispoff(){i2c1(0xae);}
            function dispon(){i2c1(0xaf);}
    function OLED(){
    var g = require("SSD1306").connect(I2C1);

    but this only change the position of string displayed on the OLED,
    when I type 'i2c1(dispoff)' or 'i2c1(dispon)'

  • I am working with a OLED over I2C and use module "SSD1306".
    Some times I only see lots of dots instead my text, guess I have to add pullups (4.7K) to SDA and SCL.

    this is what's working for me:

    // running on esp8266, 1v85.MaBe_master_6c6dc46
    function go() {
     g.drawString("Hello World!",2,2);
    var g = require("SSD1306_I2C").connect(I2C1,go,{­height : 64,contrast : 127});
    // switch disp off
    // switch  disp on
  • sorry don't know what format tags to use for code ?!

    where using the correct tags but missed empty line, now it looks like code

  • function i2c1(c){I2C1.writeTo(0x3C, [0,c]);}
    function dispoff(){i2c1(0xae);}
    function dispon(){i2c1(0xaf);}

    What do you expect that to do? Probably not what it's doing.

    You create a function called i2c1 which takes an argument, and sends that to the display.

    You also create a function called dispoff which calls that first function with the appropriate argument to turn off the display.

    But when you do i2c1(dispoff) you're telling it to send the function dispoff to the display (I have no idea what Espruino actually sends here, but I guarantee it's not what you want).

    Instead, you want to just call dispoff, eg dispoff();

    (which is pretty much what MaBe has posted)

  • MaBe your way is working for me too ;)
    thank you

    DrAzzy, I still learn javascript code proper form ;)

  • @bigplik do you sometimes see lots of dots on oled instead of the object you requested to display ?

  • @MaBe I see that dots sometimes, usually on the beginning, when I upload new code first, then when I upload it again I see on the display what I wanted,
    and also when I wake up the display I see something like a flash with dots in some parts of the display for a short time, and after details I wanted, I use graphic library from Espruino example
    Could it be something with unstable current? wiring? what you think?

  • @bigplik at the moment the OLED only shows wild dots...

    o added pullups 4.7K
    o it is completely ignoring any updates
    o on and off cmd is working

  • @MaBe it worries me that you're using some strange module SSD1306_I2C which doesn't exist in Espruino's repositories. Maybe try using the proper SSD1306 module first and see if you can get it working with that?

    The random dots happen if you have managed to initialise the display and turn it on, but haven't sent any data using flip() - so maybe flip() is broken in the module you're using?

  • @Gordon sorry for confusion, wrong copy paste, I am using SDD1306 as local module

    SDD1306_I2C is just a SDD1306 without SPI, to shrink size

    added some prints

    new Uint8Array([64, 0, ...
    new Uint8Array([64, 0, ...
    new Uint8Array([64, 0, ...
    new Uint8Array([64, 0, ...
    new Uint8Array([64, 0, ...
    new Uint8Array([64, 0, ...
    new Uint8Array([64, 0, ...
    new Uint8Array([64, 0, ...
  • solved, broken homemade build, have been using a build that generated stars or snow instead of display text .....

    After using a new build every thing is working as expected !

    If you start building firmware you should add comment to your source to remember you which build you used for that code ....

  • Before sending the init sequence a reset is needed, guess this is OLED specific. Mine is a 128x32 I2C from Adafruit and has a reset pin.

    Should be added to the module as optional parameter and toggled before sending the init sequence.

    calling connect:

    var g = require("SSD1306").connect(I2C1, start,{pin:PIN});

    add to module SSD1306:

      var addr = 0x3C;
      if(options && options.address) addr = options.address;
      // reset if pin is given 
      if (options && digitalPulse(,0,5);  // add 
      // configure the OLED
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

How to use PICO with OLED and MOSFET?

Posted by Avatar for bigplik @bigplik