For controlling GPIO pins in Jetson Nano, we can make use of the Jetson GPIO Python library (https://github.com/NVIDIA/jetson-gpio). You can install the library using a simple pip command shown here:
$ sudo pip install Jetson.GPIO
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/jetsonnano_gpio.py. Check out the important details of the code here:
...
import RPi.GPIO as GPIO
LED = 12
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 RPi.GPIO library we installed. After the necessary import statements, we define the GPIO that we would use as OUT, which means output (since it is LED in our case, but 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 that's true or false. In the next section, we will cover benchmarking embedded boards.