二維碼現(xiàn)在隨處可見,這次就教大家如何使用零知ESP8266開發(fā)板在SSD1306 OLED顯示屏上繪制QR碼。 1、硬件準(zhǔn)備 (1)零知ESP8266開發(fā)板 (2)SSD1306 OLED模塊 (3)杜邦線若干 2、軟件準(zhǔn)備 本次使用了OLED相關(guān)的軟件庫,因此需要安裝相關(guān)的軟件庫:
安裝好庫,在零知開發(fā)工具中就可以看到QRCode二維碼相關(guān)例子,打開它: 核心代碼如下,非常簡單: - /* *********************************************************************************
- * ESP8266 QRcode
- * dependency library :
- * ESP8266 Oled Driver for SSD1306 display by Daniel Eichborn, Fabrice Weinberg
- * 零知ESP8266-OLED
- * SDA --> D1-sda
- * SCL --> D0-scl
- ***********************************************************************************/
-
- #include <qrcode.h>
-
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
-
- #define SCREEN_WIDTH 128 // OLED display width, in pixels
- #define SCREEN_HEIGHT 64 // OLED display height, in pixels
-
- // Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
- #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
-
- QRcode qrcode (&display);
-
- void setup() {
-
- Serial.begin(115200);
- Serial.println("");
- Serial.println("Starting...");
-
- display.begin(SSD1306_SWITCHCAPVCC, 0x3c);
-
- display.clearDisplay();
-
-
- // enable debug qrcode
- qrcode.debug();
-
- // Initialize QRcode display using library
- qrcode.init();
- // create qrcode
- qrcode.create("www點(diǎn)lingzhilab點(diǎn)com");
-
- }
-
- void loop() { }
復(fù)制代碼 3、電路連接接線很簡單,I2C接口對應(yīng)連接即可: 接好后實(shí)物圖如下: 現(xiàn)在驗(yàn)證代碼然后上傳到零知-esp8266,可以看到如下結(jié)果啦: 用手機(jī)QQ掃一掃看看: 更多詳細(xì)資料可到零知實(shí)驗(yàn)室官網(wǎng)免費(fèi)獲取。
|