SSD1306 OLED lines


#1

Hello all!
Old and solved topic on Arduino/Teensy boards but brand new for me on imp.
I have connected SSD1306 to imp001, use @smittytone library https://gist.github.com/smittytone/20ed962d9f06072bd1c0 and I2C.
Works perfect. Now I’m interested to reduce line count from 4 to 1 or 2 and increase font size. Several attempts to achieve that (memory block size etc.) was without success: still 4 lines on 128x32 or 128x64 OLED.
So - where I must take a look in code to change line number on screen?
Many thanks in advance!


#2

Blimey, that’s going back a bit…

I would try editing the function set_text_cursor() so that it doesn’t return on a row value greater than 3 — if you have a 128 x 64, ie. eight rows of X x 8 pixel characters, you need to set the row limit to 7.

You might also want to look at adding an alternative character set if the text is too small.

PS. There’s a more up-to-date, graphics-oriented version of the code here: https://gist.github.com/smittytone/8e2defdb72751cba55e07c149127da69

It doesn’t use a text cursor: you just plot your text at whatever pixel on the display you’d like it to start from. But note that this is a work in progress, so you may find bugs


#3

@smittytone many thanks!
I have tried that - no change.
Other point I have recognised - there are no difference between OLED size:
oled <- SSD1306_OLED(hardware.i2c12, 0x78, hardware.pin5, 128, 32) or
oled <- SSD1306_OLED(hardware.i2c12, 0x78, hardware.pin5, 128, 64)
for the same display (I have tried on both display sizes).
As I have said - I must show bigger size just on 2 lines.
I will try your new library and come back with results.


#4

Hello! I have tried new code (https://gist.github.com/smittytone/8e2defdb72751cba55e07c149127da69) without any success - display don’t start…
As I see - some updates are made in constructor:
" constructor(impI2Cbus = null, address = 0x3C, impRSTpin = null, displayWidth = 128, displayHeight = 32) {
// ParametersC
// 1. The chosen CONFIGURED imp I2C bus object
// 2. The OLED’s 7-bit I2C address as an integer
// 3. The chosen UNCONFIGURED imp pin object to control the Reset line
// 4. OLED pixel width
// 5. OLED pixel height
if (impI2Cbus == null || address == 0) throw “SSD1306Pro instantiation error: invalid bus or address”;
_i2c = impI2Cbus;
_i2cAddress = address << 1; "

compared to pervious version:
"constructor(imp_i2c_bus, address, imp_rst_pin, pixel_width=128, pixel_height=32)
{
// Parameters:
// 1. The chosen imp I2C bus object
// 2. The OLED’s 7-bit I2C address as an integer
// 3. The chosen imp pin object to control the Reset line
// 4. OLED pixel width
// 5. OLED pixel height
_i2c = imp_i2c_bus
_i2c_address = address
_i2c.configure(CLOCK_SPEED_400_KHZ) "

In new version I2C configuration take place at the end:
hardware.i2c12.configure(CLOCK_SPEED_400_KHZ);

The same I2C - hardware pins 12 are applied in both versions, but in some way I2C don’t work as expected here.


#5

I think in the old version it’s assumed you convert the I2C address from 7-bit form (0x3C) to 8-bit form (0x78) manually, but the new version converts for you. And I took out the I2C configure line as some folks like to provide a pre-configured bus object because they need to set the speed for other devices.

You will need to add that to your own code, eg.

local i2c = hardware.i2c12;
i2c.configure(CLOCK_SPEED_400_KHZ);
local oled = SSD1306Pro(i2c, 0x3C, null, 128, 32);

#6

Ok - I see.
The problem was with the text, because it is possible to draw 2 lines, also inverse display, but cannot display text. Probably wrongly written comand…:

local i2c = hardware.i2c12;
i2c.configure(CLOCK_SPEED_100_KHZ);
oled <- SSD1306Pro(i2c, 0x3C, null, 128, 32);
oled.init();
oled.inverseDisplay(0);

function loop() {
oled.setCursor(5,5);
oled.text(“Testing”);
oled.line(0, 0, 128, 32, 1, 1)
oled.line(0,32, 128, 0, 1, 1)
server.log(“loop”);
imp.wakeup(5.0, loop);
}
loop()


#7

I’ll have a look at the code


#8

As far as I get - I can write a text on screen only after lines and circles with additional oled.draw();
function loop() {
oled.circle(64, 16, 10, 1, 0);
oled.line(0, 0, 128, 32, 1, 1);
oled.line(0,32, 128, 0, 1, 1);
oled.rect(10, 10, 5, 10, 1);
oled.draw();
oled.setCursor(0,0);
oled.text(“TESTING”);
server.log(“loop”);
imp.wakeup(5.0, loop);
}
loop()

But must uncomment all “ds” in function text(), compared to github source:

} else {
break;
}
}
ds = ds + c.tochar();
}
ds = ds + “\x00”;
}
//draw();
//if (onlyReturnWidth == false) draw();
_i2c.write(_i2cAddress, ds);
return width;

Result - I see lines,circle, rectangle text but all picture move to left (about 1/4 screen width) and also down some pixels on each imp.wakeup().

And still the same size font and 4 lines- how to double font and set only 2 lines?