Usage Instructions
The TWI 7-segment display can be used with any microcontroller that has a TWI or I2C bus. It works both with 5V and 3.3V systems (note that maximum brightness is lower on 3.3V compared to 5V).
To use with an Arduino or a board compatible with the Arduino IDE, there is an Arduino library available. It is implemented using the Wire library, and should work with any Arduino.
A low-level avr-gcc library is also available, and should work on ATMega chips that have an on-board hardware TWI bus. (ATTiny chips are not supported at this time, as they do not have TWI hardware).
If your processor is not directly supported, you can interface with the chip directly using its TWI protocol.
The library is the same as used with
null display, and the two displays can be used interchangably.
Usage with Arduino
The TWI 7-segment display is directly supported in the Arduino IDE. Version 1.0 or later is required.
To use it, either download our custom IDE package, with the required library preinstalled:
Arduino IDE with Akafugu Libraries.
If you already have the Arduino IDE installed, get the package and follow the instructions in this page:
Arduino IDE with Akafugu Libraries.
Once you have the Arduino IDE and the Akafugu Libraries installed, start or re-start the IDE. You should now have a TWIDisplay submenu inside the File -> Examples menu.
Here is a small example sketch for dislaying a number counter:
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #include <Wire.h> #include <TWIDisplay.h> #define SLAVE_ADDR 18 TWIDisplay disp(SLAVE_ADDR); void setup() { Wire.begin(); disp.setRotateMode(); disp.clear(); disp.setBrightness(255); } void loop() { // count to 9999 for ( int i = 0; i <= 9999; i++) { disp.writeInt(i); delay(100); } } !ENDMARKER! Copy and paste this code into the Arduino IDE, and press VERIFY compile it. You can also access this sample code along with other examples in the File -> Examples -> TWIDisplay menu. To try out the display with an Arduino board, you will need to hook up the four required wires. If you have a standard Arduino boards, such as the Arduino UNO, hook the wires up like this : SDA - Pin A4<br> SCL - Pin A5<br> GND - GND<br> VCC - 5V If you have an Arduino Mega board, use the following connection: SDA - Pin 20<br> SCL - Pin 21<br> GND - GND<br> VCC - 5V If you have a <ProductLink {... this .props} name= "serial-isp-breadboard" text= "null" ></ProductLink> board SCL and SDA is in the upper right side of the board. The pins are marked with SCL and SDA and should be easy to find. Other newer Arduino boards also have SCL and SDA marked on the silk screen. After everything is hooked up, connect the USB port of the Arduino to your computer, select the correct port in the Tools->Serial Port menu, and press the Upload button. Once programming finished, you should see the display count from 0 to 9999. Usage with avr-gcc ------ The library available on [GitHub](https: //github.com/akafugu/twidisplay) supports ATMega processors together with the [avr-gcc toolchain](/posts/resources/avr-gcc/). Note that this library currently only supports ATMega chips with onboard I2C/TWI. ATTiny processors using USI are not supported. Here is a small example for displaying a number counter: !CODEMARKER!#include <avr/io.h> #include <avr/interrupt.h> #include <util/delay.h> #include "twi-display.h" #define SLAVE_ADDR 18 // 7-seg void main( void ) { twi_init_master(); sei(); set_rotate_mode(SLAVE_ADDR); clear(SLAVE_ADDR); set_brightness(SLAVE_ADDR, 255); // count to 9999 for (uint16_t i = 0; i < 9999; i++) { write_int(SLAVE_ADDR, i); _delay_ms(100); } } |
Protocol Documentation
If your processor has hardware TWI/I2C, adding support for it should be easy. We recommend using theGitHub library as a reference.
Have a look at the protocol documentation here:
null