How to access GPIO with ROS-MELODIC?

JetPack 4.3
Ros-Melodic

Greetings,

I have a Jetson Nano and Adafruit Motor Shield v3. After looking over the documentation for the Motor Shield it appear that you can talk to it with 3/5V I2C. So I thought about going down the rabbit hole to try and access the GPIO from a ROS package.

Is there a file that I can include like a header file (e.g. gpio.h) that would facilitate such an endeavor?

I think it would be neat to send commands directly instead of using ROS Serial and an arduino with a shield installed.

Cheers,

Coach

hello CoachAllen,

you might refer to Topic 1030443 for tutorials showing how to use GPIO.
please access L4T sources via download center. you should check the gpio definition as below.
for example,
$l4t-r32.3.1/TX1_Nano/Linux_for_Tegra/source/public/kernel/kernel-4.9/include/dt-bindings/gpio/tegra-gpio.h

Hi,

I’m newbie at Ubuntu and ROS. I’m trying to use Jetson Nano 's GPIO within a ROS subscriber node. But I’m getting this error:

File “/home/hostr/hostr_ws/src/motor_controller/script/motor_controllerpy.py”, line 3, in
import Jetson.GPIO as GPIO
ImportError: No module named Jetson.GPIO

and this is the code:

#!/usr/bin/env python

import rospy
import Jetson.GPIO as GPIO
from geometry_msgs.msg import Twist

def setupGPIO(pENA,pENB,pIN1):
GPIO.setmode(GPIO.BOARD)
GPIO.setup(ENA, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN1, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(IN2, GPIO.OUT, initial=GPIO.LOW)

def callback(data):
print(data.linear.x)
print(data.angular.z)

def listener():

rospy.init_node('motor_controllerpy', anonymous=True)
rospy.Subscriber("cmd_vel", Twist, callback)
rospy.spin()

if name == ‘main’:
listener()
ENA = 33
IN1 = 35
IN2 = 37
setupGPIO(ENA,IN1,IN2)

I looked to the link has given but i understand nothing. If someone can help me, I’ll be glad.

Thanks,

Hi infohost.robotic,

Please help to open a new topic for your issue. Thanks