QR Code library

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 7:11 pm

QR Code library

Post by commy »

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!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: QR Code library

Post by adafruit_support_rick »

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 9:45 am, edited 1 time in total.
Reason: typo on 'dofbits'

User avatar
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 7:11 pm

Re: QR Code library

Post by commy »

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.

User avatar
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 7:11 pm

Re: QR Code library

Post by commy »

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.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: QR Code library

Post by adafruit_support_rick »

First, try moving all the literal strings to flash with the F() notation, e.g.:

Code: Select all

Serial.print(F("take me out of RAM and put me in flash"));

User avatar
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 7:11 pm

Re: QR Code library

Post by commy »

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.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: QR Code library

Post by adafruit_support_rick »

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
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 7:11 pm

Re: QR Code library

Post by commy »

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.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: QR Code library

Post by adafruit_support_rick »

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.

lazze
 
Posts: 3
Joined: Sun Nov 18, 2012 11:45 am

Re: QR Code library

Post by lazze »

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.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: QR Code library

Post by adafruit_support_rick »

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

lazze
 
Posts: 3
Joined: Sun Nov 18, 2012 11:45 am

Re: QR Code library

Post by lazze »

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

User avatar
commy
 
Posts: 14
Joined: Fri Jan 25, 2008 7:11 pm

Re: QR Code library

Post by commy »

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!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: QR Code library

Post by adafruit_support_rick »

Thanks, commy! That's good to know :D

lazze
 
Posts: 3
Joined: Sun Nov 18, 2012 11:45 am

Re: QR Code library

Post by lazze »

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)

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”