Tinkerboard S

Tinkerboard comes with GPIO API support in shell, Python, and C programming. Since we've working with ROS, let's learn how to control the GPIOs using Python. For more information on the GPIO pinout, please refer to the following link: https://tinkerboarding.co.uk/wiki/index.php/GPIO#Python.

GPIOs in Tinkerboard can be controlled via the Python GPIO library at http://github.com/TinkerBoard/gpio_lib_python. To install this library, use the following commands:

$ sudo apt-get install python-dev
$ git clone http://github.com/TinkerBoard/gpio_lib_python --depth 1 GPIO_API_for_Python
$ cd GPIO_API_for_Python/
$ sudo python setup.py install

Now that the Python library is installed, let's learn how to control an LED blink from a ROS topic. You can find the whole code here: https://github.com/PacktPublishing/ROS-Robotics-Projects-SecondEdition/blob/master/chapter_7_ws/tinkerboard_gpio.py. Check out the important details of the following code:

...

import ASUS.GPIO as GPIO

GPIO.setwarnings(False)
GPIO.setmode(GPIO.ASUS)
GPIO.setup(LED,GPIO.OUT)

...

def ledBlink(data):
if data.data = true:
GPIO.output(LED, GPIO.HIGH)
time.sleep(0.5)
GPIO.output(LED, GPIO.LOW)
time.sleep(0.5)
else:
GPIO.cleanup()

...

In the preceding code, we make use of the ASUS.GPIO library we had installed. After the necessary import statements, we set the mode to GPIO.ASUS. We then define the GPIO that we would use as OUT, meaning output (as it is LED in our case, whereas it would be IN if it was a switch). Then, we have the function to make the LED blink, in case the /led_status topic receives a Boolean true or false.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.2.122