QR Code library
Moderators: adafruit_support_bill, adafruit

QR Code library

by commy on Wed Oct 17, 2012 3:16 pm

Im looking for at QR Code library for generating QR codes on the Arduino to be displayed with the Adafruit_GFX library.

The only thing I have found is https://github.com/tz1/qrduino but can't get it working. It compiles fine but crashes/hangs when the encode method is called.

Anybody out there who can help turning this code into a Arduino library?

I would really appreciate that, thanks!
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 6:11 pm

Re: QR Code library

by adafruit_support_rick on Thu Oct 18, 2012 7:38 am

commy wrote:It compiles fine but crashes/hangs when the encode method is called.

That thing is pretty RAM-intensive. You've only got 2K on a 328. Add in Adafruit_GFZ and you're probably over the limit.
qrencode allocates a couple of big buffers on the stack when you call it, so you're probably crashing the stack.

The stack grows down from the top of RAM, static memory and then dynamic memory grow up from the bottom. When they meet in the middle - BOOM!

dofbits looks like it generates some kind of C file, which claims to lower RAM usage. Did you look into that?
Last edited by adafruit_support_rick on Thu Oct 18, 2012 8:45 am, edited 1 time in total.
Reason: typo on 'dofbits'
User avatar
adafruit_support_rick
 
Posts: 11689
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: QR Code library

by commy on Thu Oct 18, 2012 8:43 am

You are absolutely right, the dotbit tool was the missing piece. Thanks for pointing me at the right way.

I will now try to combine this code into a library using as real Class instead of all the seperate files.
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 6:11 pm

Re: QR Code library

by commy on Thu Oct 18, 2012 10:00 am

Hmm still seems to run into RAM problems, so i think i will make a separate slave device for encoding the QR code and talk to it using serial or i2c.
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 6:11 pm

Re: QR Code library

by adafruit_support_rick on Thu Oct 18, 2012 10:42 am

First, try moving all the literal strings to flash with the F() notation, e.g.:
Code: Select all | TOGGLE FULL SIZE
Serial.print(F("take me out of RAM and put me in flash"));
User avatar
adafruit_support_rick
 
Posts: 11689
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: QR Code library

by commy on Sat Oct 20, 2012 11:14 am

The optimized qrencoder only uses 640 bytes of SRAM.

So the problem now is the Adafruit_SSD1306 library with its heavy SRAM use of 1KB for the display buffer.

I will look for a optimized SSD1306 library without a display buffer to finish my project.
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 6:11 pm

Re: QR Code library

by adafruit_support_rick on Sun Oct 21, 2012 4:09 am

commy wrote:The optimized qrencoder only uses 640 bytes of SRAM.

Nice. I wasn't expecting that you could make it that small. Still, you might think about a Leonardo, which has an extra 512 bytes of SRAM. That could give you the elbow room you need to use the unmodified SSD1306 library.
User avatar
adafruit_support_rick
 
Posts: 11689
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: QR Code library

by commy on Sun Oct 21, 2012 4:14 am

Yes the code should be perfect to run on a Leonardo or other Atmega32u4 boards with the extra 512K SRAM.

But it could be nice to rewrite the SSD1306 library to not use a large display buffer and get the SRAM usage under 2KB.
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 6:11 pm

Re: QR Code library

by adafruit_support_rick on Sun Oct 21, 2012 4:30 am

commy wrote:But it could be nice to rewrite the SSD1306 library to not use a large display buffer and get the SRAM usage under 2KB.

That would be difficult. All the graphics routines in Adafruit_GFX boil down to calling drawPixel in Adafruit_SSD1306.cpp. drawPixel needs to know the state of the other 7 pixels in any particular byte of the bitmap in order to update the display coherently.
User avatar
adafruit_support_rick
 
Posts: 11689
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: QR Code library

by lazze on Sun Nov 18, 2012 11:02 am

Could someone explain how to you use qrduino as a arduino library. I'd like to use this library to generate QRcodes and display them on a led matrix. I managed to compile and now I have these files: dofbit, lcd, lcd.hex, lcd.o, qrencode.o, qrv6l1.c, qrv6l1.o but I don't know exactly what to do or how to create a library.
lazze
 
Posts: 3
Joined: Sun Nov 18, 2012 10:45 am

Re: QR Code library

by adafruit_support_rick on Sun Nov 18, 2012 3:07 pm

Arduino libraries are not pre-compiled. You provide them as source code; there is no need for you to compile them before-hand.

Have a look at our libraries tutorial here: http://www.ladyada.net/library/arduino/libraries.html
User avatar
adafruit_support_rick
 
Posts: 11689
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: QR Code library

by lazze on Mon Nov 19, 2012 2:26 pm

driverblock wrote:Arduino libraries are not pre-compiled. You provide them as source code; there is no need for you to compile them before-hand.

Have a look at our libraries tutorial here: http://www.ladyada.net/library/arduino/libraries.html


Thanks, but at the moment I lack the skill to create .ccp and .h files on my own.

If commy managed to create a library for arduino I'd be clad to use that. :D
lazze
 
Posts: 3
Joined: Sun Nov 18, 2012 10:45 am

Re: QR Code library

by commy on Mon Nov 19, 2012 5:08 pm

I did not rewrite the code to a Arduino library because of the way qrduino is build.

But it is quite easy to use when you got an idea of how it works. The code comes with both a project and an some tools, one for generating the frame.h file to optimise the SRAM usage.

First build the tool using the Makefile and then run the ./dofbit with the version and level needed (be carefull of memory use when using higher version and ecc levels).

Next copy the files frame.h, qrencode.h and qrencode.cpp to your Arduino sketch.

Include the frame.h and qrencode.h and copy the string you want to encode to the "strinbuf" object and call qrencode();

strcpy((char *)strinbuf, "http://adafruit.com");
qrencode();

And you can now run through QRBIT(x,y) to get the pixel (use WD to find max width and height of x and y).

Hope this helps!
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 6:11 pm

Re: QR Code library

by adafruit_support_rick on Tue Nov 20, 2012 1:27 pm

Thanks, commy! That's good to know :D
User avatar
adafruit_support_rick
 
Posts: 11689
Joined: Tue Mar 15, 2011 10:42 am
Location: Buffalo, NY

Re: QR Code library

by lazze on Tue Nov 20, 2012 4:33 pm

commy wrote:I did not rewrite the code to a Arduino library because of the way qrduino is build.

But it is quite easy to use when you got an idea of how it works. The code comes with both a project and an some tools, one for generating the frame.h file to optimise the SRAM usage.

First build the tool using the Makefile and then run the ./dofbit with the version and level needed (be carefull of memory use when using higher version and ecc levels).

Next copy the files frame.h, qrencode.h and qrencode.cpp to your Arduino sketch.

Include the frame.h and qrencode.h and copy the string you want to encode to the "strinbuf" object and call qrencode();

strcpy((char *)strinbuf, "http://adafruit.com");
qrencode();

And you can now run through QRBIT(x,y) to get the pixel (use WD to find max width and height of x and y).

Hope this helps!


Best answer ever! Thank you very much. 8)
lazze
 
Posts: 3
Joined: Sun Nov 18, 2012 10:45 am