Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QR to bitmap to print via Thermal Printer #20

Open
janna574 opened this issue Apr 20, 2020 · 3 comments
Open

QR to bitmap to print via Thermal Printer #20

janna574 opened this issue Apr 20, 2020 · 3 comments

Comments

@janna574
Copy link

how can i get a bitmap from qrcode to print via ThermalPrinter !

printer.printBitmap(50,50,qrcode data,false);

@1000283
Copy link

1000283 commented Jan 5, 2022

You need to use the GS ( k family of commands, if the printer supports it.
Or convert the QR code to a bitmap and try GS v 0 or ESC *.

@aaron-neal
Copy link

Hope this helps....
Example below generates a WiFi QR code.
It is a version 3 code, then printed at 5 times the size.

if (tpScan("", 1)) {
        Serial.println((char *)"Found a printer!, connecting...");
        if (tpConnect()){
            uint8_t qrVersion = 3;
            static uint8_t ucBuf[48 * 160]; //tp printer buffer 48 * ver lines
            tpSetBackBuffer(ucBuf, 384, 160);
            
            tpFill(0);
            char buf[50];
            sprintf(buf, "WIFI:S:%s;T:WPA;P:%s;;", config.networkConfig.apSSID, config.networkConfig.apPassword);
            Serial.println(buf);
            uint8_t qrcodeData[qrcode_getBufferSize(qrVersion)];
            qrcode_initText(&qrcode, qrcodeData, qrVersion, 0, buf); //ver 3 = 29*29 //ver 40 177*177

            uint8_t startX = 117;
            uint8_t startY = 10;

            for (uint8_t y = 0; y < qrcode.size; y++) {
                for (uint8_t x = 0; x < qrcode.size; x++) {
                    if (qrcode_getModule(&qrcode, x, y) == 1){    
                        //below, print QR 5 times as big                
                        tpSetPixel(startX + 5 * x,     startY + 5 * y, 1);
                        tpSetPixel(startX + 5 * x + 1, startY + 5 * y, 1);
                        tpSetPixel(startX + 5 * x + 2, startY + 5 * y, 1);
                        tpSetPixel(startX + 5 * x + 2, startY + 5 * y, 1);
                        tpSetPixel(startX + 5 * x + 2, startY + 5 * y, 1);
                            
                        tpSetPixel(startX + 5 * x,     startY + 5 * y + 1, 1);
                        tpSetPixel(startX + 5 * x + 1, startY + 5 * y + 1, 1);
                        tpSetPixel(startX + 5 * x + 2, startY + 5 * y + 1, 1);
                        tpSetPixel(startX + 5 * x + 3, startY + 5 * y + 1, 1);
                        tpSetPixel(startX + 5 * x + 4, startY + 5 * y + 1, 1);

                        tpSetPixel(startX + 5 * x,     startY + 5 * y + 2, 1);
                        tpSetPixel(startX + 5 * x + 1, startY + 5 * y + 2, 1);
                        tpSetPixel(startX + 5 * x + 2, startY + 5 * y + 2, 1);   
                        tpSetPixel(startX + 5 * x + 3, startY + 5 * y + 2, 1);   
                        tpSetPixel(startX + 5 * x + 4, startY + 5 * y + 2, 1);   

                        tpSetPixel(startX + 5 * x,     startY + 5 * y + 3, 1);
                        tpSetPixel(startX + 5 * x + 1, startY + 5 * y + 3, 1);
                        tpSetPixel(startX + 5 * x + 2, startY + 5 * y + 3, 1);   
                        tpSetPixel(startX + 5 * x + 3, startY + 5 * y + 3, 1);   
                        tpSetPixel(startX + 5 * x + 4, startY + 5 * y + 3, 1);  

                        tpSetPixel(startX + 5 * x,     startY + 5 * y + 4, 1);
                        tpSetPixel(startX + 5 * x + 1, startY + 5 * y + 4, 1);
                        tpSetPixel(startX + 5 * x + 2, startY + 5 * y + 4, 1);   
                        tpSetPixel(startX + 5 * x + 3, startY + 5 * y + 4, 1);   
                        tpSetPixel(startX + 5 * x + 4, startY + 5 * y + 4, 1);  
                    }
                }
            }
            tpPrintBuffer();
            tpDisconnect();
        }
    } else {
        Serial.println((char *)"Didn't find a printer :( ");
    }

@lailuboy
Copy link

I implemented saving a QR code as a BMP file using C language

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants