Esp32 QRCode generation and decode

Use this section to discuss your embedded Flowcode projects.
Post Reply
mnfisher
Valued Contributor
Posts: 1819
http://meble-kuchenne.info.pl
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 860 times

Esp32 QRCode generation and decode

Post by mnfisher »

So QR code (Quick Response code) - were mentioned - and I thought I'd experiment with the esp32 components for this...

First up. Generation - note that Flowcode includes a DrawQRCode component - and this will display a code on a display.
However - to test decoding, to allow use in a web page from an esp32 server, or for other uses - I tested the component. Here is a very simple program that generates a QR code - and outputs it to UART. The component allows a range of sizes / error corrections etc (as does the Flowcode component - and that is not limited to esp32)

To add the component - create the FC project (DO NOT call your project qrcode! - this will cause things to break) - and attempt to compile (which will fail)
Navigate to the project directory in a cmd prompt.

Code: Select all

C:\Espressif\frameworks\esp-idf-v5.5\export  (Adjust path to suit) 
git init
idf.py add-dependency "espressif/qrcode^0.2.0"
idf.py fullclean (or idf.py menuconfig and alter the flash size or other setting to force a rebuild)
idf.py -p COMn -b 921600 (set COMn to suit or rebuild from Flowcode)
Open a terminal to the esp32 (using PuTTY or similar) - and check the QR code using your phone (it works!)

Next to look at outputting the QR code to a display (mimicking the FC component) - and then onto testing the quirc decoder. Then the camera module - to create a QR code reader!

Martin
Attachments
qrcode_test.fcfx
(7.47 KiB) Downloaded 42 times

mnfisher
Valued Contributor
Posts: 1819
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 860 times

Re: Esp32 QRCode generation and decode

Post by mnfisher »

... and a first attempt at drawing a QR code - Here on an esp32s3 with and ili9488 (parallel) display. I had to make each 'pixel' a 5 x 5 rectangle - 1 x 1 is too tiny for my phone to read!
It also ignores the x,y co-ords at the moment and always draws the code at 0,0.
However - it successfully demonstrates using a callback to draw the code :-)
Attachments
qrtest.fcfx
(18.94 KiB) Downloaded 47 times

mnfisher
Valued Contributor
Posts: 1819
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 860 times

Re: Esp32 QRCode generation and decode

Post by mnfisher »

And to decode....

This just creates a QR code - and then decodes it using 'quirc' - I struggled initially to get the decoder to recognise any QR code (the image can contain multiple - just one here) - and the 'trick' was inverting the image - originally I created it as white (255) on black (0) - but it needs to be black on a white (background). This led to experiments with scaling the image - but it wasn't necessary - 1 pixel per module (with a 4 pixel border) is sufficient.

Create the Flowcode app and add the qrcode component (as above) - then add the quirc component using :

Code: Select all

idf.py add-dependency "espressif/quirc^1.2.0"
fullclean and rebuild.

I used a simple buffer (qrcode) to store the generated code - it has space for a 171x171 QR code (+ 8 border) - this is overkill for the example. Using malloc would be better!

I also used menuconfig to modify the stack size to 32k and changed the flash size to 4MB

It outputs to UART (use PuTTY) !

Martin
Next - the camera!
Attachments
qrdecode_test.fcfx
(19.46 KiB) Downloaded 3 times

mnfisher
Valued Contributor
Posts: 1819
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 153 times
Been thanked: 860 times

Re: Esp32 QRCode generation and decode

Post by mnfisher »

As it outputs the QR code text, QR version and ECC level - I used V for version - so it looks like

Greetings from Flowcode V5 - for a little nostalgia. I used v11 - but the encoder decided on a V5 QR code...

Post Reply