180 likes | 195 Views
Explore how to integrate an ATtiny85 microcontroller with an SSD1306 OLED display using the TYWu Library, understand the connection, font size, and how to address common issues. Step-by-step guide for a successful integration.
E N D
Library • ssd1306xled
OLED2864 • Resolution 128 64
SSD1306.ssd1306_char_f8x16 • SSD1306.ssd1306_char_f8x16(x, y, string) • Font Size: 8x16 (Home Version is modified by TY Wu for the size 16x16) • x: 0~128 • y:0 (0*8), 1 (1*8), 2 (2*8) SSD1306.ssd1306_char_f8x16(0, 5, “Q”) 5*8=40 Q
Connection • 2. Connect VDD to 3.3V • 3. Connect GND • 4. (OLED) RES <-> PB1, Give a pulse 1->0->1 (ATTINY85) (pin 6) • 5. (OLED) CS <-> GND • 6. (OLED) SDA <-> PB0 (ATTINY85) (pin 5) • 7. (OLED) SCL <-> PB2 (ATTINY85) (pin 7) • 8. D/C: Floating Small OLED
Replace ld.exe • This patch replaces the ld.exe file (or just ld for Mac) in WinAVR/Crosspack supplied with the Arduino IDE. The supplied version has a bug which causes weird errors when files larger than 4kB are compiled for AVR25 processors which include those in the Tiny series.
Replace ld.exe • Download and replace ld.exe • URL • https://github.com/TCWORLD/ATTinyCore/tree/master/PCREL%20Patch%20for%20GCC • Relace • ?\arduino-1.0.4\hardware\tools\avr\avr\bin\ld.exe
Example #include <font8x16.h> #include <ssd1306xled.h> #include <ssd1306xled8x16.h>
Example void setup() { pinMode(PB4, OUTPUT); //BEEP pinMode(3, INPUT); //Button digitalWrite(3, HIGH); //Pull-up OLED_reset(); SSD1306.ssd1306_init(); clear_OLED();
Example SSD1306.ssd1306_char_f8x16(0, 5, "By TY Wu"); for(int j=0;j<64;j++) { SSD1306.ssd1306_char_f8x16(j, 0, "NCUE"); for(int k=128;k>j*2;k--) { digitalWrite (PB4,HIGH); delayMicroseconds (j+1); digitalWrite (PB4,LOW); delayMicroseconds (j+1); } }
Example delay(500); for(int j=64;j>0;j--) { SSD1306.ssd1306_char_f8x16(j, 0, "NCUE"); for(int k=128;k>j*2;k--) { digitalWrite (PB4,HIGH); delayMicroseconds (j+1); digitalWrite (PB4,LOW); delayMicroseconds (j+1); } } delay(1000); }
Example void OLED_reset() { delay(300); pinMode(1, OUTPUT); //Connect to RES (RESET) digitalWrite(1, HIGH); delay(300); digitalWrite(1, LOW); delay(1000); digitalWrite(1, HIGH); }
Example int s=0; int m=0; int h=0; void loop() { char time_str[12]; s=(s+1)%60; if(s==0) { m=(m+1)%60; if(m==0) h=(h+1)%24; } sprintf(time_str, "%02d:%02d:%02d", h, m, s); SSD1306.ssd1306_char_f8x16(0, 0, time_str); //x, y }
Other OLED Compatible pins SDA SCK VDD VSS
Reference • http://webboggles.com/attiny85-breakout-keychain-game/