HELP: Printing QR codes on Adafruit Thermal Printer

hello,
i am using qrcode library

for generating QR code at runtime

but i can not print it using Adafruit Thermal Printer

which uses method printer.printBitmap(x,y,qrdata)

now my problem is how to convert the qrcode generated from qrcode library to
static const uint8_t PROGMEM adaqrcode_data = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, .....

How big is the char array ? (uint_8t)
You need to remember the total memory limits in the CPU

its just an array of {double,double,double,double,double} 5 items only

Thanks. that will help a lot for the users...

any help ... please !

Unfortunately you need someone with the same hardware & library to collaborate on this, because the environment seems quite specific.
If you don’t get anywhere, ask the mods to move it Gigs & Collaborations, you may get someone to invest the time if there’s a reward involved.

lastchancename:
Unfortunately you need someone with the same hardware & library to collaborate on this, because the environment seems quite specific.
If you don’t get anywhere, ask the mods to move it Gigs & Collaborations, you may get someone to invest the time if there’s a reward involved.

thanks for fast reply,

anyway how can i ask moderators to move my question to Gigs & Collaborations?

Use the link, just below this text.

any help please?

Maybe change the thread topic to something more specific… like

HELP: Printing QR codes on Adafruit Thermal Printer

lastchancename:
Maybe change the thread topic to something more specific... like

HELP: Printing QR codes on Adafruit Thermal Printer

i did

It does sound like a project that needs someone who has the particular Adafruit printer.

Adafruit maybe ?

yes i am using Adafruit printer, but the main problem is how to convert output from qrcode to bitmap data

here is my code

QRCode qrcode;
int buffsize = qrcode_getBufferSize(3);
uint8_t *qrcodeBytes= malloc(buffsize);
qrcode_initText(&qrcode, qrcodeBytes, 10, ECC_LOW, “Test”);

// here i need to convert the out put of qrcode to qrcode_data
printer.printBitmap(50,50,qrcode_data,false);

You are allocating your buffsize based on VERSION 3 QR codes (29x29) but then you are calling qrcode_initText() with VERSION 10 (57x57).

If you look at the documentation for printBitmap, it needs to be a multiple of 8 so your 50x50 will really be 48x50. You can’t just send the QR raw data, you need to iterate over it calling the Module() function which returns true/false if that bit is ON or OFF. Just like the example shows

Something like this

// The structure to manage the QR code
QRCode qrcode;

// default is VERSION 3: 29x29
// Allocate a chunk of memory to store the QR code
uint8_t qrcodeBytes[qrcode_getBufferSize()];

qrcode_initText(&qrcode, qrcodeBytes, 3, ECC_LOW, "HELLO WORLD");

// thermal printer needs multiples of 8 so make it 32 x 32
// which is 32/8 * 32 = 128 bytes
const int printerBuffer = 32/8 * 32;
uint8_t printerData[printerBuffer];

memset(printerData, 0, printerBuffer);

for (uint8_t y = 0; y < qrcode.size; y++) {
  for (uint8_t x = 0; x < qrcode.size; x++) {
    if (qrcode_getModule(&qrcode, x, y) {
    // bit is on so set it in printerData
    uint8_t pos = y * 4 + x / 8;  // byte position
    uint8_t idx = 7 - x % 8;      // bit position,
    printerData[pos] |= (1 << idx);
    }
  }
}

printer.printBitmap(32,32,printerData,false);

Thx, for your effort

i tried your code, but the result not a bitmap as shown in image attached

1.png

OP's image

1.png

yes, it is just a strange characters printed !

janna574:
Thx, for your effort

i tried your code, but the result not a bitmap as shown in image attached

Some debugging on your part will be necessary. You have the hardware. Maybe the translation from QR to bitmap bit location is wrong? What happens when you use the QR example and simply print the QR code to the Serial Monitor? Does that at least look correct?

blh64:
Some debugging on your part will be necessary. You have the hardware. Maybe the translation from QR to bitmap bit location is wrong? What happens when you use the QR example and simply print the QR code to the Serial Monitor? Does that at least look correct?

yes, works fine in serial mode ... i am using Arduino Mega

Then try printing out the the bitmap image after it has been created. Dump it to the Serial Monitor as well using HEX or BIN notation and see if the ON bits are in the right spot as well.