as I’m working on my MP3 player project, I needed to do some adapts to the Adafruit_SSD1306 library (included in Rogers core, adapted by myself some years ago).
Warning: This library was only tested with a 128×64 I2C Oled without RST pin. For SPI you need to adapt my new I2C functions!
Here some changes:
full speed HW I2C again (was modified by someone, but forgotten to insert a Wire.setClock(400000) after Wire.begin
encapsulated the whole screen buffer from private to public. This “costs” only 1KB (on a 128×64 display) But now you can copy the buffer into a temporary array, do something on screen and after that putting the state before on screen again. So with other words: You don’t need to take care what was on screen before. Saves many lines of code
delete the pre built adafruit logos in the buffer: Saves flash memory (about 1KB)
Not only full screen update, but pages:
Ok, the screen is only 1024 bytes, but with I2C this can be a lot of time, so I read the datasheet of SSD1306 and recognized that the screen can also be updated by pages (8 lines), so you have 8 pages on a 128×64 display. Here is a practical example:
void oled_invert_entry(byte page) {
for (int z = 0; z < 128; z++) {
display.buffer[z + page* 128] = ~display.buffer[z + page * 128]; // invert page
}
display.display(page, page );
}
Super fast software scrolling of a single line with a long string (in opposite to the useless HW scrolling):
void scrollText(String text, byte txtsize, byte page )
{
display.setTextColor(0, 1);
display.setTextSize(txtsize);
display.setTextWrap(false);
int x = display.width();
int minX = -6 * txtsize * text.length(); // 6 = 6 pixels/character * text size
for (int y = 0; y < 6 * txtsize * text.length() + 6 * 20 * txtsize; y++) { //Full text length plus 20 additional character
if (encflag || buttonflag) {
return;
display.setTextColor(1, 0);
}
display.fillRect(0, page * 8 , 128, 8 * txtsize, 1);
display.setCursor(x, (0 + page * 8) );
display.print(text);
display.display(page, page + txtsize - 1 );
delay(10);
if (--x < minX) x = display.width();
}
}
A small typo
12864 display
took me some time to realize that there was an x missing. Monday morning, I took my espresso but it seems I need more!
[heisan – Mon Oct 08, 2018 8:41 am] –
Please note that the Adafruit license requires that the splash screen be retained.
What makes you think that?
https://github.com/adafruit/Adafruit_SS … icense.txt
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
license.txt IS included.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
see 1)
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
blah.
[zoomx – Mon Oct 08, 2018 8:04 am] –
Well done, I have to test your library one day, I hope in the next days. I like very much these little OLED.A small typo
12864 display
took me some time to realize that there was an x missing. Monday morning, I took my espresso but it seems I need more!
Corrected! Now IamX
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen below must be included in any redistribution
But it totally contradicts the main license text file here: https://github.com/adafruit/Adafruit_SS … icense.txt
I opened an issue on github, because this is nonsense bloating the flash memory with about 1KB with a stupid logo.
https://github.com/adafruit/Adafruit_SSD1306/issues/117
So guys: Please after downloading include the original logo file and comment it out….
[madias – Mon Oct 08, 2018 11:11 am] –
Ok, we don’t have to keep it, read here:
https://github.com/adafruit/Adafruit_SSD1306/issues/117
Yes – that was my request. Not 100% sure if that constitutes a one-off approval or general approval for change of license terms…
Personally, I really want to clean room all these drivers, with proper abstraction, and cleaner licenses – but I just don’t have the time.
As a side note, the bit-shifting pixel functions are quicker on the STM32 than the lookup tables, so if you revert those, you can get a bit more performance.
[heisan – Mon Oct 08, 2018 11:21 am] –
…
Yes – that was my request. Not 100% sure if that constitutes a one-off approval or general approval for change of license terms…Personally, I really want to clean room all these drivers, with proper abstraction, and cleaner licenses – but I just don’t have the time.
As a side note, the bit-shifting pixel functions are quicker on the STM32 than the lookup tables, so if you revert those, you can get a bit more performance.
Waste of time, IMO. This is why many (most) commercial endeavors shun (reject, avoid, punish employees upto termination) for using open source code. I remember my old company “insisting” that a free software author accept $50K and sign a right-to-use license. Legal had the same issue with Linux OS and it took years to work through the indemnity clauses… Nothing is really “free”.
In the case of hobby use (non-redistribution), just do what you want with the lib modifications. The issue is re-hosting for download and publication of more than a snippet. #ifdef/#ifndef logic added to re-hosted libs generally solve the concerns.
Ray
Heisan: Do you have some code examples on github, I didn’t find anything from you.
The major problem with the I2C OLED is….I2C, better called the wire library. As a “compatibility feature” the send buffer is only 32KB. So you cannot send the whole display buffer at once. But sad enough, you cannot use the “full” 32KB:
// I2C
for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) {
// send a bunch of data in one xmission
Wire.beginTransmission(_i2caddr);
WIRE_WRITE(0x40);
for (uint8_t x=0; x<16; x++) {
WIRE_WRITE(buffer[i]);
i++;
}
i--;
Wire.endTransmission();
}
[madias – Mon Oct 08, 2018 9:43 pm] –
…Which library do use for your Nokia5110? *sneer*
….
http://playground.arduino.cc/Code/PCD8544
Ray
[madias – Mon Oct 08, 2018 9:43 pm] –
Ray: There are much better SSD1306 libraries as the adafruit one,
If I need only ASCII characters I use this one
Text only Arduino Library for SSD1306 OLED displays
https://github.com/greiman/SSD1306Ascii
that has very small flash and RAM usage.
I also “encapsulate” libs as a copy in the project folder – so I can hack what may need some surgery to perform what I wish. For example, the Nokia lib function “clear” did not reset x, y. Editing clear to include x=0, y=0 saved a few source code lines. I also made some changes to the way Ladyada handled her 2-line GPS buffer.
I simply do not use libraries I do not understand… library use is a convenience but should never be a crutch.
Ray