0. Introduction

In a previous project I used the I2C channel of TinkerBoard and I was looking for a library that could handle it with python in an easy way. For this reason, I found this library available from Adafruit github page for raspberry and I changed it a bit in order to make it suitable for TinkerBoard.

1. Installing the dependencies

First of all, you need to install the package to use the library. For this reason type:

sudo apt-get update
sudo apt-get install build-essential python-pip python-dev python-smbus git i2c-tools
sudo adduser linaro i2c
sudo reboot

2. Downloading the repository and changing it a bit

You have now to download the repository:

cd ~
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git

Now you have to edit the files in order to make it suitable for TinkerBoard:

cd ~/Adafruit_Python_GPIO/
gedit Adafruit_GPIO/I2C.py

Now find these lines and add them in the script:

    plat = Platform.platform_detect()
    if plat == Platform.RASPBERRY_PI:
        if Platform.pi_revision() == 1:
            # Revision 1 Pi uses I2C bus 0.
            return 0
        else:
            # Revision 2 Pi uses I2C bus 1.
            return 1
    elif plat == Platform.BEAGLEBONE_BLACK:
        # Beaglebone Black has multiple I2C buses, default to 1 (P9_19 and P9_20).
        return 1
    elif plat == Platform.TINKERBOARD:                          #add these lines
        # Tinkerboard has multiple I2C buses, default to 4      #add these lines
        return 4                                                #add these lines

If you want to use a different I2C bus, you have only to change the

return 4

with another value.

The last file you have to edit is:

gedit Adafruit_GPIO/Platform.py

You have to add this line at the beginning of the file:

UNKNOWN = 0
RASPBERRY_PI = 1
BEAGLEBONE_BLACK = 2
MINNOWBOARD = 3
TINKERBOARD = 4  #add this line
...

Then, find this line and add it:

...
plat = platform.platform()
if plat.lower().find('xxxx') > -1:    #add this line
    return TINKERBOARD            #add this line
...

Istead of ‘xxxx’, open a terminal and type:

python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> plat = platform.platform()
>>> print plat.lower()

add the output of the last command inside the ”.

2. Installing it

The last step is the installation. Type:

sudo adduser linaro i2c
sudo python setup.py install

Now the library is ready!!