Encoding and generating QR Codes

Hi.
I'm making a project on Arduino that will basically display a QR Code on a LCD.
First I was using the QR-Code-Generator as a base (this code was used to create the QR Code clock, and is available at: GitHub - extrame/QR-Code-Generator: Arduino Mega 2560 + SeedStudio TFT 1.0 QR Code Generator).
The problem is that it only generates codes of Version 1, those that can display a string with length above 16. And, besides that, it proved itself not so trustable for all kings of alphanumeric strings.

So, now I'm trying to use the qrduino library, which I succesfully generated images of the desired QR Codes on both Windows and Linux, but wasn't able to generate theses pictures on the Arduino.

It gives me some problems casting unsigned char to char, method references, etc.

Probably I'm not knowing how to use it, and I've never found any examples on how to use it.

Could someone tell me how to use this library or maybe provide me some example codes? I've already tried a lot and I'm still unable to generate the QR-Codes. I usually don't ask for this, but I've already googled a lot and got nothing that could be used.

Thank's!

This looks germane...
http://forums.adafruit.com/viewtopic.php?f=25&p=167154

Thank's for the quick reply.
I tried following up the answers on this thread, but no success yet. When I build the Makefile, I don't get an executable file for the dofbit.c, which I believe would help me.

And when I try to make the Makefile.avr, it says that the commands in there are wrong.

I've been playing with the qrduino code and finally got it to work on a NANO. I've attached the two sketches required on the NANO.
The qrencoder sketch has pre-built tables for 1,1 1,2 and 1,6 so if you are using one of those you only need to change the text you want to encode in the qrenc function. Otherwise you have to run the dofbit sketch first, set the ecc and version you want to use, and then run it to produce the code which is placed in the qrframe.cpp file of qrencoder.

Pete
Sorry, I uploaded the wrong version of one of the files. If you have qrcode_1.zip, replace it with this:
qrcode_2.zip

Hi Pete,
today I tried you code. When I compile it to run on a nano I get this error message:

Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Nano, ATmega328"

Build options changed, rebuilding all

In file included from qrencode.h:8:0,

                 from qrencode.cpp:4:

qrencode.cpp:20:34: error: variable 'framebase' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

 extern unsigned char framebase[] PROGMEM;


qrencode.cpp:21:32: error: variable 'framask' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

 extern unsigned char framask[] PROGMEM;

I already tried to make it constant but then I get additional errors. When I store the variable at the SRAM I can compile but I get wrong results.
Do you have an idea to fix it?
thanks a lot and kind regards,
David

klabba:
I already tried to make it constant but then I get additional errors.

Any particular reason you are keeping the modified code to yourself?

Any particular reason you are keeping the new error messages to yourself?

Hi Coding Badly,
you are right. I will try to give more information.
To fix the error I described in my last post I defined the variables 'framebase' and 'framask' as constants.
qrencode.cpp:

extern const unsigned char framebase[] PROGMEM;
extern const unsigned char framask[] PROGMEM;

qrframe.cpp:

const unsigned char framebase[] PROGMEM = {
0xFE, 0x03, 0xF8, 0x82, 0x02, 0x08, 0xBA, 0x02, 
0xE8, 0xBA, 0x02, 0xE8, 0xBA, 0x02, 0xE8, 0x82, 
0x02, 0x08, 0xFE, 0xAB, 0xF8, 0x00, 0x00, 0x00, 
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 
0x80, 0x00, 0xFE, 0x00, 0x00, 0x82, 0x00, 0x00, 
0xBA, 0x00, 0x00, 0xBA, 0x00, 0x00, 0xBA, 0x00, 
0x00, 0x82, 0x00, 0x00, 0xFE, 0x00, 0x00, 
};

const unsigned char framask[] PROGMEM = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x10, 0x04, 
0x00, 0x80, 0x08, 0x1F, 0xF0, 0x7F, 0xC0, 0xFF, 
0x80, 0xFF, 0x80, 0x7F, 0xC0, 0x1F, 0xF0, 0x03, 
0xFE, 0x00, 0x3F, 0xE0, 0x00, 
};

With the changes I got this error messages:

qrencode.cpp.o: In function `ismasked':

C:\Users\David\AppData\Local\Temp\build3828410659722439733.tmp/qrencode.cpp:230: undefined reference to `framask'

C:\Users\David\AppData\Local\Temp\build3828410659722439733.tmp/qrencode.cpp:230: undefined reference to `framask'

qrencode.cpp.o: In function `fillframe':

C:\Users\David\AppData\Local\Temp\build3828410659722439733.tmp/qrencode.cpp:239: undefined reference to `framebase'

C:\Users\David\AppData\Local\Temp\build3828410659722439733.tmp/qrencode.cpp:239: undefined reference to `framebase'

If I just remove the 'PROGMEM' modifiers the code is compilable but it produces the following result which isn't a valid QR-code:

