ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

How to use import serial in Ros Foxy

asked 2021-12-21 04:18:39 -0500

Nur92 gravatar image

updated 2022-02-22 11:17:30 -0500

lucasw gravatar image

Hello. I wanted to ask. Is it possible to use serial port for ros foxy for publishing data?

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-12-21 06:15:41 -0500

ljaniec gravatar image

You could try micro-ROS, but I am not sure if it fits your use case - could you describe it?

edit flag offensive delete link more

Comments

import RPi.GPIO as GPIO import time import serial

GPIO.setmode(GPIO.BCM)

redLED = 13 GPIO.setup(redLED, GPIO.OUT) GPIO.output(redLED,False)

ser = serial.Serial('/dev/ttyUSB0',115200,timeout=None)

while True: GPIO.output(redLED, False) line1 = ser.readline() line2 = ser.readline() line3 = ser.readline() line4 = ser.readline() ch1 = line1.strip().decode('utf-8') ch2 = line2.strip().decode('utf-8') ch3 = line3.strip().decode('utf-8') ch4 = line4.strip().decode('utf-8') print(ch1,ch2,ch3,ch4) GPIO.output(redLED, True) time.sleep(1) ser.close()

i wanted to publish the ser.readline data.

Nur92 gravatar image Nur92  ( 2021-12-21 06:36:04 -0500 )edit

Then this demo https://micro.ros.org/blog/2019/06/03... or this tutorial https://ubuntu.com/blog/getting-start... suit you very well :) With Raspberry Pi and some LEDs

ljaniec gravatar image ljaniec  ( 2021-12-21 06:55:18 -0500 )edit

Thank you for the suggestions but is it possible is I don't want to use micro ros? and for the raspberry pi I'm using raspberry pi 4.

Nur92 gravatar image Nur92  ( 2021-12-21 17:11:28 -0500 )edit

Unfortunately, I only know (somewhat) the solution for ROS1, rosserial, I am not sure if there is similar package for ROS2. I couldn't find any, so I mentioned micro-ROS.

ljaniec gravatar image ljaniec  ( 2021-12-22 03:54:39 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-12-21 04:18:39 -0500

Seen: 305 times

Last updated: Dec 21 '21