Hello,
I went through most of the SSD1306 flickering questions but they all talk about how often the screen content is updated and also some suggestions around white background.
I believe my problem is slightly different.
I am using Adafruit library and must mention that it is an STM32 based custom board, but not sure why that would matter.
My requirement is to display a QR code on the screen that can be read using a mobile phone. When I use Adafruit OLED library and the standard QR code library that is available in the editor, the code gets printed fine. I initially noticed a bit of pixel bleeding and reducing the brightness helped.
Once the code is printed, the screen is no longer updated. It merely sits in the while loop, doing nothing.
In this case I expect a static picture with no flickers. However when I point the mobile phone camera to the screen I see a black line moving downwards (i.e. the screen for some reason keeps refreshing). This makes reading the QR code quite a hit-and-miss. It does work after several tries, but not suitable for practical purposes.
Is it normal for this OLED screen to get refreshed even when the content is not being updated ? If so is there a way to adjust that refresh rate ? Either slower or faster would help.
Or any other suggestions to get a clearer image ?
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <qrcode.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 4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
QRCode qrcode;
const char* MESSAGE_CONFIGURE_WIFI[4] = { "Scan QR", "to goto", "Map", "" };
const char* MESSAGE_OPEN_WEBAPP[4] = { "Scan QR", "to open", "Lumifera", "webapp " };
void setup() {
Serial.begin(9600);
pinMode(PA7, OUTPUT);
digitalWrite(PA7, HIGH);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for(;;); // Don't proceed, loop forever
}
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.clearDisplay();
display.display();
display.dim(true);
// Wifi QR code options: https://en.wikipedia.org/wiki/QR_code#Joining_a_Wi%E2%80%91Fi_network
// const char* qrStr = "WIFI:S:Lumifera Setup;T:nopass;P:;;";
// const char *lines[4] = { "Scan to", "Join", "Lumifera", "WiFi" };
drawQrCode("https://maps.apple.com/?ll=51.620690,-0.145539", MESSAGE_CONFIGURE_WIFI);
delay(50000);
}
void loop() {
digitalWrite(PA7, HIGH);
delay(1000);
}
void drawQrCode(const char* qrStr, const char* lines[]) {
uint8_t qrcodeData[qrcode_getBufferSize(3)];
qrcode_initText(&qrcode, qrcodeData, 3, ECC_LOW, qrStr);
// Text starting point
int cursor_start_y = 10;
int cursor_start_x = 4;
int font_height = 12;
// QR Code Starting Point
int offset_x = 62;
int offset_y = 3;
for (int y = 0; y < qrcode.size; y++) {
for (int x = 0; x < qrcode.size; x++) {
int newX = offset_x + (x * 2);
int newY = offset_y + (y * 2);
if (qrcode_getModule(&qrcode, x, y)) {
display.fillRect( newX, newY, 2, 2, 0);
}
else {
display.fillRect( newX, newY, 2, 2, 1);
}
}
}
display.setTextColor(1,0);
for (int i = 0; i < 4; i++) {
display.setCursor(cursor_start_x,cursor_start_y+font_height*i);
display.println(lines[i]);
}
display.display();
}