(1)简介
随着数字化发展,二维码在生活中的使用率越来越高,本文就基于Arduino控制器生成二维码并在液晶屏幕上显示出来,扫描后会跳转到指定的网页,二维码的显示内容可任意修改。
本文使用0.96寸OLED液晶显示屏,如下图所示:

(2)接线
Arduino控制器使用的是UNO,0.96寸OLED液晶显示屏使用的是IIC接口,接线方式如下表所示:
| 0.96 OLED屏 | UNO |
|---|---|
| VCC | 5V |
| GND | GND |
| SCL | A5 |
| SDA | A4 |
(3)主程序(完整代码及函数头文件见文末链接)
qrcode_initText(&qrcode, qrcodeData, 3 , ECC_LOW, "https://www.baidu.com");// start drawu8g2.firstPage();do {// get the draw starting point,128 and 64 is screen sizeuint8_t x0 = (128 - qrcode.size * 2) / 2;uint8_t y0 = (64 - qrcode.size * 2) / 2;// get QR code pixels in a loopfor (uint8_t y = 0; y < qrcode.size; y++) {for (uint8_t x = 0; x < qrcode.size; x++) {// Check this point is black or whiteif (qrcode_getModule(&qrcode, x, y)) {u8g2.setColorIndex(1);} else {u8g2.setColorIndex(0);}// Double the QR code pixelsu8g2.drawPixel(x0 + x * 2, y0 + y * 2);u8g2.drawPixel(x0 + 1 + x * 2, y0 + y * 2);u8g2.drawPixel(x0 + x * 2, y0 + 1 + y * 2);u8g2.drawPixel(x0 + 1 + x * 2, y0 + 1 + y * 2);}}} while ( u8g2.nextPage() );
(4)结果展示

Arduino 二维码显示
完整代码链接:
CSDN下载
https://download.csdn.net/download/u011816009/85086775
百度网盘下载
https://pan.baidu.com/s/1ZBKVnUjwMuV9iGCcO1e33w
提取码:ypae