Pixl LCD initialisation and output

Posted on
  • After quite a while of Espruino abstinence there is a new private project for me: a bicycle computer.
    When uploading code, doing a save() and a power cycle there is still the Pixl logo showing up before my code takes over the screen.
    Also when connecting or disconnecting via bluetooth sometimes output shows up for a fraction of a second.
    Where does that all come from - can it be disabled or avoided?

    Thanks for any pointers.

  • Wed 2019.10.30

    Welcome back from your respite @ChristianW

    Is there a tutorial being used that will assist us to follow along? Link please.

    I will defer to others, but until they respond, is that output intentional or is it a possible error being reported?

    re: 'sometimes output shows up for a fraction of a second'

    Beneath heading 'LCD Screen'


    "Any errors generated when there is no connection will also be displayed on the LCD."

    Are there any Espruino commands that are outside functions, that would be executed on upload, before the E.on('init') fires?


    'can it be disabled or avoided?'

    From tutorial below heading 'Tutorials', use of g.clear() function perhaps?


    also from same link below heading 'Graphics'

    What about clearing an off screen area, then flip that into view?

  • Take a look into jswrap_pixljs.c

  • Thanks @MaBe for the link.
    It seems


    is causing the output after initialization just before I do the g.clear() and g.flip().
    To avoid this I guess I'd have to patch it and compile my own firmware?
    Or is there some more elegant way around this?

    The function also seems to contain some button magic like self test that would be missing if skipped altogether...
    I'll look into this some more tonight after work.
    Thanks for the pointer.

  • @Robin thanks for your reply.

    My code is still in early stages. Advertising a CSC and battery service already works as far as I can check with NRF toolbox on my phone.
    I also successfully connected some I2C modules for voltage and current measurement (energy monitoring of my Lipo on-board battery block for light) and RTC (which is a bit bulky but somehow works too).

    The output is the lines "Bluetooth" being written to the LCD when a BLE central (phone or laptop) connects or disconnects like you can see here: https://youtu.be/pawHDr4i3jI?t=126

    It is the same output written when you just see the boot screen and no code is loaded.

    But it still seems to happen with my code running and somehow interferes with my "g" screen outputs. It will disappear on the next update interval with g.clear() and g.flip() but you will notice it as a flicker sometimes.

  • Yep, custom firmware.

    Maybe a define in the board file to exclude the sections and some ifdef in the function.

  • To avoid Bluetooth connection writing to the screen, just call Bluetooth.setConsole(true)

  • @AkosLukacs - ah. Thanks a lot!

  • Wow, yeah - custom firmware seems like overkill :)

    The Pixl.js logo is displayed at boot, and after a reset it's only there for a fraction of a second - a g.clear();g.flip() in your code would probably get rid of it pretty quickly.

    If it was a real problem for you I could probably modify the firmware to have a flag that disabled that behaviour though - this is the first time it's come up.

    However it seems the real issue here is the text that appears on connect/disconnect? That's just as @AkosLukacs said - the REPL goes to the LCD by default, and Bluetooth.setConsole(true) will force it to stay on Bluetooth.

    ... it's work leaving on the LCD for development purposes though - if your code causes some kind of error then you'll get a stack trace on the screen, which can save you a lot of trouble!

  • Thanks @Gordon.
    Meanwhile I tried the Bluetooth.setConsole() and it works.
    Now I understand what it was about.
    The other thing is only cosmetic. No trouble currently, but sometimes I am trying to be a perfectionist. Actually there were two things why it struck me:

    1. I am using the screen 9o° rotated so the Logo appears sideways. Looks a bit odd.
    2. My onInit() did not do the screen refresh right away, but only a setInterval()so there was a delay till my own layout took over. I have fixed this now.
      But for the "final touch" I will probably consider doing something about the startup animation. If you don't mind. ;-)
  • What about a custom splash screen stored in flash and named “.splash”?

    Should include image and rotation.

    If .splash exist use it, otherwise load custom.

  • What about a custom splash screen stored in flash

    That sounds like a great idea! I can always make a zero-size file mean there is no splash screen.

  • @Gordon I hoped you would say that ;-)

  • Just done - if you use a new firmware, create an image, go to http://www.espruino.com/Image+Converter and create it to a 1bpp white/black 'image string'. Then write to storage:


    There's no rotation done, so you'll need to rotate it yourself to landscape, then sort out what you need rotation-wise in the init code :)

    You may also have the image shifted up by one line because of the terminal, but you can actually disable the terminal completely by removing the internal link to the graphics object. Either do it right at the start of your 'save to flash' code, or add E.setBootCode('delete global["\xff"].gfx')

  • Perfekt - Thanks!

  • Thanks @Gordon.

    I just picked up on this, compiled+compiled a new firmware.
    And it works - but not just as expected.

    Using a 90°CCW rotated flash image (see code) below.
    Showing the image with g.drawImage() seems okay.

    Maybe I am doing something wrong here, but two things happen after flashing:

    1. after storing the flash and power-cycling the left lines (or lower lines if not rotated) of the image are blank - maybe this is something about the terminal you mentioned
    2. doing a manual reset() after installing also gives an error message:

     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v04.228 (c) 2019 G.Williams
    Uncaught Error: Expecting first argument to a valid Image

    This is my complete code, including the 90°CCW rotated image:

    // just a test to show that the image works
    g.drawImage({width:128, height:64, bpp:1, buffer: buf});
    // write to flash
    require("Storage").write(".splash", buf);
    E.setBootCode('delete global["\xff"].gfx');
    function onInit() {
      Bluetooth.setConsole( true );
  • I think the image needs to be an 'image string' - looks like you maybe just exported it as 'image object' from the image converter - so ideally just typing g.drawImage(buf) should do it

  • Thanks @Gordon for the quick reply.
    But there is no issue with g.drawImage() - it shows correctly.

    It even is drawn after a power cycle - only the bottom few lines (or left part if you hold the Pixl in portrait mode) are missing (see photo).

    1 Attachment

    • IMG_4174.JPG
  • Have you tried the delete global["\xff"].gfx code? Those lines sure look a lot like what I'd expect happens with the terminal (although the newest builds should stop that automatic newline at boot now)

  • See my code above.
    I think it's in:
    (line 11 quoted from above):

    E.setBootCode('delete global["\xff"].gfx');

    Also checked:

    >s = require('Storage');
    =function () { [native code] }
    ="delete global[\"\xFF\"].gfx"
  • Sorry. My bad.
    Found it by trying around - maybe it's just the lack of understanding the internals... especially what belongs to onInit() and what does not.

    I removed the E.setBootcode() completely and moved the Bluetooth.setConsole(true) from onInit() to just the first line of the code.
    Now the splash screen is complete.

    Thanks @Gordon

    It's working now! (yay)

    And I also upgraded my bangle pledge to the early ones delivered in December by the way ;-)

  • Update:
    It wasn't working. Somehow. Just by accident.
    The issue was: I did not create an image string, but an image object.

    NOW it works!

  • Great! :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Pixl LCD initialisation and output

Posted by Avatar for ChristianW @ChristianW