Barcode or QR code generation in Espruino

Posted on
  • There was a thread some time ago about QR codes. I'd like to generate them on the Bangle. Did anyone get a port of the javascript QR code generator working? I could potentially use a barcode, but QR would be much better...


  • @MaBe was asking about this recently as well.

    I don't know of one that has actually been used, but for the App Loader I use

    In the source (­blob/master/qrcode.js) it actually uses a QR code generator from­generator which looks pretty compact and should work - the rest of the file is more or less just boilerplate

  • Yep

    and there is a c implementation as well

    I am petty sure this should be created as JS module with at least a size a 64x64 one bit which is pretty nice readable on oled's and lcd's.

  • Thanks @MaBe and @Gordon. I'll try to dig into it; this is a demo/idea so unfortunately back burner for me at best. If anyone in this group gets there first...

  • Just had a quick look at this, and the code I suggested runs out of memory.

    I made a few quick changes to reduce RAM usage when saved to flash (eg getPatternPosition and similar can define the array inside the function) and minified, but while it's enough to load the functions it's not enough to run.

    The code itself uses normal (sparse) arrays heavily, so realistically it'd need changing to use Uint8Array to store the QR Code itself while it's being created. When that's done it might work, but that's a reasonable undertaking!

  • Uint8Array to store the QR Code itself while it's being created.

    Yes, something like a bitbucket to place the marks and pattern and then use xor to set the byte values.

  • I think it'd probably be fine even as a byte array - it's just right now as a sparse array it's 1 var per entry, so you're looking at 16x more memory than if you used a Uin8Array and 128x than if you packed it as bits :)

  • Thanks Guys! I appreciate the follow up. I'm short on time to spend on this, and lack the expertise that you clearly have. I think it would be a good and intriguing feature to have in the Espruino toolkit.

  • With some help there is now a qrcode lib in my custom firmware build.

    // running on linux build
    var g = Graphics.createArrayBuffer(128,64,1,draw­Pixel);
    var version = 3; // 29x29
    var text = "Espruino Rocks";
    var size = version * 4 + 17;
    var ECC = 3; // 3:high, 1:medium
    image = Graphics.createArrayBuffer(size,size,1, {msb:true});
    qrcode = require('qrcode').generate(text,image.bu­ffer,version,ECC);

    1 Attachment

    • Bildschirmfoto 2020-09-14 um 10.58.58.jpg
  • Nice - so that's actually compiled-in C code?

  • Nice - so that's actually compiled-in C code?

    Yes, in libs/qrcode/ and available with QRCODE in board file and USE_QRCODE in Makefile.

    Code size depends on version, e.g. only version 3 runs without NUM_ array.

    Let me know if you like to be added, so I come up with a pr for this.

  • Really nice! It would be great to roll that into the standard build @Gordon. My humble opinion, of course.

  • It's just given the lack of flash space on a lot of boards now this is a very specific bit of code to include.

    I think as Inline C (or even just JS - which should still be possible to do with some minor tweaking, or maybe an emscripten compile of the qrcode C) this would make a lot of sense.

  • or maybe an emscripten compile of the qrcode C

    Ok, got a.aout.js and a.out.wasm file

    Not sure how to include this generated stuff?

  • You'd have to google it - as far as I remember you can use a command-line switch to disable WASM

    edit: what I did for heatshrink in the browser might work:­-js

    But I don't know whether your wrapped emscripten code can be squished down further with some options

  • Thanks, this look's very helpful.

  • Hey, I am interested in generating qr code on the fly with my pixl.js (and bangle2)

    Do you have more complete code I could look at ?

  • Didn't continue working on the wasm stuff.

  • I did successfully get QR codes "working" in Espruino, but used an ESP32 for the Wifi. Being lazy, I just got a QR code generator and put it on a server then downloaded the image to the ESP32 and displayed it as an image. There are lots of websites to generate QR codes, so that might work for you also.

    I couldn't get it to work on an OLED screen (128x64), but had some success with an ST7789 AND ILI9341. This could have been due to the type of QR code I was using at the time.

  • Thanks for the answers

    For my use case I need the qr code to be generated by the device itself unfortunately

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

Barcode or QR code generation in Espruino

Posted by Avatar for billsalt @billsalt