Skip to content

Use a LCD i2c with attiny84

Using an ATtiny84 to drive an i2c LCD screen.

Target Hardware

  • ATtiny84 MCU
  • LCD display with i2c adaptor board.

Libraries installation

Three libraries are required.

Libraries Modifications

Tiny Core

The tiny core will need to see the new.cpp and new.h from the arduino core. An easy way get this working is to copy files. On Linux platform this will be something like

cp /usr/share/arduino/hardware/arduino/cores/arduino/new.* /home/user/sketchbook/hardware/tiny/cores/tiny/

Note. If using arduino IDE version 1.5 and above you will need to copy the new.h and new.cpp from an older version of the IDE. These are given here. new.cpp new.h

TinyWireM

Open file TinyWire.h.

On line 57 replace void send(uint8_t);

by void`` ``write(uint8_t);

On line 60 replace void receive(uint8_t);

by void`` ``read(uint8_t);

Open file TinyWire.cpp

On line 49 replace

void USI_TWI::send(uint8_t data){ // buffers up data to send by void`` ``USI_TWI::write(uint8_t`` ``data){`` ``//`` ``buffers`` ``up`` ``data`` ``to`` ``send

On line 76 replace

if (xferOK) return 0; by if`` ``(xferOK)`` ``return`` ``1;

On line 83 replace

uint8_t USI_TWI::receive(){ // returns the bytes received one at a time by uint8_t`` ``USI_TWI::read(){`` ``//`` ``returns`` ``the`` ``bytes`` ``received`` ``one`` ``at`` ``a`` ``time

Open file USI_TWI_Master.cpp

On line 23 replace #define F_CPU 1000000UL // Sets up the default speed for delay.h

by #define`` ``F_CPU`` ``8000000UL`` ``//`` ``Sets`` ``up`` ``the`` ``default`` ``speed`` ``for`` ``delay.h

Open file USI_TWI_Master.h

On line 23 replace #define SYS_CLK 1000.0 // [kHz] Default for ATtiny2313

by #define`` ``SYS_CLK`` ``8000.0`` ``//`` ``[kHz]`` ``Default`` ``for`` ``ATtiny2313

LiquidCrystal

Open file I2CIO.cpp

After line 34 insert the code below:

#if defined(__AVR_ATtiny84__) || (__AVR_ATtiny2313__) #include "TinyWireM.h"      // include this if ATtiny85 or ATtiny2313 #define Wire TinyWireM #else #include <Wire.h>           // original lib include #endif

Then delete the line that says:

#include <../Wire/Wire.h>

Basic sketch example

#include <TinyWireM.h> #include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

void setup() {

lcd.begin(16,2);

//3 flash introduction for(int i = 0; i< 3; i++) { lcd.backlight(); delay(150); lcd.noBacklight(); delay(150); } lcd.backlight();

lcd.setCursor(2,0); lcd.print(">lechacal.com<"); lcd.setCursor(6,1); lcd.print("..."); }

void loop() { }

This article has mainly been inspired by this article here for the ATtiny85. http://meta-blog.eklablog.com/attiny85-lcd-en-i2c-p977350