Generate QRCode with Raspberry Pi Pico (arduino framework), display on 1.54" 200x200 B&W e-Paper (SSD1681)

Last post show how to display on 1.54" 200x200 e-Paper (SSD1681) with Raspberry Pi Pico using GxEPD2 library, in Arduino framework. It's another exercise to generate QRCode with Raspberry Pi Pico, and display on 1.54" 200x200 B&W e-Paper (SSD1681)



GxEPD2 and QRCode libraries are needed, install them in Arduino IDE's Library Manager.


Code

Pico_GxEPD2_SSD1681_qrcode.ino
/*
 *Exercise run on Raspberry Pi Pico/RP2040
 *display QRCode on 1.54" 200x200 e-Paper with SSD1681 SPI driver,
 *using ZinggJM/GxEPD2 and qrcode lib
 *
 *qrcode:
 *https://github.com/ricmoo/qrcode/
 */

#include <GxEPD2_BW.h>
#include <qrcode.h>

#define EPD_CS     17
#define EPD_DC     21
#define SRAM_CS    -1
#define EPD_RESET  20
#define EPD_BUSY   22

GxEPD2_BW<GxEPD2_154_GDEY0154D67, GxEPD2_154_GDEY0154D67::HEIGHT> display(
  GxEPD2_154_GDEY0154D67(EPD_CS, EPD_DC, EPD_RESET, EPD_BUSY));

const int DISP_WIDTH = display.width();
const int DISP_HEIGHT = display.height();
const int DISP_HALF_W = (int)DISP_WIDTH/2;
const int DISP_HALF_H = (int)DISP_HEIGHT/2;

void setup()
{
  delay(500);
  Serial.begin(115200);

  display.init();
  display.setRotation(0);
  
  drawScreen();
  drawQRCode_FullWindows();

  delay(1000);
  display.powerOff();
  
}

void drawQRCode_FullWindows()
{
  // Create the QR code
  QRCode qrcode;
  const char *data = "https://www.youtube.com/@coXXect";
  //const char *data = "http://coxxect.blogspot.com/";
  const uint8_t ecc = 0;  //lowest level of error correction
  const uint8_t version = 2;
  uint8_t qrcodeData[qrcode_getBufferSize(version)];
  qrcode_initText(&qrcode,
                  qrcodeData,
                  version,
                  ecc,
                  data);

  Serial.println(data);
  Serial.print("qrcode.version: ");
  Serial.println(qrcode.version);
  Serial.print("qrcode.ecc: ");
  Serial.println(qrcode.ecc);
  Serial.print("qrcode.size: ");
  Serial.println(qrcode.size);
  Serial.print("qrcode.mode: ");
  Serial.println(qrcode.mode);
  Serial.print("qrcode.mask: ");
  Serial.println(qrcode.mask);
  Serial.println();
  
  display.setFullWindow();

  const int xy_scale = 8;
  const int x_offset = (display.width() - xy_scale*qrcode.size)/2;
  const int y_offset = (display.height() - xy_scale*qrcode.size)/2;

  display.firstPage();
  do
  {
    for (uint8_t y = 0; y < qrcode.size; y++) {
      for (uint8_t x = 0; x < qrcode.size; x++) {
        bool mod = qrcode_getModule(&qrcode, x, y);
        if(mod){
          int px = x_offset + (x * xy_scale);
          int py = y_offset + (y * xy_scale);
          display.fillRect(px, py, xy_scale, xy_scale, GxEPD_BLACK);
        }
      }
    }
  }
  while (display.nextPage());
  
}


void drawScreen()
{
  display.setFullWindow();

  display.firstPage();
  do
  {
    display.fillScreen(GxEPD_BLACK);
  }
  while (display.nextPage());
  delay(2000);

  display.setPartialWindow(0, 0, DISP_WIDTH, DISP_HEIGHT);
  display.firstPage();
  do
  {
    display.fillScreen(GxEPD_WHITE);
    display.drawRect(0, 0, DISP_WIDTH, DISP_HEIGHT, GxEPD_BLACK);
  }
  while (display.nextPage());
  delay(2000);

}

void loop() {
  };



Comments

Popular posts from this blog

MicroPython/ESP32-C3 + 1.8" 128x160 TFT ST7735 SPI, using boochow/MicroPython-ST7735 library.

CameraWebServe: ESP32-S3 (arduino-esp32) + OV5640 camera module