Posts Tagged ‘Arduino’
Adafruit sells a really nice 16×2 OLED display and they even have an Arduino library for it. However I only have a Atmega32 and Arduino does not run on the Atmega32. Rather than spending $20 or so for an Arduino, I decided to port their library to AVR. It wasn’t too difficult since Arduino is just AVR C++ behind the scenes.
Re-writing the Adafruit library was straightforward. I hardcoded PORTA as the I/O port but some additional code could make that generic. I had to re-write the digitalRead and digitalWrite functions to read and write out of PORTA instead of the Arduino pins. The delayMicroseconds command is replaced by the AVR _delay_ms() macro.
The trickiest part was figuring out how to implement the print function. After some digging around I found it in the Arduino code at \hardware\arduino\cores\arduino\Print.cpp. The print function calls a write function that iterates through the character string which then calls our native OLED write on each character. This seems seems a little roundabout but I guess that is how they chose to implement it.
My No-Arduino code:
Adafruit Arduino library: