I2C bus

The AQM0802 communicate by the I2C protocol. Let’s activate I2C protocol on the Raspberry Pi.

Install i2c-tools

The “i2c-tools” utility is needed to communicate by the I2C protocol on the Raspberry Pi.

$ sudo apt-get install i2c-tools

After install the “i2c-tools” utility, you activate the I2C by the “raspi-config” utility. And then, you should shutdown the Raspberry Pi to attach the LCD module.

If you find the kernel modules called “i2c_bcm2708” and “i2c_dev” using the “lsmod” utility, you can use the I2C protocol.

pi@raspberrypi:~ $ lsmod
Module                  Size  Used by
cfg80211              407532  0 
rfkill                 16036  1 cfg80211
bcm2835_rng             1763  0 
i2c_bcm2708             4920  0 
bcm2835_gpiomem         2860  0 
uio_pdrv_genirq         2944  0 
uio                     7753  1 uio_pdrv_genirq
i2c_dev                 5671  0 
snd_bcm2835            19802  0 
snd_pcm                73474  1 snd_bcm2835
snd_timer              18848  1 snd_pcm
snd                    50779  3 snd_bcm2835,snd_timer,snd_pcm
ipv6                  340825  37

You can know using the “i2cdetect” utility, whether the Raspberry Pi has found the LCD module. If you find “3e” on the address 3e, the LCD is available.

pi@raspberrypi:~ $ sudo i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- 3e -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --

The “i2cdetect” utility accepts the options as above, if your Raspberry Pi is the current version. When the Raspberry Pi is the early version, you should run as “i2cdetect -y 0”.

I2C protocol

The I2C protocol is the digital communication using a pair of a positive line and a negative line.

Because the I2C network can control multiple slave devices, the master device knows every slave device by the individual address. In this case, the AQM0802 is given addess as 0x3e. (“0x” is the prefix for hexadecimal.)

Now, you can operate the LCD module on 0x3e using the “i2cset” command of the “i2c-tools” utility.

Using the code in the blog of the Switch Science, you can see “SWITCH SCIENCE” on the LCD module.

The “i2cset” utility accepts the options as below.

i2cset "Option switch" "I2C bus number" "Chip address" "Data address" "Data" "Mode"
Parameter Details Values
Option switch Disable interactive mode -y
I2C bus number Indicate I2C bus number. Pi2’s number is 1. 1
Chip address Address of a slave device from 0x03 to 0x77. AQM0802 is 0x3e. 0x3e
Data address Address of RAM in a slave device from 0x00 to 0xff. AQM0802 has 0x00 for control and 0x40 for display characters. 0x00 of 0x40
Data Data written in a slave device. In AQM0802, the interuction code follows 0x00, and the characters for display follows 0x40. Various data
Mode Mode of data for a slave device. There are four types as b, w, s, and i.

  • b : Data of 1 byte (8 bits)
  • w : Data of 1 word (16 bits)
  • s : Size of the data block for SM bus
  • i : Size of data block for I2C
i

The SM bus is a one of the I2C bus.