PROGRAMMING ATTINY85 AND I2C COMMUNICATION USING ATTINY85
3 min readJan 22, 2022
Connections with Arduino for SPI Communication
- 5v — pin8
- GND — pin4
- D10 — pin1
- D11 — pin5
- D12 — pin6
- D13 — pin7
- 10uF capacitor between reset and ground(optional)
Programming ATTINY85 for blinking LED with Arduino as ISP
- Files->examples->ArduinoISP->ArduinoISP->upload
- Files->preferences->paste”http://drazzy.com/package_drazzy.com_index.json” in
additional boards manager. - tools->board->boards manager->search attiny->install ATtinyCore
- tools->board->ATtiny85 @ 8MHz(BOD disabled)
- tools->programmer->Arduino as ISP
- tools->burn bootloader
- Connect led at pin0->program->upload.
Code
void setup()
{
pinMode(0,OUTPUT);
}
void loop()
{
digitalWrite(0,HIGH);
delay(100);
digitalWrite(0,LOW);
delay(100);
}
I2C Communication with ATtiny is master and Arduino as slave
- Download the ATtiny85 I2C master library from
“https://playground.arduino.cc/uploads/Code/TinyWireM/index.zip” - Unzip the library and copy that library into documents/arduino/libraries
- Upload the code in ATtiny85 by making the Arduino as an ISP.
#include<TinyWireM.h>
void setup() {
TinyWireM.begin();
}
void loop() {
TinyWireM.beginTransmission(8);
TinyWireM.send('8');
TinyWireM.endTransmission();
delay(5000);
TinyWireM.beginTransmission(8);
TinyWireM.send('4');
TinyWireM.endTransmission();
delay(5000);
Upload the Arduino code by selecting Arduino/Genuino uno in tools->boards
#include<Wire.h>
char x;
void setup() {
Wire.begin(8);
Wire.onReceive(receiveevent);
Serial.begin(9600);
Serial.println("data received");
pinMode(7,OUTPUT);
}
void receiveevent()
{
while(Wire.available()>0){
x=Wire.read();
Serial.println(x);
}}
void loop() {
delay(100);
if(x=='8')
{digitalWrite(7,0);
delay(100);
digitalWrite(7,1);
delay(100);}
else if(x=='4')
{ digitalWrite(7,0);
delay(1000);
digitalWrite(7,1);
delay(1000);}}
Connections for I2C communication
Arduino -> ATtiny85
A4 -> port 0 (SDA).
A5 -> port 2 (SCL).
- Functionality of the code:
The master writes the data to the slave and depending on the character sent in the
slave, Arduino changes the speed of a blinking LED.
I2C Communication with ATtiny is slave and Arduino as master
Download the ATtiny85 I2C library from
”https://playground.arduino.cc/uploads/Code/TinyWireS/index.zip”
- Unzip that library and copy that library into documents/arduino/libraries.
- Upload the ATtiny85 code by making arduino as ISP
#include<TinyWireS.h>
void setup() {
TinyWireS.begin(8);
}
void loop() {
TinyWireS.send('8');
delay(100);
}
Upload the arduino code by selecting arduino/genuino uno in tools->board
#include<Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
Wire.requestFrom(8,1);
while(Wire.available())
{
char c=Wire.read();
Serial.println(c);
}
delay(500);
}
- Connect accordingly for I2C communication
- Functionality of the code:
The master reads the data from the slave which is ATtiny85 and prints that data in
the serial monitor