Raspberry pi2串口通信
来源:互联网 发布:淘宝跳失率多少正常 编辑:程序博客网 时间:2024/06/10 16:39
安装pyserial的串口库,$ wget http://downloads.sourceforge.net/project/pyserial/pyserial/2.7/pyserial-2.7.tar.gz
下载后,对压缩文件解压:
$ tar zxvf ./pyserial-2.7.tar.gz
$ cd pyserial
$ sudo python setup.py install
用命令查找串口设备
$ dmesg | grep tty*
打开python交互运行环境
$ python
>>> import serial
>>> ser = serial.Serial('/dev/ttyUSB0',115200)
>>> while 1:
.... ser.readlin()
>>>ser.write('this is string')
连接到PC端串口调试助手,打印
Communication with ROS through USART Serial Port
$ cd ~/catkin_ws/src$ catkin_create_pkg r2SerialDriver std_msgs rospy roscpp$ cd ~/catkin_ws$ catkin_make
To add the workspace to your ROS environment you need to source the generated setup file:
$ . ~/catkin_ws/devel/setup.bash$ cd ~/catkin_ws/src/r2SerialDriver/src
Add a file: "r2Serial.cpp", Source code:
Modify the CMakeList.txt file:
$ cd ~/catkin_ws/src/r2SerialDriver$ gedit CMakeList.txt
add/modify these lines as below:
- find_package(catkin REQUIRED COMPONENTS
- roscpp
- rospy
- std_msgs
- )
- include_directories(
- ${catkin_INCLUDE_DIRS}
- )
- add_executable(r2SerialDriver src/r2Serial.cpp)
- add_dependencies(r2SerialDriver ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
- target_link_libraries(r2SerialDriver
- ${catkin_LIBRARIES}
- )
Save and Build the package again:
$ cd ~/catkin_ws$ catkin_make -DCMAKE_BUILD_TYPE=Release
He also offered a simple launch file that interfaces to two microcontrollers using two serial connections, put the code into
"~/catkin_ws/src/r2SerialDriver/launch/r2SerialDriver.launch" file:
- <launch>
- <node pkg="r2SerialDriver" type="r2SerialDriver" name="r2Serial0" args="0 /dev/ttyUSB0 9600" output="screen" >
- <remap from="ucCommand" to="uc0Command" />
- <remap from="ucResponse" to="uc0Response" />
- </node>
- <node pkg="r2SerialDriver" type="r2SerialDriver" name="r2Serial1" args="1 /dev/ttyUSB1 9600" output="screen" >
- <remap from="ucCommand" to="uc1Command" />
- <remap from="ucResponse" to="uc1Response" />
- </node>
- </launch>
Usage:
$ rosrun r2SerialDriver r2SerialDriver 0 /dev/ttyUSB0 9600
or
$ roslaunch r2SerialDriver r2SerialDriver.launch
try:
$ rostopic pub -r 1 /uc0Command std_msgs/String hello_my_serial$ rostopic echo /uc0Response
You may also need to remap the /dev/ttyUSB* to some name you like cuz you may have several usb-serial devices.If so, just Ref:重新指派usb转串口模块在linux系统中的设备调用名称(English Version: remap your usb-serial devices' names in Linux )
But Kevin mentioned a question: "Interesting, but a lot of my serial stuff is send a message and receive a response back. Instead of separate publish/subscribes have you tried a service? That seems like it would work nicely for this."
I also noticed a problem: The Linux's System RAM and CPU will be much costed by r2serial_driver when it is running.
Next time, we'll see how to use Kevin's service to play ROS serial communication.
2. Use Service to play ROS-Serial communication
see this blog brother below...
http://blog.csdn.net/sonictl/article/details/51372534
- Raspberry pi2串口通信
- raspberry pi2 andrid
- 编译raspberry pi2内核
- Raspberry Pi2/3引脚介绍
- Raspberry pi 之间的串口通信总结
- Raspberry pi 使用python+pySerial实现串口通信
- raspberry pi2 智能小车源码及测试视频
- 用Kinect1和Raspberry pi2制作简易3D扫描仪
- Ubuntu Mate: mak Raspberry Pi camera work without raspi-config on Raspberry Pi2
- Raspberry Pi3 串口问题
- 如何在windows系统下用串口通信完爆raspberry pi(树莓派)
- 树莓派(Raspberry Pi2)上源码编译安装tensorflow——基于NFS
- Gitlab在Ubuntu、Debian、CentOS 6、CentOS 7、OpenSUSE、Raspberry Pi2安装
- 串口通信
- 串口通信
- 串口通信
- 串口通信
- 串口通信
- Android ListView图片蒙层点击监听
- java学习笔记
- 炒股的四类投资法
- Swift开发UITableView常用的一些细节知识点介绍
- Appium的ios环境搭建、真机运行app
- Raspberry pi2串口通信
- 2016夏季练习——AC自动机
- PyGobject(八)布局容器之Button篇——Gtk.LinkButton
- 跨站点请求伪造
- 最全的常用正则表达式大全
- android studio tabhost基础 多功能时钟app 实现闹钟功能(一)
- [LeetCode] 52. N-Queens II
- Android UI高级之RecyclerView
- SourceTree+OSChina+CocoaPods提交时,Pods提交失败解决办法: