-1

Can someone please help me rewrite this code to make the QRcode to use the whole display size (200x200)?

I'm using this display:
https://www.waveshare.com/1.54inch-e-paper-module.htm

Here is the libary which I use to create the QRCode:
https://github.com/ricmoo/qrcode/

Here is a picture of the current state:
click for picture

This is my code:

#include <SPI.h>
#include "epd1in54_V2.h"
#include "qrcode.h"
#include "epdpaint.h"

//set the pins of the ESP32
Epd epd(33, 25, 26, 27);        // my Pins ESP32 (Reset, DC, CS, Busy)
unsigned char image[1024];
Paint paint(image, 0, 0);
QRCode qrcode;

#define BLACK     0
#define WHITE   1

void setup()
{
  uint8_t qrcodeData[qrcode_getBufferSize(3)];
    qrcode_initText(&qrcode, qrcodeData, 3, 0, "https://vinotes.app");

    epd.LDirInit();
    epd.Clear();

    paint.SetWidth(45);
    paint.SetHeight(45);
    paint.Clear(WHITE);
    for (int y = 0; y < qrcode.size; y++) {
        for (int x = 0; x < qrcode.size; x++) {
            if (qrcode_getModule(&qrcode, x, y)) {
                paint.DrawPixel(x, y, BLACK);
            }
        }
    }

    epd.SetFrameMemory(paint.GetImage(), 0, 0, paint.GetWidth(), paint.GetHeight());
    epd.DisplayFrame();
    epd.Sleep();
}

void loop()
{

}
luegm.dev
  • 81
  • 8

1 Answers1

1

Instead of iterating over the size of your QR code, iterate over the size of your display, and request QR modules using coordinates divided by the scaling factor.

There is a very good example in the TouchGFX documentation. (I know you're not using that, but the same principle applies.)

e.g. if you want to scale up your QR code by a factor of 4 (psuedo-ish code):

#define SCALE_FACTOR 4

for (int y = 0; y < HEIGHT; ++y)
{
    for (int x = 0, x < WIDTH; ++x)
    {
        setPixel(x, y, getModule(x / SCALE_FACTOR, y / SCALE_FACTOR));
    }
}

You'll want to figure out the maximum scaling factor that will fit, and maybe add some offsets to center the image.

Edit: To be clear, don't actually iterate over the literal width and height of your display, otherwise you won't get a square QR code. The upper bounds of both loops would be (qrcode.size * SCALING_FACTOR).

pmacfarlane
  • 3,057
  • 1
  • 7
  • 24