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!!
May 9, 2018 at 3:00 pm
I just want to say I am just beginner to blogging and site-building and honestly savored this web page. Probably I’m want to bookmark your blog post . You certainly come with terrific writings. Thank you for sharing with us your web page.
December 10, 2018 at 6:53 am
yah ga paham sama isi artikel nya
March 12, 2019 at 6:33 pm
Hi!
I used this tutorial and it seems to work, but i still got a problem.
In short, i’m trying to use a bme280 adafruit sensor on the TinkerBoard, using I2C protocol.
The i2cdetect command tells the channel used by the sensor is found, so it should be wired correctly.
I’m doing a test to see if i can read temperature using the following code
————————————————–
import ASUS.GPIO as GPIO
import busio
import adafruit_bme280
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
scl = 5
sda = 3
try:
GPIO.setup(scl, GPIO.IN)
GPIO.setup(sda, GPIO.IN)
i2c = busio.I2C(scl, sda, 1000)
bme = adafruit_bme280.Adafruit_BME280_I2C(i2c)
print(“\nTemperature: %0.1f C” % bme.temperature)
except KeyboardInterrupt:
pass
finally:
GPIO.cleanup()
————————–
but when i run it i get this error
linaro@tinkerboard:~/Python$ sudo python3 bme_test.py
Traceback (most recent call last):
File “bme_test.py”, line 14, in
i2c = busio.I2C(scl, sda, 1000)
File “/usr/local/lib/python3.5/dist-packages/busio.py”, line 16, in __init__
self.init(scl, sda, frequency)
File “/usr/local/lib/python3.5/dist-packages/busio.py”, line 23, in init
from machine import I2C as _I2C
ImportError: No module named ‘machine’
any idea how I can solve this?
Thank you for your time
March 12, 2019 at 8:37 pm
Hi Marco,
It seems the busio library is missing some dependencies. Have you correctly installed the machine package by typing:
sudo pip3 install machine
on the Tinkerboard terminal?
By the way, I would not recommend to use busio library with the Tinkerboard since it’s not natively supported by Adafruit.
March 13, 2019 at 9:25 am
Hi Simone,
thanks for your fast reply, I have now done a clean reinstall of TinkerOS and will try setting it up more carefully. I used the busio library because of the example code found on adafruit page
https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout/python-circuitpython-test
The project is to use the BME280 sensor to get data into the Tinker Board, using Python possibly. Since busio library is not natibely supported by Adafruit how would you do it?
Thank you again
Marco
March 13, 2019 at 10:34 am
Hi Marco,
I would try using the deprecated library from Adafruit itself https://github.com/adafruit/Adafruit_Python_BME280
March 27, 2019 at 4:59 pm
Hi again!
Clean reinstall and some testing with the BME280 library did the work!
I’m really grateful for your help!
Now i’m trying to make this OLED (https://www.adafruit.com/product/938) display work on the TinkerBoard, i managed to solder and connect via I2C both the sensor and the OLED display, the both get scanned by the i2cdetect command, but i can’t manage to get its library to work on tinkerOS.
Any idea how to make it work?
Marco
March 30, 2019 at 1:49 pm
Hi Marco,
Could you please post here all the error you got?
Simone
April 1, 2019 at 3:43 pm
Hi Simone,
so i tried with the Adafruit_Python_SSD1306 library from github but when i try run one examples i get this error:
linaro@tinkerboard:~/Adafruit_Python_SSD1306/examples$ sudo python shapes.py
Traceback (most recent call last):
File “shapes.py”, line 46, in
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
File “build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py”, line 288, in __init__
File “build/bdist.linux-armv7l/egg/Adafruit_SSD1306/SSD1306.py”, line 85, in __init__
File “build/bdist.linux-armv7l/egg/Adafruit_GPIO/GPIO.py”, line 420, in get_platform_gpio
ImportError: No module named Adafruit_BBIO.GPIO
i also tried using the luma.oled library since i’ve found a video telling it does actually work on tinker board but with not much more luck, i get this different error:
linaro@tinkerboard:~/luma.examples/examples$ sudo python welcome.py
Version: luma.oled 3.1.1 (luma.core 1.8.3)
Display: ssd1306
Interface: i2c
Dimensions: 128 x 64
————————————————————
Traceback (most recent call last):
File “welcome.py”, line 229, in
device = get_device()
File “/home/linaro/luma.examples/examples/demo_opts.py”, line 63, in get_device
device = cmdline.create_device(args)
File “/usr/local/lib/python2.7/dist-packages/luma/core/cmdline.py”, line 179, in create_device
device = Device(Serial(), **vars(args))
File “/usr/local/lib/python2.7/dist-packages/luma/oled/device/__init__.py”, line 185, in __init__
self._const.NORMALDISPLAY)
File “/usr/local/lib/python2.7/dist-packages/luma/core/device.py”, line 39, in command
self._serial_interface.command(*cmd)
File “/usr/local/lib/python2.7/dist-packages/luma/core/interface/serial.py”, line 84, in command
list(cmd))
File “/usr/local/lib/python2.7/dist-packages/smbus2/smbus2.py”, line 482, in write_i2c_block_data
ioctl(self.fd, I2C_SMBUS, msg)
IOError: [Errno 6] No such device or address
April 3, 2019 at 6:40 pm
Hi have you tried installing the Adafruit BBIO library via pip?
sudo pip install Adafruit_BBIO