Updated SSD1306xLED library, fixes, compatibility with SSD1315 and more

SSD1306xLED Testing

Our SSD1306xLED library works well with the SSD1306 displays, it is small as binary code and is very fast.

But, there was a problem …

Several months ago we ordered some displays from the Far East and we expected them to work just fine. Unfortunately, they did not. And the problem was not in our library but with the chips. Instead of SSD1306, it seems they put the not that well known SSD1315 OLED display controller. We found that out by looking closely at the PCB, beneath the LCD glass plate.

ssd1306xled testing
SSD1315 OLED display controller

The testing script was producing the result shown in the picture. Note the bottom lines – they were not redrawn, or not always, at least.

On another display that we’ve got earlier, a few years ago, and that was using the SSD1306 controller the picture was looking good.

SSD1306xLED Testing
SSD1306 OLED display controller

Apparently, the problem was with the display controller. Further experiments proved that.

What made it worse for us was that we’ve discovered that from about a hundred display modules we’ve ordered recently half seemed not compatible with our code. We couldn’t even figure out what exactly was the OLED controller on those modules –
SSD1306 as stated in the description where we bought them, or the SSD1315 looking at the testing scripts results. So, we decided to just fix the problem for both kinds of chips. Easy to say it than to do it.

First attempt

2 months ago. We played with the timing and the speed of the data sent to the modules. Tried a few other things, like reordering the commands sent while drawing. We even moved some of the I2C specific code to a separate library to isolate the potential problems and try to fix the issue. No luck.

Second attempt

2 days ago. We decided to re-do the initialization sequence for the OLED controller. These are the commands that we send to the chip before we start drawing things on the display. We read, again, the Solomon Systech PDF file about the SSD1306 controller – the so-called datasheet. There was a half-baked algorithm of how to initialize the chip. Also, looked at several other libraries to see how they do it. Actually, the “Adafruit_SSD1306.cpp” was a really good example so we used some know-how from it.

Wrote the code. Tested it. And, it worked!

Done!

SSD1306xLED Testing
SSD1306xLED Testing

Some optimizations

There were a couple of TO-DO’s in the source code for the optimization of multiplication by a constant. That could be easily converted to a combination of 1 or more left-bitwise-shift and additions.

void ssd1306tx_char(char ch) {
  uint8_t c = ch - 32; // Convert ASCII code to font data index.
  ssd1306_start_data();
  for (uint8_t i = 0; i < 6; i++) {
    ssd1306_data_byte(pgm_read_byte(&amp;ssd1306tx_font_src[c * 6 + i]));
  }
  ssd1306_stop();
}

We combined the c = ch – 32 and the c * 6 + i and optimized the entire expression.

void ssd1306tx_char(char ch) {
  uint16_t j = (ch << 2) + (ch << 1) - 192;
  ssd1306_start_data();
  for (uint8_t i = 0; i < 6; i++) {
    ssd1306_data_byte(pgm_read_byte(&amp;ssd1306tx_font_src[j + i]));
  }
  ssd1306_stop();
}

That saved us about 30 bytes of binary code and it is probably a bit faster than the multiplication with a subroutine.

We did something similar for the void ssd1306tx_stringxy(const uint8_t *fron_src, uint8_t x, uint8_t y, const char s[]); function but without the left-bitwise-shift as the compiler optimizes the very well the multiplication with numbers that are powers of 2, i.e. 2, 4, 8, etc. In our case – 16. That saved us another 20 bytes of binary code and probably gained some speed.

So, we saved about 50 bytes of machine code and gained some speed. That might not look that much but for a microcontroller with 4096 bytes for code and 1 or 8 MHz CPU that’s about 1.2% less memory usage. And, our library is now a bit faster.

Resources

There are more functions in the SSD1306xLED library such as for printing text and numbers on the screen and drawing images but that will be subject of another article.

The official page of the library (will be):
https://tinusaur.org/software/libraries/ssd1306xled/

Source code is available at:
https://bitbucket.org/tinusaur/ssd1306xled/src

Launched crowdfunding campaign for the Tinusaur OLED Display Kit

Tinusaur OLED Display Кit

We have just launched our crowdfunding campaign at Crowd Supply for the Tinusaur OLED Display Kit – a bundle of boards and modules that allows you to connect an ATtiny85 microcontroller to an SSD1306 OLED display. This is a kit so you have to assemble the boards yourself by soldering the parts to the PCB thus start learning about electronics and physics. It might sound complicated at first but these Tinusaur boards are very easy to assemble using the guides and tutorials that we provide. Once all the boards are assembled you could connect a DHT11 sensor module, measure temperature and humidity and show the results on the screen.

Tinusaur OLED Display Кit
Tinusaur OLED Display Кit

With the Tinusaur OLED Display Kit, you get everything you need to start: the Tinusaur main board with the ATtiny85 microcontroller, the LED shield for test and learning, the OLED display shield, the SSD1306 OLED display, the DHT11 sensor module, a LiPo battery kit, and, a USBasp programmer.

The Tinusaur is an Open Source project – both the software and the hardware. Our own library for with the display, called SSD1306xLED, is considered one of the fastest for that display and microcontroller.

Check out the campaign page for details!