attiny85 lcd display free sample

I will start by saying that this project was result of many days of trial and error. In general it is easy to connect an I2C adapter to an LCD and drive it with an Attiny85. But this was not the case for me! My I2C adapter was refusing to cooperate with any common library. The screen was either flickering or it was displaying white squares.

At some point it came to me that I had a library that was working for this specific LCD with Arduino as my controller. So I start searching my computer for this code, and managed to make my LCD work with this one. Keep reading for the solution.

I used an arduino nano as programmer and selected “Arduino as ISP” for that reason. Also make sure that all the board setting are the same as in the image bellow. Board: Attiny85, Processor: Attiny85, Clock: Internal 8MHz (it is very important to select internal clock), Port: whatever port arduino is connected to

#include <LCD.h>

lcd.begin (16,2); // <<----- My LCD was 16x2

attiny85 lcd display free sample

A library that utilizes the I2C library for ATtiny85 so to control an I2C LCD screen. Largely based on the Digispark library. This library was supposed to be seamlessly working as the old LiquidCrystal I2C by Malpartida with normal arduinos and attinys. However because my Arduino 1.6.1 IDE wanted me to include the regular Wire library in every sketch and also some old sketches of mine wouldn"t work with this version, I decided to turn this into a dedicated ATtiny85 library for controlling the LCD screen through an I2C connection. Some minor changes, just to enforce separation of concerns in other words. Don"t forget the 4.7 ΚΩ resistors between the SDA and SCK lines and the Vcc.

attiny85 lcd display free sample

This article describes a 64x48 monochrome OLED display based on an ATtiny85. I"ve included three sample applications: a simple oscilloscope, a wireframe animation, and an analogue voltmeter:

The display needs 4 pins to drive it, just within the capabilities of the ATtiny85 and leaving one pin available for another application. You can"t read the display memory, so to do graphics you need to write into a buffer in RAM, and then copy this to the display. Because the display is 64x48 pixels it requires 64x48/8 or 384 bytes of memory for the graphics buffer, again just within the capabilities of the ATtiny85.

The resistor from the display"s CS pin holds the chip select high to prevent the display from being affected by the ISP signals while programming the ATtiny85.

The graphics commands to plot points, draw lines, and draw text, all edit a buffer, which stores one bit for each pixel on the display. This is defined as follows:

The DisplayBuffer() routine display the contents of the buffer by copying the bytes to the display. For this application we"re using the display"s Horizontal Addressing mode, which copies bytes to the display memory from left to right and top to bottom. To use this mode you just specify the column and page ranges with the commands 0x21 and 0x22, and then send the 384 bytes.

The SSD1306 is designed to handle displays up to 128x64, and the 64x48 display is positioned in the centre of this area, so to address it you need to select columns 32 to 95 (inclusive) and pages 2 to 7 (inclusive):

I spent a bit of time optimising the Data() routine, to make the display update as fast as possible. This version uses a variable changes to determine whether the data pin, PB1, should be changed for each bit to be output. This allows us to write to the PINB port to toggle the bit. With an 8 MHz ATtiny85 this routine updates the display in about 5.4 msec. This implies that we can update the display about 180 times a second, fast enough for simple animations.

Note that this doesn"t do any checking, so either make sure you don"t plot points outside the display area, or add a line to check the x and y values.

Because of the limited RAM available on the ATtiny85, the text to be plotted is also specified in program memory, and the PlotText() routine reads the characters using pgm_read_byte():

To define the text to be plotted as being in program memory use the PSTR() macro (for PROGMEM string). For example, to plot "ATtiny85" centred on the second line of the display, write:

The first application is an analogue voltmeter that reads the voltage on the analogue input A2 (PB4), and displays it as a pointer on an analogue display:

3rd December 2018: Fixed the circuit diagram so the CS pin is held high by the 33kΩ resistor (not low), and tidied up the program to make it consistent with Big Text for Little Display.

attiny85 lcd display free sample

This is a compact graphics library that supports a range of different colour TFT displays, such as the displays from Adafruit and AliExpress. It uses standard Arduino SPI calls making it compatible with a variety of different boards and processors:

In my earlier article Tiny TFT Graphics Library I described a small graphics library designed for driving a variety of TFT displays from an ATtiny85. This library is an extension of that program, with the following enhancements:

