I bought one of these OLED from ebay for ~$5. I used this page as a guide for the wiring and code:
https://github.com/jandelgado/arduino/wiki/SSD1306-based-OLED-connected-to-Arduino
The Arduino communicates using the SPI
I have the wiring as follows
OLED - Arduino pin - AVR pin (PORTB) - Function
D0 - Pin 13 - B5 - MISO
D1 - Pin 11 - B3 - CLOCK
RST - Pin 8 - B0 - RESET
DC - Pin 9 - B1 - Data/Command
CS - Pin 10 - B2 - Chip select
First I set-up the AVR peripherals (using http://brittonkerin.com/cduino/lessons.html as a guide for uart). UART is used for debugging:
setup_uart: ldi r16, low(bittimer) sts UBRR0L, r16 ldi r16, high(bittimer) sts UBRR0H, r16 ldi r16, (3<<UCSZ00) sts UCSR0C, r16 ldi r16, (1<<RXEN0)|(1<<TXEN0) sts UCSR0B, r16 ret
To send a byte over uart I store it in r16 and invoke the tx_uart subroutine
tx_uart:
lds r17, UCSR0A
sbrs r17, UDRE0
rjmp tx_uart
sts UDR0, r16
ret
Setting up the SPI:setup_spi:
ldi r16, (1<<5)|(1<<3)|(1<<rst)|(1<<cs)|(1<<dc)
out DDRB, r16
ldi r16, (1<<SPE)|(1<<MSTR)
out SPCR,r16
ldi r16, (1<<SPI2X)
out SPSR, r16
ret
To send a byte over spi I store it in r20 and invoke spi_send subroutinespi_send:
out spdr, r20
wait_sprs:
in r16, SPSR
sbrs r16, SPIF
rjmp wait_sprs
ret
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.