P1
21 21
1 0 0 0 0 0 0 0 1 1 0 0 0 1 0 1 1 0 0 0 0 
0 0 1 0 1 1 1 1 1 1 0 1 1 0 0 0 0 0 0 0 1 
1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 1 1 
0 1 1 0 1 0 1 1 1 0 0 0 1 1 1 0 0 1 0 0 0 
1 1 0 1 1 1 0 0 0 0 1 1 0 1 1 0 0 1 0 0 1 
0 1 0 1 1 0 1 1 1 1 1 0 1 0 0 1 1 1 0 0 0 
1 1 0 0 1 1 1 1 0 0 0 1 1 0 1 1 1 1 1 1 0 
1 1 1 0 0 0 0 0 1 1 0 0 1 1 0 1 1 0 0 1 1 
1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 1 1 1 1 1 1 
1 0 0 1 0 1 0 1 1 0 0 1 0 1 1 1 0 0 0 0 0 
1 1 0 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 0 1 
1 1 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 1 1 1 
1 0 0 1 1 1 0 0 0 0 1 1 0 1 0 1 0 1 0 0 0 
1 0 1 0 0 1 0 0 1 0 1 1 1 1 0 1 0 0 1 1 0 
0 1 0 0 0 1 0 0 1 0 1 1 1 1 1 1 0 1 0 0 1 
1 0 0 1 1 0 1 0 1 0 1 0 1 1 1 0 0 1 0 1 0 
1 0 1 0 0 1 1 0 1 1 0 1 0 1 0 1 1 1 0 0 0 
0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 0 1 0 0 1 1 
0 1 1 1 1 0 1 0 1 0 0 0 1 1 1 0 0 0 1 1 0 
1 0 1 1 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 0 
0 0 1 1 0 0 0 0 1 0 1 1 1 0 0 1 0 1 0 0 1

Wow. That was bizarre.

This in qrencode.cpp...

...
#else
extern unsigned char rlens[];
extern const unsigned char framebase[] PROGMEM;
extern const unsigned char framask[] PROGMEM;
#endif
...

...and this in qrframe.cpp...

...
extern const unsigned char framebase[] PROGMEM = {
0xFE, 0x03, 0xF8, 0x82, 0x02, 0x08, 0xBA, 0x02, 
0xE8, 0xBA, 0x02, 0xE8, 0xBA, 0x02, 0xE8, 0x82, 
0x02, 0x08, 0xFE, 0xAB, 0xF8, 0x00, 0x00, 0x00, 
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 
0x80, 0x00, 0xFE, 0x00, 0x00, 0x82, 0x00, 0x00, 
0xBA, 0x00, 0x00, 0xBA, 0x00, 0x00, 0xBA, 0x00, 
0x00, 0x82, 0x00, 0x00, 0xFE, 0x00, 0x00, 
};

extern const unsigned char framask[] PROGMEM = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF8, 0x10, 0x04, 
0x00, 0x80, 0x08, 0x1F, 0xF0, 0x7F, 0xC0, 0xFF, 
0x80, 0xFF, 0x80, 0x7F, 0xC0, 0x1F, 0xF0, 0x03, 
0xFE, 0x00, 0x3F, 0xE0, 0x00, 
};
...

...compiles. You will have to decide if it runs correctly.

I tried several variations except that one. It works! Weird. Thanks Coding Badly.

Maybe something to do with the 1.6.x IDE or the newer compiler?

Pete

Thank you guys,
It works wonderful now. You can find the code with this little modifications attached.
best regards
David

qrcode_2.1.zip (15.8 KB)

el_supremo:
I tried several variations except that one. It works! Weird.

I agree. That is weird.

Thanks Coding Badly.

You are welcome.

Maybe something to do with the 1.6.x IDE or the newer compiler?

Could be. Probably the first time I ever had to combine extern with a definition.

klabba:
Thank you guys,
It works wonderful now. You can find the code with this little modifications attached.
best regards
David

Great job on this, thank you.

Please let me know how I can send you money.

@klabba

Thank you for the updated file. It works great!

Correction: It has been pointed out that the comment in qrencode.ino about the correct output from the sketch is wrong.
The correct output for qrenc(1,1) and the string "test string" should be this:

P1
21 21
1 1 1 1 1 1 1 0 0 0 1 1 1 0 1 1 1 1 1 1 1 
1 0 0 0 0 0 1 0 1 1 1 0 1 0 1 0 0 0 0 0 1 
1 0 1 1 1 0 1 0 0 0 1 1 1 0 1 0 1 1 1 0 1 
1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1 
1 0 1 1 1 0 1 0 0 1 0 0 1 0 1 0 1 1 1 0 1 
1 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 0 1 
1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 
1 1 1 1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 0 1 0 
0 1 0 0 1 1 0 1 0 0 1 1 1 0 0 0 1 1 1 0 1 
1 0 1 1 1 1 1 1 0 0 1 0 1 0 1 0 0 1 1 1 0 
0 1 0 1 0 1 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 
0 0 1 1 1 1 1 1 0 1 1 0 1 0 1 0 0 1 0 1 0 
0 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 1 0 1 1 1 
1 1 1 1 1 1 1 0 1 1 1 1 0 1 0 0 0 1 0 1 0 
1 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0 1 1 1 1 1 
1 0 1 1 1 0 1 0 1 1 1 1 0 0 1 1 0 1 0 0 1 
1 0 1 1 1 0 1 0 1 0 1 0 1 1 1 0 1 1 1 0 0 
1 0 1 1 1 0 1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 
1 0 0 0 0 0 1 0 1 0 1 1 0 1 0 1 0 0 1 0 0 
1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 1 0

Sorry about that.

Pete

I am working on QR code encoder and display it on EPD panel with Arduino Uno.

I am using the code from GitHub - ricmoo/QRCode: QR code generation library in C, optimized for low-power devices, such as Arduino.

I found two important points.

  1. The text is more than 127 characters then this code doesn't encode the text
  2. Some of the special characters like ?, @ are not encoded.

I would request your help.

Thanks ... Suresh