* These Adafruit displays conveniently all have the same edge-connector layout, so you can make a prototyping board or PCB that will take any of them.

Some of the AliExpress displays include a LDO 3.3V regulator, but as far as I can tell none of them include logic-level translation, so I recommend only interfacing them to a processor running from 3.3V.

The Adafruit displays all include an LDO 3.3V regulator and logic-level translation, so can be safely interfaced to processors powered from either 5V or 3.3V.

On the AliExpress 160x128 display you need to connect the backlight pin to Vcc to turn it on. This doesn"t seem to be necessary with the other displays.

The library will probably support other TFT displays that use the same ST7735 or ST7789 driver chips, but you may need to experiment with the parameters to get the image scaled and centered correctly.

Two of these, Data In and Clock, are dictated by the SPI interface on the processor you are using. They are usually called MOSI and SCK on the pinout diagram, and they connect to the appropriate two pins on the display.

This graphics library will work with ATtiny processors that support SPI using the hardware USI peripheral, such as the ATtiny85, ATtiny84, and ATtiny4313, but note that on these devices the MOSI pin is labelled DO.

The library includes basic graphics routines for plotting points and drawing lines. These work on a conventional coordinate system with the origin at lower left. For example, on the 80x160 display:

The different displays are catered for by six constants which specify the size of the display, the offsets relative to the area supported by the display driver, whether the display is inverted, and the rotation value; for example:

Note that on some displays you may also have to change the xoff or yoff value when rotating the display. For example, to rotate the image on the 240x240 displays by 180° use the settings:

To check or adjust the values for each display I ran this program, which draws a one-pixel border around the display area, and plots an "F" to show the orientation:

attiny85 lcd display free sample

Using an LCD on a small chip like an attiny85 is not really that hard and till recent I didnt even think it warranted an instructable, but I have received questions about it, so I may as well expand on the process.

With the attiny only having a max of 6 pins available, it goes without saying that it cannot directly control all the pins of the standard Hitachi based LCD"s

A little bit over a year ago, I described how to add an LCD to an Attiny or other chip, using only 2 pins. That circuit made use of an HC164 shift register, but as I2C modules for LCD"s are extremely cheap and even LCD"s with a module already in place also are dirt cheap, one might as well use I2C on the Attiny85.

I2CThe attiny85 can simulate I2C on PB2 (pin 7) (SCL) and PB0 (pin 5) (SDA). The "Wire" library that is used to read and write bytes from and to the I2C port on the arduino doesnt work on the attiny. It needs the TinyWireM library to act as an I2C master

The "NewLCD" library from Francisco Malpartida is my favorite library, but also that one fails in using I2C for the Attiny because it makes a call to the Wire library. A modification to make it work with Attiny85 can be found here.

The "Bro Hogan" library however does work. It is basically the same library as the standard arduino LCD library, but it is modified to recognize the Attiny85 and the Attiny2313 and then makes a call to "TinyWireM" rather than "Wire".

Adafruit also provides a libray that works with the Attiny85 and that is described in another instructable. I will be using the Bro Hogan library here.

Most problems you may encounter are related to the IDE getting confused regarding the libraries. If you are using the standard Arduino LCD library, best replace it by the Bro Hogan library. If you are using Malpartida"s library and want to keep that (as it is a great library), move it out of the way. Grab the entire folder and move it out of your sketchbook/libraries folder. Make sure you have the TinyWireM library installed and make sure your libraries are up to date.

Now obviously there is no bootloader for the attiny85, but the process of burning the bootloader sets the fuses of the attiny from factory mode, to the mode you want to use it in. So, presuming you use the Arduino as ISP,:

attiny85 lcd display free sample

The Arduino family of devices is features rich and offers many capabilities. The ability to interface to external devices readily is very enticing, although the Arduino has a limited number of input/output options. Adding an external display would typically require several of the limited I/O pins. Using an I2C interface, only two connections for an LCD character display are possible with stunning professional results. We offer both a 4 x 20 LCD.

The character LCD is ideal for displaying text and numbers and special characters. LCDs incorporate a small add-on circuit (backpack) mounted on the back of the LCD module. The module features a controller chip handling I2C communications and an adjustable potentiometer for changing the intensity of the LED backlight. An I2C LCD advantage is that wiring is straightforward, requiring only two data pins to control the LCD.

A standard LCD requires over ten connections, which can be a problem if your Arduino does not have many GPIO pins available. If you happen to have an LCD without an I2C interface incorporated into the design, these can be easily

The LCD displays each character through a matrix grid of 5×8 pixels. These pixels can display standard text, numbers, or special characters and can also be programmed to display custom characters easily.

Connecting the Arduino UNO to the I2C interface of the LCD requires only four connections. The connections include two for power and two for data. The chart below shows the connections needed.

The I2C LCD interface is compatible across much of the Arduino family. The pin functions remain the same, but the labeling of those pins might be different.

Located on the back of the LCD screen is the I2C interface board, and on the interface is an adjustable potentiometer. This adjustment is made with a small screwdriver. You will adjust the potentiometer until a series of rectangles appear – this will allow you to see your programming results.

The Arduino module and editor do not know how to communicate with the I2C interface on the LCD. The parameter to enable the Arduino to send commands to the LCD are in separately downloaded LiquidCrystal_I2C library.

Several examples and code are included in the Library installation, which can provide some reference and programming examples. You can use these example sketches as a basis for developing your own code for the LCD display module.

The I2c address can be changed by shorting the address solder pads on the I2C module. You will need to know the actual address of the LCD before you can start using it.

Once you have the LCD connected and have determined the I2C address, you can proceed to write code to display on the screen. The code segment below is a complete sketch ready for downloading to your Arduino.

The code assumes the I2C address of the LCD screen is at 0x27 and can be adjusted on the LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27,16,2); as required.

Similar to the cursor() function, this will create a block-style cursor. Displayed at the position of the next character to be printed and displays as a blinking rectangle.

This function turns off any characters displayed to the LCD. The text will not be cleared from the LCD memory; rather, it is turned off. The LCD will show the screen again when display() is executed.

Scrolling text if you want to print more than 16 or 20 characters in one line then the scrolling text function is convenient. First, the substring with the maximum of characters per line is printed, moving the start column from right to left on the LCD screen. Then the first character is dropped, and the next character is displayed to the substring. This process repeats until the full string has been displayed on the screen.

The LCD driver backpack has an exciting additional feature allowing you to create custom characters (glyph) for use on the screen. Your custom characters work with both the 16×2 and 20×4 LCD units.

A custom character allows you to display any pattern of dots on a 5×8 matrix which makes up each character. You have full control of the design to be displayed.

To aid in creating your custom characters, there are a number of useful tools available on Internet. Here is a LCD Custom Character Generator which we have used.

attiny85 lcd display free sample

LiquidCrystal fork for displays based on HD44780. Uses the IOAbstraction library to work with i2c, PCF8574, MCP23017, Shift registers, Arduino pins and ports interchangably.

The most powerful and popular available library for using 7/14/16 segment display, supporting daisy chaining so you can control mass amounts from your Arduino!

Menu library for Arduino with IoT capabilities that supports many input and display devices with a designer UI, code generator, CLI, and strong remote control capability.

A simple library to display numbers, text and animation on 4 and 6 digit 7-segment TM1637 based display modules. Offers non-blocking animations and scrolling!

Monochrome LCD, OLED and eInk Library. Display controller: SSD1305, SSD1306, SSD1309, SSD1312, SSD1316, SSD1318, SSD1320, SSD1322, SSD1325, SSD1327, SSD1329, SSD1606, SSD1607, SH1106, SH1107, SH1108, SH1122, T6963, RA8835, LC7981, PCD8544, PCF8812, HX1230, UC1601, UC1604, UC1608, UC1610, UC1611, UC1617, UC1638, UC1701, ST7511, ST7528, ST7565, ST7567, ST7571, ST7586, ST7588, ST75160, ST75256, ST75320, NT7534, ST7920, IST3020, IST3088, IST7920, LD7032, KS0108, KS0713, HD44102, T7932, SED1520, SBN1661, IL3820, MAX7219, GP1287, GP1247, GU800. Interfaces: I2C, SPI, Parallel.

True color TFT and OLED library, Up to 18 Bit color depth. Supported display controller: ST7735, ILI9163, ILI9325, ILI9341, ILI9486,LD50T6160, PCF8833, SEPS225, SSD1331, SSD1351, HX8352C.

attiny85 lcd display free sample

If you want to embed a microcontroller into a project and are looking for something smaller and cheaper than an Arduino and you don’t need a lot of I/O pins or code space, the ATtiny85 can be a good solution.

The ATtiny85 is an 8-bit Atmel ATtiny85 MCU from the same AVR family that the Arduino boards are based on.  Though it only has 8 pins, it packs quite a lot of functionality into that small package.

The device can be programmed using the Arduino IDE and much of the standard Arduino software and existing libraries will work with it.  Other libraries have been modified to work properly with the ATtiny85.

The 5V pin can accept a 3.0 – 5.5V input if you want to power the module directly off 5V or a battery pack in that range.  This range is determined by the ATtiny85 chip operating range.  If you are instead using the VIN pin to power the module, then you can use this pin as a 5V output to power a sensor or other device.

When connecting the SPI interface, the pins are cross-connected, so the ATTiny85 MISO pin would connect to the external device MOSI and the ATTiny85 MOSI would connect to the external device MISO.

The I/O port on the ATtiny85 chip is Port B and that is why digital I/O are labeled PB0 – PB5 on the backside of the board (and P0-P5 on the front side).  These correspond to digital I/O D0-D5 on an Arduino and are referenced in the program using just the number as in pinMode(0, OUTPUT);

You can program the ATtiny85 using the Arduino IDE.  The basic steps are presented here.  There is a link to an excellent video at the end of this section that explains the process of getting your environment setup in great detail.

If everything goes as planned, when you plug the ATtiny85 into the computer using a Micro USB cable, you will see the device recognized as Digispark Bootloader in the Windows Device Manager window.

If you are new to the ATtiny85, or have any issues with getting the programming environment up and running it is highly recommended that you watch this excellent video as it answers most of the questions that may come up:

One unique feature of programming the ATtiny85 module is that you do not select a COM port to communicate to it with.  Instead you follow these basic steps:

Our example here creates a simple temperature and humidity display.  The LCD display uses I2C communications and the DHT22 humidity/temperature sensor uses a library to communicate using one pin.

Some libraries that come with the Digistump download are standard libraries that have been modified to work with the ATtiny85, but still have the same name.  For example, our program is using the LiquidCrystal_I2C.h library which has been modified to work with the ATiny85.  If you are getting errors because the program is not finding the correct library to use, simply copy the  LiquidCrystal_I2C.h and LiquidCrystal_I2C.cpp files from the Digistump download location to the same folder as the ATtiny85 sketch.  The parenthesis around the library name in the program below tell the compiler to look in the current directory for the files.

Also connect a source of 5V power for the LCD and DH22.  In our setup here, we are using a 5V power supply to supply power to the LCD display, DH22 sensor and the ATtiny85 module.

attiny85 lcd display free sample

I2C or Inter Integrated circuit is another popular serial communication protocol built in almost every modern microcontrollers. This protocol uses full duplex communication and uses only two wires to exchange data.  ATtin85 microcontroller is equipped with Universal Serial interface aka USI which can be configured to operate in I2C mode. I2C mode using this USI interface is also referred as Two wire mode. In this tutorial we will see how to configure USI as I2C protocol in ATtiny85 microcontroller to send and receive data between devices.

When master need to communicate it will send slave address via data line SDA. The slaves connected to master will receive the address. And then only the slave matching the address will store the incoming data from master device and other slaves will discard the incoming data from master. In ATtiny85 microcontroller SDA pin is PB0 and SCL pin is PB2. Read more about this protocol in detail.

A – In ATtiny85 this start condition occurs when master device pulls the SDA line low while keeping the SCL line high. This can be done by writing the PB0 pin to zero or low. Now the start detector of the slave device deduces this as start condition and sets the USISIF flag.

This the actual register which holds the data that need to be sent and the data that is received from other devices. User need to write 8 bit data in this register and then transmit the data by activating clock pulses to synchronize the transfer. Similarly when the ATtiny85 receives the data each bit received and placed in the USIDR register. When transfer of a byte is complete, data in USIDR register will be copied to USIBR register.