I²C displays are awesome because they save a lot of pins on your microcontroller. A 20×4 sainsmart display would require 16 total pins, and using a I²C bus reduces it to only 4, with the possibility of sharing with other devices, as specified by the I²C protocol. If you are not familiar with I2C or SPI, the Sparkfun website have a very welcoming introduction .
In this tutorial we used a 20×4 sainsmart display with an I²C module included, as seen in figure 1, tp connect to a raspberry pi using the I²C port and a logic level translator module.
Configuring the I2C bus
First we need enable and put the I2C bus to work
Select “8 – Advanced Config”-> and enable I2C bus:
Open terminal again and install the dependencies:
`sudo apt-get install python-smbus i2c-tools`
There are two I2C ports on the raspberry pi, user and system (better use user)
i2cdetect in the terminal will report if
program will probe all the addresses on a bus, and report whether any devices are present.
Connecting the display
These displays only works 5V TTL logic, and the raspberry pi is 3V3 logic. So we have to use a logic level converter, and it’s usually available on online electronic shops, as pcb modules. Pay attention and check your connections before turning the power on!
The second I2C port are available at pins 23 (GPIO0 / I2C_SDA) and 24 (GPIO1 / I2_SCL), that you can check on the side figure.
The 3V3 and 5V of the I2C module can be connected to the raspberry pi, but pay attention to the max current rating of the pins. From the elinux.org wiki page :
The maximum permitted current draw from the 3.3 V pins is 50 mA.
Maximum permitted current draw from the 5 V pin is the USB input current (usually 1 A) minus any current draw from the rest of the board.
- Model A: 1000 mA – 500 mA -> max current draw: 500 mA
- Model B: 1000 mA – 700 mA -> max current draw: 300 mA
LCD interface using python
The repository  with the code example was extracted from , and it’s easy to setup. The code is very simple and it’s a good example on how to use python to interface with hardware. The hierarchy of the files are lcd.py –> i2c_lcddriver.py –> lcd_lib.py.
It is pretty straight forward to use, and can be adapted to other uses. Figure 4 shows my test results.
Using the RPI GPIOs
The gpio program is a good way to start messing around the raspberry pi’s gpios. Some the commands are:
Other possibilities can be found at .