Skip to content

Instantly share code, notes, and snippets.

@nerdralph
Created January 7, 2020 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nerdralph/4affd5987701c35cead1e4c802301e2d to your computer and use it in GitHub Desktop.
Save nerdralph/4affd5987701c35cead1e4c802301e2d to your computer and use it in GitHub Desktop.
picoI2C ssd1306 128x32 test
/* ssd1306 test for picoI2C
* Ralph Doncaster (c) 2019
* free software - MIT license
*/
#include <stdint.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "picoI2C.h"
// PORT pin numbers for SDA & SCL (0-7)
const uint8_t PicoI2C::SCL = 4;
const uint8_t PicoI2C::SDA = 3;
const uint8_t ssd1306_init [] PROGMEM = {
0xC8, // COM output scan direction
0xA1, // segment re-map A1=column 127 mapped to SEG0.
0xA8, 0x1F, // multiplex ratio
0xDA, 0x02, // com pins config
0x8D, 0x14, // enable DC charge pump
//0xA7, // invert display
0xAF // display ON
};
__attribute__ ((OS_main))\
void main()
{
// scan bus
uint8_t addr = 0x3C;
if (PicoI2C::startWrite(addr) == 0) {
// turn on LED to show ACK received
PORTB |= (1<<0); // pullup PB0
PicoI2C::write(0x00); // command sequence
uint8_t init_len = sizeof(ssd1306_init);
uint8_t pos = 0;
while (pos < init_len) {
uint8_t data = pgm_read_byte(&ssd1306_init[pos++]);
PicoI2C::write(data);
}
PicoI2C::stop();
PicoI2C::startWrite(addr);
PicoI2C::write(0x40); // data sequence
uint8_t count = 0;
while (++count) {
PicoI2C::write(count);
_delay_ms(25);
}
}
PicoI2C::stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment