All, continuing on with my cockpit sim build, I am trying to use some small OLED displays in order to show some digits on a panel. The intention is that each OLED displays one digit, and I have been able to get the sketch together that outputs the digit to a nano using the DCS BIOS protocol.
The problem I have is that the display of the digit is not what I want, and if fact I am rather puzzled by what is happening. What I want is to use a 64 x 32 0.49" OLED, and so I have produced the following sketch for the first digit
#define DCSBIOS_DEFAULT_SERIAL
#include "DcsBios.h"
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "charactersbak.h"
#define SCREEN_WIDTH 64 // OLED display width, in pixels
#define SCREEN_HEIGHT 32// OLED display height, in pixels
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define TISL
int updateInterval = 100; //the number of milliseconds between updates
struct scrollDigit {
int digit; //The digit that is displayed
int y; // The vertical position of the digit
};
struct disp {
Adafruit_SSD1306 display;
int width;
int numberOfDigits;
scrollDigit digits[1];
};
#ifdef TISL
disp oled = {Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET), 24, 1, {{0,0}}};
#endif
void setup() {
if(!oled.display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for(;;); // Don't proceed, loop forever
}
DcsBios::setup();
}
void UpdateDisplay()
{
oled.display.clearDisplay();
for (int i = 0; i < oled.numberOfDigits; i++)
{
printScrollingDigit(oled.digits[i].digit, oled.width, oled.digits[i].y, i + 1, &oled);
}
if (oled.width == 16)
{
oled.display.fillRect(0, 25, 67, 7, BLACK);
}
oled.display.display();
}
int YPos()
{
return (oled.width + 9) * -1;
}
void printScrollingDigit(int digit, int width, int y, int pos, disp *oled)
{
int x = (width * pos) - width + pos;
#ifdef TISL
switch (digit)
{
case -1: oled->display.drawBitmap(x, y, c24_Empty, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_1, 24, 32, 1); break;
case 1: oled->display.drawBitmap(x, y, c24_1, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_2, 24, 32, 1); break;
case 2: oled->display.drawBitmap(x, y, c24_2, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_3, 24, 32, 1); break;
case 3: oled->display.drawBitmap(x, y, c24_3, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_4, 24, 32, 1); break;
case 4: oled->display.drawBitmap(x, y, c24_4, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_5, 24, 32, 1); break;
case 5: oled->display.drawBitmap(x, y, c24_5, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_6, 24, 32, 1); break;
case 6: oled->display.drawBitmap(x, y, c24_6, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_7, 24, 32, 1); break;
case 7: oled->display.drawBitmap(x, y, c24_7, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_8, 24, 32, 1); break;
case 8: oled->display.drawBitmap(x, y, c24_8, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_9, 24, 32, 1); break;
case 9: oled->display.drawBitmap(x, y, c24_9, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_0, 24, 32, 1); break;
default: oled->display.drawBitmap(x, y, c24_0, 24, 32, 1); oled->display.drawBitmap(x, y+33, c24_1, 24, 32, 1); break;
}
#endif
}
#ifdef TISL
void onTislCode1Change(unsigned int newValue)
{
unsigned int mappedValue = newValue / 2;
unsigned int y = map(newValue, mappedValue * 2, mappedValue * 2 + 3, 0, YPos());
oled.digits[1].digit = newValue / 2;
oled.digits[1].y = y;
}
DcsBios::IntegerBuffer tislCode1Buffer(0x1116, 0x1f00, 8, onTislCode1Change);
#endif
unsigned long time = 0;
void loop() {
DcsBios::loop();
time = millis();
if (time % updateInterval == 0)
{
UpdateDisplay();
}
}
The sketch is derived from a successful sketch used to show scrolling altimeter information on a 128 X 32 0.96" OLED.
So the problem is that when used on a 64 x 32 OLED display, the digit doesn't appear, and the right half of the screen is full of speckles. Modifying the sketch to display two digits, only the bottom half of the numeral is displayed, and every other line is not appearing plus the right hand half of the screen is full of speckles. Take a look at the first and second pictures (64x32_ and 64x32_2)
In this case it appears to be acting like a 32 X 16 display. As I understand it the speckles are where there is no screen info defined.
So when I connect the same single digit sketch to a 128 x 64 OLED you get the whole digit displayed, again with every other line missing, and the right half of the display full of speckles.
Out of curiosity, I connected it to a couple of 128 x 32 displays I have, and was surprised to see the display show the digit perfectly, with a correct clear area up to half the screen width, and the right side of the screen showing speckles. Well, with the first one at least. With the other three 128 x 32 modules, it showed the digit with every other line shown horizontally, but with speckles over the entire screen.
So is there an explanation for the 64 x 32 displays acting like modules with half the resolution? And why to seemingly the same modules differ in the output?
Cheers
Les