In this illustration we will going to wire the ATTINY85 to control the OLED Screen using i2C Bus on ATTINY85 Microcontroller, I will just give an introduction what is ATTNY85 Microcontroller. The ATTINY 25,45, and 85 is a low power CMOS 8 bit microcontroller base on AVR enhance RSICK architecture by executing powerful instruction in a single clock cycle the ATTINYXX achieves throughputs approaching 1 MIPS per MHz allowing you to optimize the power consumption v/s processing speed. See below block diagram or you can just download the datasheet located below.
The AVR core combines a rich instructions set with 32 general purpose working registers all 32 register are directly connected to the Arithmetic Logic Unit or ALU, allowing the two independent registers to be accessed in one single instruction executed in one clock cycle. The resulting architecture is more code efficient while achieving throughputs up to ten times faster than conventional CISC microcontrollers.
The ATTINYXX provides you of 2, 4, 8 byres of In-System Programmable Flash, 128, 256, 512 bytes EEPROM, 128/256/256 bytes of SRAM, 6 IO lines, 32 working registers, 1 8bit timer/counter with compare modes, 1 8bit high speed timer/counter, USB, internal and external interrupts, 4 channel, 10-bit ADC, programmable watchdog timer with internal Oscillator, and 3 software selectable power saving modes. IDLE mode stops the CPU while allowing the SRAM, timer/counter, tents, disabling all chip functions until the next interrupt system to continue functioning. Power-down mode save the register contents, disabling all chip function until the next interrupt or hardware rest, ADC noise reduction mode stop the CPU and all I/O modules except ADC to minimize switching noise during ADC conversions.
The ATTINYXX is manufactured using ATMEL high density non-volatile memory technology. The One-Chip SPI flash allows you to program the memory to be re-programmed in system through an SPI serial interface, by a conventional non-volatile memory programmer or by on-chip boot code running on the AVR core. The ATTINY supported mostly commonly used program development tools including C, Micro Assembler, Program Debugger/Simulator and Evaluation Kits.
Digispark ATTINY Arduino IDE Integration with Windows Operating System
Copy this URL for additional board > http://digistump.com/package_digistump_index.json
DigiSpark ATTINY85 Pin Out Diagram
Wiring Diagram OLED 096″ Screen i2C / SPI /
Wiring with DHTXX Weather Station with ATTINY85
Sketch Code for Driving OLED Screen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include "font6x8.h" //Code library can be downloaded below #include "font8x16.h" // Code library can be downloaded below //#include <num2str.h> #include "ssd1306xled.h" //Code library can be downloaded below #include "ssd1306xled8x16.h" //Code library can be downloaded below #include <stdlib.h> //Code library can be downloaded below float h=0; float t=0; char buffH[6]; char buffT[6]; void setup() { DelayMs(40); SSD1306.ssd1306_init(); } void texto(char* s) {SSD1306.ssd1306_string_font6x8(s);} void textoG(int pos_x, int pos_y, char* sG) {SSD1306.ssd1306_char_f8x16(pos_x, pos_y, sG);} void pos(uint8_t x, uint8_t y){SSD1306.ssd1306_setpos(x, y);} void DisMan(){uint8_t p = 0xff; for (uint8_t i = 0; i < 4; i++){p = (p >> i); SSD1306.ssd1306_fillscreen(~p); DelayMs(100);}SSD1306.ssd1306_fillscreen(0x00);} void loop() { h=23; t=23; dtostrf(h, 4, 2, buffH); dtostrf(t, 4, 2, buffT); DisMan(); pos(0, 3); texto("Humidity(%)"); pos(0, 5); texto("Temperature(C)"); pos(0, 7); texto(" www.14core.com"); textoG(0,0,"Weather Station"); textoG(87,2,buffH); textoG(87,4,buffT); DelayMs(3000); } |
Sketch Code Driving DHT11 and OLED
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
#include // I2C Master lib for ATTinys which use USI - comment this out to use with standard arduinos #include // needed to up clock to 16 MHz on 5v Trinket dht DHT; const byte DHT11_Pin = 1; const int analogInPin = 3; #include "SSD1306_minimal.h" #include #define DEG "\xa7" "C" SSD1306_Mini oled; char strHum[5]; char strTemp[5]; char strSensorValue[5]; // Struct for sending measured data /* struct Data { uint16_t temp; // Temperature value uint16_t hum; // Humidity value int status; // DHT11 module status } data; */ void setup(){ if (F_CPU == 16000000) clock_prescale_set(clock_div_1); // 5V Trinket: run at 16 MHz TinyWireM.begin(); // initialize I2C lib - comment this out to use with standard arduinos oled.init(0x3c); oled.clear(); } void loop(){ /* sensorValue = analogRead(analogInPin); data.status = DHT.read22(DHT11_Pin); data.hum = (int)DHT.temperature; data.temp = (int)DHT.humidity; */ int chk = DHT.read22(DHT11_Pin); int h=DHT.humidity; int t=DHT.temperature; int sensorValue = analogRead(analogInPin); oled.startScreen(); oled.cursorTo(0,0); oled.printString( "Humidity: "); oled.startScreen(); oled.cursorTo(86,0); oled.printString( itoa(h, strHum, 10)); oled.startScreen(); oled.cursorTo(0,18); oled.printString("Temperature: "); oled.startScreen(); oled.cursorTo(100,18); oled.printString( itoa(t, strTemp, 10)); oled.startScreen(); oled.cursorTo(0,36); oled.printString("Light: "); oled.startScreen(); oled.cursorTo(51,36); oled.printString( itoa(sensorValue, strSensorValue, 10)); delay(500); } |
Downloads
Download ATTINY 25/45/85 Data Sheet | Pdf
Download Code Library ATTINY 85 | Zip
Download ATTINY85 Arduino Boot Loader| Zip
Download DigiUSB DigiSpark Board Windows Driver | Zip
Tack så mycket. koden testades.
Arduino: 1.8.2 (Windows 10), Board: “Digispark (Default – 16.5mhz)”
C:\Users\Summit\Downloads\ATTINY85-OLED\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void setup()’:
ATTiny85_OLED_weather_demo:16: error: ‘DelayMs’ was not declared in this scope
DelayMs(40);
^
ATTiny85_OLED_weather_demo:17: error: ‘SSD1306’ was not declared in this scope
SSD1306.ssd1306_init();
^
C:\Users\Summit\Downloads\ATTINY85-OLED\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void texto(char*)’:
ATTiny85_OLED_weather_demo:20: error: ‘SSD1306’ was not declared in this scope
void texto(char* s) {SSD1306.ssd1306_string_font6x8(s);}
^
C:\Users\Summit\Downloads\ATTINY85-OLED\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void textoG(int, int, char*)’:
ATTiny85_OLED_weather_demo:21: error: ‘SSD1306’ was not declared in this scope
void textoG(int pos_x, int pos_y, char* sG) {SSD1306.ssd1306_char_f8x16(pos_x, pos_y, sG);}
^
C:\Users\Summit\Downloads\ATTINY85-OLED\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void pos(uint8_t, uint8_t)’:
ATTiny85_OLED_weather_demo:22: error: ‘SSD1306’ was not declared in this scope
void pos(uint8_t x, uint8_t y){SSD1306.ssd1306_setpos(x, y);}
^
C:\Users\Summit\Downloads\ATTINY85-OLED\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void DisMan()’:
ATTiny85_OLED_weather_demo:23: error: ‘SSD1306’ was not declared in this scope
void DisMan(){uint8_t p = 0xff; for (uint8_t i = 0; i > i); SSD1306.ssd1306_fillscreen(~p); DelayMs(100);}SSD1306.ssd1306_fillscreen(0x00);}
^
ATTiny85_OLED_weather_demo:23: error: ‘DelayMs’ was not declared in this scope
void DisMan(){uint8_t p = 0xff; for (uint8_t i = 0; i > i); SSD1306.ssd1306_fillscreen(~p); DelayMs(100);}SSD1306.ssd1306_fillscreen(0x00);}
^
ATTiny85_OLED_weather_demo:23: error: ‘SSD1306’ was not declared in this scope
void DisMan(){uint8_t p = 0xff; for (uint8_t i = 0; i > i); SSD1306.ssd1306_fillscreen(~p); DelayMs(100);}SSD1306.ssd1306_fillscreen(0x00);}
^
C:\Users\Summit\Downloads\ATTINY85-OLED\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void loop()’:
ATTiny85_OLED_weather_demo:42: error: ‘DelayMs’ was not declared in this scope
DelayMs(3000);
^
exit status 1
‘DelayMs’ was not declared in this scope
This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.
PLEASE HEEEELP!
I have the same problem: ‘DelayMs’ was not declared in this scope
Arduino:1.8.2 (Windows 7), Tarjeta:”Digispark (Default – 16.5mhz)”
C:\Users\Alvaro!\Documents\Arduino\ATTINY85-OLED (1)\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void setup()’:
ATTiny85_OLED_weather_demo:15: error: ‘DelayMs’ was not declared in this scope
DelayMs(40);
^
ATTiny85_OLED_weather_demo:16: error: ‘SSD1306’ was not declared in this scope
SSD1306.ssd1306_init();
^
C:\Users\Alvaro!\Documents\Arduino\ATTINY85-OLED (1)\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void texto(char*)’:
ATTiny85_OLED_weather_demo:19: error: ‘SSD1306’ was not declared in this scope
void texto(char* s) {SSD1306.ssd1306_string_font6x8(s);}
^
C:\Users\Alvaro!\Documents\Arduino\ATTINY85-OLED (1)\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void textoG(int, int, char*)’:
ATTiny85_OLED_weather_demo:20: error: ‘SSD1306’ was not declared in this scope
void textoG(int pos_x, int pos_y, char* sG) {SSD1306.ssd1306_char_f8x16(pos_x, pos_y, sG);}
^
C:\Users\Alvaro!\Documents\Arduino\ATTINY85-OLED (1)\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void pos(uint8_t, uint8_t)’:
ATTiny85_OLED_weather_demo:21: error: ‘SSD1306’ was not declared in this scope
void pos(uint8_t x, uint8_t y){SSD1306.ssd1306_setpos(x, y);}
^
C:\Users\Alvaro!\Documents\Arduino\ATTINY85-OLED (1)\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void DisMan()’:
ATTiny85_OLED_weather_demo:22: error: ‘SSD1306’ was not declared in this scope
void DisMan(){uint8_t p = 0xff; for (uint8_t i = 0; i > i); SSD1306.ssd1306_fillscreen(~p); DelayMs(100);}SSD1306.ssd1306_fillscreen(0x00);}
^
ATTiny85_OLED_weather_demo:22: error: ‘DelayMs’ was not declared in this scope
void DisMan(){uint8_t p = 0xff; for (uint8_t i = 0; i > i); SSD1306.ssd1306_fillscreen(~p); DelayMs(100);}SSD1306.ssd1306_fillscreen(0x00);}
^
ATTiny85_OLED_weather_demo:22: error: ‘SSD1306’ was not declared in this scope
void DisMan(){uint8_t p = 0xff; for (uint8_t i = 0; i > i); SSD1306.ssd1306_fillscreen(~p); DelayMs(100);}SSD1306.ssd1306_fillscreen(0x00);}
^
C:\Users\Alvaro!\Documents\Arduino\ATTINY85-OLED (1)\ATTiny85_OLED_weather_demo\ATTiny85_OLED_weather_demo.ino: In function ‘void loop()’:
ATTiny85_OLED_weather_demo:41: error: ‘DelayMs’ was not declared in this scope
DelayMs(3000);
^
Se encontraron múltiples librerías para “font6x8.h”
Usado: C:\Users\Alvaro!\Documents\Arduino\libraries\ATTINY85-OLED
No usado: C:\Users\Alvaro!\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.6.7\libraries\DigisparkOLED
No usado: C:\Users\Alvaro!\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.6.7\libraries\DigisparkOLED
No usado: C:\Users\Alvaro!\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.6.7\libraries\DigisparkOLED
No usado: C:\Users\Alvaro!\AppData\Local\Arduino15\packages\digistump\hardware\avr\1.6.7\libraries\DigisparkOLED
exit status 1
‘DelayMs’ was not declared in this scope
Your code doesn’t work
Check your c code libraries.
I don’t know why, but I beat this code into compliance… sort of. Here is what I did to resolve the errors listed above:
1. ‘DelayMs’ was not declared in this scope. Resolved by replacing ‘DelayMs’ with’ delay’ in all instances.
2. ‘SSD1306’ was not declared in this scope…SSD1306.ssd1306_init();
Resolved by removing all “SSD1306.” instances leaving the remainder (i.e. ssd1306_Init();)
3. restored lines 182-196 of ssd1306xled.cpp that had been previously commented out disabling the fillscreen function.
4. Commented out all code on the Weather_Demo tab due to the multiple declarations of variables. I think the intent was to use one of the first two tabs.
I hope this is of some help to others.
for me the wiring was wrong it was sda to p2 and scl to p0 but apart fromt hat really good guide, helped alot understanding the Digispark