Skip to content
Aleksei edited this page Oct 14, 2018 · 13 revisions

FAQ

There is garbage on the display

There can be several root causes for the garbage observed:

  • Check max i2c or spi interface freqyency, supported by your display
  • Check if correct ssd1306 library mode is used with specific API functions

Frequency can be changed inside of ssd1306 library. You need to find the code, which works for your platform. In general ssd1306 library sets the frequency, supported by your display. But there are a lot of hardware solutions from reach amount of lcd display manufactures. We assume that frequency tuning may be necessary in ssd1306 library code.

As for ssd1306 library mode, ssd1306 library has 2 sets of functions: with 8 suffix (like ssd1306_printFixed8()) and without 8 suffix (like ssd1306_printFixed()).
Functions without the suffix work ONLY in ssd1306 compatible mode, that is: GDRAM addressing mechanism is the same as for ssd1306 controller. Such addressing has some limitations.
Functions with the suffix 8 work ONLY in native mode for selected display. By default, for any supported display the ssd1306 library works in ssd1306 compatible mode. And it is possible to switch between modes using ssd1306_setMode().

How to reduce code size

The main rule here is "the less different functions you use from ssd1306 library, the less flash space it requires".

For atmega328p ssd1331 display initialization code needs 392 bytes, but you also need to initialize SPI interface to communicate with display module. Arduino SPI library for atmega328p eats another 892 bytes. Adding single ssd1306_clearScreen() to your program need another 88 bytes of flash (calling ssd1306_clearScreen() twice from the sketch needs 88 bytes for first call + 4 bytes for second call). Thus, the idea is clear: it is ok to call specific function several times from source code, but number of different used functions should be reduced.

There is very helpful script for AVR controllers in ssd1306/tools directory: avrparse.bat for Windows and avrparse.sh for Linux, it provides detailed information on functions and data variables space consumption.

Not to use Arduino IDE for compilation, or use workaround in ssd1306 library

Arduino IDE is specific IDE, limiting compiling capabilities too heavy. Ssd1306 library supports many interfaces, and compile all supported interfaces for your chosen platform. It is deal of the linker to remove not used code. But some Arduino IDE core libraries do not allow linker to throw out unused code due to their implementation (Serial.h, Wire.h, etc.). So, if you do not use Wire interface to reduce binary size, you need to tell SSD1306 library to not compile Wire support at all. This can be done in two ways:

  1. Not to use Arduino IDE (arduino builder), and pass SSD1306_DISABLE_WIRE_SUPPORT (for example) definition when compiling library
  2. Use workaround way and edit ssd1306_hal/UserSettings.h file and comment CONFIG_ARDUINO_WIRE_LIBRARY_ENABLE and/or CONFIG_ARDUINO_SPI_LIBRARY_ENABLE.

How to debug application

When working with micro controllers debugging application takes much time. It is big deal to get logs from the program running on micro controller. There are several ways to solve the problem:

  1. use hardware jtag debugger (not always available by hand)
  2. use serial port communication to get run-time logs (log places of interest to Serial port, and collect logs on PC).
  3. use SDL emulation mode, embedded to ssd1306 library, and run your code on PC.

The third-way greatly speeds up code development, since you use all standard PC debugging tools, but requires some accuracy from developer when working with hardware. All ssd1306 examples can be run on PC (both in Linux and Windows OS), you can use them as start point for your project.

How to add new font

Refer to How to create new font instructions.

How to use my own i2c/spi instead of built-in ones

If you already have some i2c or spi interface implementation and do not need the one, built-in ssd1306 library, you can easily make the library to work with your implementation. Refer to wiki instructions.

How to run demos on raspberry pi

You need to through several simple steps prior to running demo code on raspberry:

I2C

  1. Enable i2c in raspi-config (please, refer to official instructions)
  2. reboot your raspberry
  3. run sudo modprobe i2c-dev to make i2c-1 interface available in /dev/.

SPI

  1. Enable SPI in raspi-config (please, refer to official instructions)
  2. reboot your raspberry

Now compile the demo, you want, and run it like in this example:

cd ssd1306/tools
./build_and_run.sh -p linux demos/ssd1306_demo
sudo ../bld/demos/ssd1306_demo.out

Note: sudo is required only for SPI-based demo, because demo needs to export gpio to control RST, D/C pins.

How to port library to new platform

Actually porting library to new platform greatly depends on platform-specific toolchain and SDK. But there are some mandatory steps, which should be done:

  1. Follow the steps described in ssd1306_hal template
  2. Prepare Makefile for your platform.

For example, the library doesn't need Makefile for ESP32, because ESP32 IDF uses component system (You can find component.mk in ssd1306 root folder). Please, refer to ssd1306_hal/esp as good example of porting ssd1306 library.