Waveshare-Expansions
Contents
Introduction
This guide introduces how to bring up Waveshare expansions on Tinker Borad.
Waveshare is a manufacturer of development kits and universal modules. The company offer includes products dedicated for education and for prototyping.
This document will show the porting procedures step-by-step for the part of most popular expansions from Waveshare.
Beside the modules listed here, you can find many kinds of products on https://www.waveshare.com/".
Outlines
a. RPi LED Matrix
b. RGB LED HAT
c. RGB LED HAT (B)
d. RPi Touch Keypad
e. 2.13inch e-Paper HAT
Image Version
Please use V2.0.3 image version or above
Porting steps
a. RPi LED Matrix
Because the original demo code is implemented by c and uses many APIs of bcm2835 library.
I traced the code and wrote a new one by python for Tinker Board.
Before testing it, please install the require modules for controlling SPI:
$ sudo apt update $ sudo apt install python-dev python-setuptools python-wheel python-pip $ pip install spidev
Plug the Led matrix onto Tinker Board and run the demo code:
$ python ws_ledMatrix.py # you can find it in attachment
The demo code will send data to controll each led on/off, change the content in disp1 to show what you want!
b. RGB LED HAT & RGB LED HAT(B)
The code for this module does not support Tinker Board hardware again, I re-write a demo code with python and use SPI to instead of DMA.
First, please change the pin connection that connect pin 19 (SPI2TX) of Tinker Board to pin 12(P18/Din) of HAT.
Then install the required packages for python (skip the part if you have done it at a.)
$ sudo apt update $ sudo apt install python-dev python-setuptools python-pip python-wheel $ pip install spidev
And run the demo code to test the RGB led HAT:
$ python led_test.py
You can change the RGB values by modifying the values of r, g, b:
r = int((1 + math.sin(n * 0.1324)) * 127) g = int((1 + math.sin(n * 0.1654)) * 127) b = int((1 + math.sin(n * 0.1)) * 127)
And modify the led_cnt depends on the number of leds:
led_cnt = 64 # RGB LED HAT (B) has 64 leds
# RGB LED HAT has 32 leds
d. RPi Touch Keypad
Because the demo code of touch keypad also uses APIs of bcm2835 library and it's short, I implement new demo code by python again.
However, with the smbus module of python, there is a question that ACK from slave device (please reference to I2C protocol) cannot be recognized.
So I reference to the https://raw.githubusercontent.com/shenki/linux-i2c-example/master/i2c_example.c and re-write the code by c, then it works!
Please find the code in attachment and run it as following:
$ cd <the_path_of_code> && make $ ./keypad_test
The program will keep polling the data from TTP229, the touch IC, and when you can find which key is pressed by the changed value:
By the way, I connect the SCL/SDA to pin 5 (I2C1_SCL) and pin 6 (I2C2_SDA) to use i2c-1.
If you want to use another bus, modify the path in demo code, and remember to change the hardware connetction pins, too.
const char *path = "/dev/i2c-1";
e. 2.13inch e-Paper HAT
Install the required modules as below: (skip the part if you have done it at a.)
$ sudo apt update $ sudo apt install python-dev python-setuptools python-pip python-wheel python-pil $ pip install spidev
Install gpio library:
$ git clone https://github.com/TinkerBoard/gpio_lib_python.git $ cd gpio_lib_python && python setup.py install
Run the modified demo code (please find them in attachment):
$ python main.py
The epaper will show some text and graphics at beginning, then load the .bmp file and show on it.
Reference
https://www.waveshare.com/
Waveshare wiki - https://www.waveshare.com/wiki/RPi_LED_Matrix
Waveshare wiki - https://www.waveshare.com/wiki/RGB_LED_HAT
Waveshare wiki - https://www.waveshare.com/wiki/RGB_LED_HAT_(B)
Waveshare wiki - https://www.waveshare.com/wiki/RPi_Touch_Keypad
Waveshare wiki - https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT
https://github.com/shenki/linux-i2c-example