ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

How to use import serial in Ros Foxy

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

Nur92 gravatar image

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

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

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

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


import RPi.GPIO as GPIO import time import serial


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 -0600 )edit

Then this demo or this tutorial suit you very well :) With Raspberry Pi and some LEDs

ljaniec gravatar image ljaniec  ( 2021-12-21 06:55:18 -0600 )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 -0600 )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 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



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

Seen: 108 times

Last updated: Dec 21 '21