Go Down

Topic: Encoding and generating QR Codes (Read 5994 times) previous topic - next topic

cristianorbs

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: https://github.com/extrame/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!


cristianorbs

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.

el_supremo

#3
Feb 27, 2015, 10:54 pm Last Edit: Feb 28, 2015, 01:42 am by el_supremo
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
Don't send me technical questions via Private Message.

klabba

Hi Pete,
today I tried you code. When I compile it to run on a nano I get this error message:
Code: [Select]
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

Coding Badly

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?


klabba

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:
Code: [Select]
extern const unsigned char framebase[] PROGMEM;
extern const unsigned char framask[] PROGMEM;

qrframe.cpp:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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

Coding Badly


Wow.  That was bizarre.

This in qrencode.cpp...
Code: [Select]

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


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

Code: [Select]

...
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.


el_supremo

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
Don't send me technical questions via Private Message.

klabba

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

Coding Badly

I tried several variations except that one. It works! Weird.
I agree.  That is weird.

Quote
Thanks Coding Badly.
You are welcome.

Quote
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.


Derrick-

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.

avenue33

@klabba

Thank you for the updated file. It works great!

el_supremo

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:
Code: [Select]
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
Don't send me technical questions via Private Message.

Go Up