This project includes a easy to use OLED library for an SSD1306/SH1106 that can be used with an ATmega- or ATmega0-Series controller. The library itself can be found in the lib directory and demo applications for avr are pushed to demo and for avr0 to demo-avr0 directory. A short description of how to use the library for avr platforms can be found below.
| Link | Description |
|---|---|
| Extended Documentation | Detailed documentation of howto using the library |
| Doxygen Code Documentation | Detailed documentation of defines and functions |
| Graphics Design Panel | Panel to design graphics for the frame library |
| Name | Type | Controller | CLOCK | SCL | SDA | Description |
|---|---|---|---|---|---|---|
| tty_sw_twi_m16a.hex | tty | ATmega16A | 12MHz | PB0 | PB1 | TTY with software TWI |
| tty_hw_twi_m16a.hex | tty | ATmega16A | 12MHz | PC0 | PC1 | TTY with hardware TWI |
| frame_sw_twi_m16a.hex | frame | ATmega16A | 12MHz | PB0 | PB1 | FRAME with software TWI |
| frame_hw_twi_m16a.hex | frame | ATmega16A | 12MHz | PC0 | PC1 | FRAME with hardware TWI |
| Name | Type | Controller | CLOCK | SCL | SDA | Description |
|---|---|---|---|---|---|---|
| tty_sw_twi_m4808.hex | tty | ATmega4808 | 20MHz | PD2 | PD3 | TTY with software TWI |
| tty_hw_twi_m4808.hex | tty | ATmega4808 | 20MHz | PC3 | PC2 | TTY with hardware TWI |
| frame_sw_twi_m4808.hex | frame | ATmega4808 | 20MHz | PD2 | PD3 | FRAME with software TWI |
| frame_hw_twi_m4808.hex | frame | ATmega4808 | 20MHz | PC3 | PC2 | FRAME with hardware TWI |
The library to control the display supports two modes.
tty- Text Modeframe- Graphical Mode
The oled library currently supports the avr and avr0 plattform. The platform can be defined within the oled.h library. By default avr is selected.
// For AVR platform
#define OLED_HAL_PLATFORM avr
// For AVR0 platform
#define OLED_HAL_PLATFORM avr0
Microchip Studiocompiles all libraries in the folders by default. Therefore, eitheravroravr0should be created in the folder structure and the library that is not used should be removed. To select the correct platform and set the clock speed correctly in the libraries, it is best to create aglobal defineunderProject-Settings -> AVR/GNU C-Compiler -> SymbolsinMicrochip studio.
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !! IMPORTANT NOTICE !!
// !! Setup following symbols: !!
// !! Project-Settings -> AVR/GNU C-Compiler -> Symbols !!
// !! !!
// !! F_CPU=20000000UL !!
// !! OLED_HAL_PLATFORM=avr0 !!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!The oled library supports two communication modes. It is possible to use the hardware or the software-twi mode. These settings can be adapted in the oled.h.
To use hardware-twi the following macro has to be undefined in oled.h.
// #define OLED_USE_SOFT_TWIThe standard
pinsdescribed in the controller datasheet are used for TWI communication.
To use software-twi the following macro has to be defined in oled.h.
#define OLED_USE_SOFT_TWIIn addition, the “pins” on which the communication takes place can be adjusted in oled.h.
The tty-mode allows to write a text to the display line-by-line.
#define F_CPU 12000000UL
#include <avr/io.h>
#include <util/delay.h>
#include "../../lib/oled/tty/tty.h"
int main(void)
{
tty_init();
unsigned char temp = 0;
while (1)
{
printf("Text %u\n", (temp++));
_delay_ms(10);
}
}Autoscroll in tty mode can be enabled via the autoscroll macro (this is usually the case) in tty.h.
#define TTY_AUTOSCROLLThe frame-mode allows you to use a background graphic for text or a status bar.
The background graphic itself consumes a huge amount of program memory (
1KiB). The background can be disabled on smaller controllers to prevent the system from loading it when the display initializes to save space.
The background graphic is enabled by default with the FRAME_SPECIFIC_BACKGROUND macro in frame.c and can be deactivated by commenting it out.
#define FRAME_SPECIFIC_BACKGROUNDTo simplify the graphic design process, the project has a built-in tool called the OLED Graphics Design Panel. Within this tool it is possible to create any specific background for the display.
After designing the background the created array has to be placed in the
frame_backgroundvariable at frame.c.
A background is already designed and filed in frame.c for testing purposes.
#define F_CPU 12000000UL
#include <avr/io.h>
#include <util/delay.h>
#include "../../lib/oled/frame/frame.h"
int main(void)
{
frame_init();
DRAWING_Position position = { 106, 1 };
DRAWING_Size size = { 10, 10 };
frame_draw_text("Init", position);
unsigned char temp = 0;
while (1)
{
position.x = 1;
position.y = 56;
size.width = 126;
size.height = 6;
frame_draw_bar(position, size, temp++);
if(temp >= 100UL)
{
temp = 0;
}
position.x = 2;
position.y = 46;
frame_draw_number_uint(temp, 4, NUMBER_Decimal, position);
_delay_ms(50);
}
}R. GAECHTER