数梅派连接arduino出现Permission denied: '/dev/ttyUSB0'错误解决

本文记录了在使用ROS与Arduino进行交互过程中遇到的权限错误问题,并详细介绍了如何通过修改用户组设置来解决串口访问权限受限的情况,最终成功启动ROS节点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

全部错误信息:

pi@pi:~$ roslaunch ros_arduino_python arduino.launch
... logging to /home/pi/.ros/log/21167e0a-74bf-11e7-b0e3-b827ebc62e10/roslaunch-pi-5106.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://pi.local:44455/

SUMMARY
========

PARAMETERS
 * /arduino/accel_limit: 0.2
 * /arduino/base_controller_rate: 10
 * /arduino/base_frame: base_link
 * /arduino/baud: 115200
 * /arduino/encoder_resolution: 52
 * /arduino/gear_reduction: 30.0
 * /arduino/left_Kd: 24
 * /arduino/left_Ki: 0
 * /arduino/left_Ko: 100
 * /arduino/left_Kp: 20
 * /arduino/motors_reversed: False
 * /arduino/port: /dev/ttyUSB0
 * /arduino/rate: 50
 * /arduino/right_Kd: 24
 * /arduino/right_Ki: 0
 * /arduino/right_Ko: 100
 * /arduino/right_Kp: 17
 * /arduino/sensorstate_rate: 10
 * /arduino/timeout: 0.1
 * /arduino/use_base_controller: True
 * /arduino/wheel_diameter: 0.068
 * /arduino/wheel_track: 0.287
 * /rosdistro: kinetic
 * /rosversion: 1.12.6

NODES
  /
    arduino (ros_arduino_python/arduino_node.py)

auto-starting new master
process[master]: started with pid [5129]
ROS_MASTER_URI=http://pi.local:11311

setting /run_id to 21167e0a-74bf-11e7-b0e3-b827ebc62e10
process[rosout-1]: started with pid [5142]
started core service [/rosout]
process[arduino-2]: started with pid [5145]
Connecting to Arduino on port /dev/ttyUSB0 ...
Serial Exception:
(<class 'serial.serialutil.SerialException'>, SerialException(13, "could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'"), <traceback object at 0x75608328>)
Traceback follows:
Traceback (most recent call last):
  File "/home/pi/catkin_ws/src/ros_arduino_bridge/ros_arduino_python/src/ros_arduino_python/arduino_driver.py", line 65, in connect
    self.port = Serial(port=self.port, baudrate=self.baudrate, timeout=self.timeout, writeTimeout=self.writeTimeout)
  File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 180, in __init__
    self.open()
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 294, in open
    raise SerialException(msg.errno, "could not open port %s: %s" % (self._port, msg))
SerialException: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'
Cannot connect to Arduino!
[arduino-2] process has died [pid 5145, exit code 1, cmd /home/pi/catkin_ws/src/ros_arduino_bridge/ros_arduino_python/nodes/arduino_node.py __name:=arduino __log:=/home/pi/.ros/log/21167e0a-74bf-11e7-b0e3-b827ebc62e10/arduino-2.log].
log file: /home/pi/.ros/log/21167e0a-74bf-11e7-b0e3-b827ebc62e10/arduino-2*.log

主要错误信息:

SerialException: [Errno 13] could not open port /dev/ttyUSB0: [Errno 13] Permission denied: '/dev/ttyUSB0'
Cannot connect to Arduino!

终端输入:

sudo usermod -a -G dialout pi

重新插拔usb后,再次运行

pi@pi:~$ roslaunch ros_arduino_python arduino.launch
... logging to /home/pi/.ros/log/2761f1ee-74c0-11e7-b0e3-b827ebc62e10/roslaunch-pi-5440.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://pi.local:37379/

SUMMARY
========

PARAMETERS
 * /arduino/accel_limit: 0.2
 * /arduino/base_controller_rate: 10
 * /arduino/base_frame: base_link
 * /arduino/baud: 115200
 * /arduino/encoder_resolution: 52
 * /arduino/gear_reduction: 30.0
 * /arduino/left_Kd: 24
 * /arduino/left_Ki: 0
 * /arduino/left_Ko: 100
 * /arduino/left_Kp: 20
 * /arduino/motors_reversed: False
 * /arduino/port: /dev/ttyUSB0
 * /arduino/rate: 50
 * /arduino/right_Kd: 24
 * /arduino/right_Ki: 0
 * /arduino/right_Ko: 100
 * /arduino/right_Kp: 17
 * /arduino/sensorstate_rate: 10
 * /arduino/timeout: 0.1
 * /arduino/use_base_controller: True
 * /arduino/wheel_diameter: 0.068
 * /arduino/wheel_track: 0.287
 * /rosdistro: kinetic
 * /rosversion: 1.12.6

NODES
  /
    arduino (ros_arduino_python/arduino_node.py)

auto-starting new master
process[master]: started with pid [5451]
ROS_MASTER_URI=http://pi.local:11311

setting /run_id to 2761f1ee-74c0-11e7-b0e3-b827ebc62e10
process[rosout-1]: started with pid [5464]
started core service [/rosout]
process[arduino-2]: started with pid [5481]
Connecting to Arduino on port /dev/ttyUSB0 ...
Connected at 115200
Arduino is ready.
[INFO] [1501375438.888724]: Connected to Arduino on port /dev/ttyUSB0 at 115200 baud
Updating PID parameters
Updating PID parameters
[INFO] [1501375439.043502]: Started base controller for a base of 0.287m wide with 52 ticks per rev
[INFO] [1501375439.045340]: Publishing odometry data at: 10.0 Hz using base_link as base frame

成功连接arduino,enjoy!

参考:
http://www.ncnynl.com/archives/201612/1209.html

<think>我们正在处理一个关于在Ubuntu24.04上运行Python程序时遇到ModuleNotFoundError的问题,具体是缺少'board'模块。用户提到“raspberrypi”,但问题是在Ubuntu上运行,所以可能是与莓派相关的库在Ubuntu上缺失。首先,我们需要明确:'board'模块通常与AdafruitBlinka库相关,该库用于在非莓派系统(如普通Linux、Windows)上模拟莓派的GPIO访问。因此,用户可能在运行一个为莓派编写的程序,但当前环境是Ubuntu桌面系统。解决方案步骤:1.确认是否安装了AdafruitBlinka库。该库提供了'board'模块。2.如果没有安装,则安装它。但是,注意:在非莓派系统上安装AdafruitBlinka需要额外步骤,因为它依赖于特定的库来模拟硬件访问。具体步骤:-首先,确保Python环境正确(可能是Python3)。-然后,安装必要的系统依赖(用于模拟莓派GPIO的库)。-最后,安装AdafruitBlinka。根据Adafruit官方文档,在非莓派系统上安装Blinka的步骤大致如下:1.安装Python开发包和pip(如果未安装):```bashsudoaptupdatesudoaptinstallpython3-devpython3-pip```2.安装libgpiod2(用于GPIO访问):```bashsudoaptinstalllibgpiod2```3.通过pip安装AdafruitBlinka:```bashpip3installadafruit-blinka```注意:如果用户使用虚拟环境,需要在虚拟环境中运行上述pip3命令。另外,用户提到“raspberrypi”,但问题是在Ubuntu上运行,所以需要确认程序是否确实需要模拟莓派环境。如果程序原本是为莓派编写的,那么上述步骤应该可以解决。如果用户是在莓派上运行Ubuntu24.04,那么可能需要安装莓派特定的库。但是,莓派官方系统通常已经包含了这些库,而Ubuntu24.04forRaspberryPi可能没有。在这种情况下,同样需要安装AdafruitBlinka。因此,无论用户是在普通Ubuntu桌面还是莓派上的Ubuntu,安装AdafruitBlinka都是解决方案。如果用户遇到权限问题,可以尝试在pip命令中添加`--user`选项,或者使用虚拟环境。最后,建议用户验证安装:```pythonpython3-c"importboard;print(board)"```如果没有报错,则说明安装成功。引用说明:用户提供的引用[^1]是关于MAVProxy的错误信息,与当前问题无关,因此我们忽略它。相关问题生成:考虑到用户的问题是关于模块缺失,我们可以生成一些相关问题,帮助用户深入理解或解决类似问题。§§相关问题§§1.如何为莓派编写的Python程序在普通Linux系统上运行?2.AdafruitBlinka库的作用是什么?3.在Ubuntu上安装Python模块的常见方法有哪些?4.如何避免Python环境中的模块冲突?</think>### Ubuntu 24.04 解决 Python ModuleNotFoundError: No module named 'board' 在 Ubuntu 24.04 上遇到 `ModuleNotFoundError: No module named 'board'` 错误,通常是因为缺少莓派 GPIO 访问所需的库。`board` 模块是 Adafruit Blinka 库的一部分,用于在非莓派系统(如 Ubuntu)上模拟莓派的 GPIO 功能。 #### 解决方案步骤: 1. **安装系统依赖** ```bash sudo apt update sudo apt install python3-dev libgpiod2 -y ``` - `python3-dev` 提供 Python 开发头文件 - `libgpiod2` 是 GPIO 设备访问库 2. **安装 Adafruit Blinka** ```bash pip3 install adafruit-blinka ``` - 如果使用虚拟环境,请在激活环境后安装 - 如果遇到权限问题,可添加 `--user` 选项 3. **验证安装** ```bash python3 -c "import board; print(board)" ``` 成功执行将显示类似结果:`<module 'board' from '...'>` 4. **额外依赖(若需要具体传感器支持)** ```bash pip3 install adafruit-circuitpython-<sensor_name> ``` 例如 DS18B20 温度传感器: ```bash pip3 install adafruit-circuitpython-ds18x20 ``` #### 常见问题排查: - **虚拟环境**:确保在正确的 Python 环境中安装 - **Python 版本**:确认使用 Python 3.x(Ubuntu 24.04 默认) - **权限问题**:使用 `sudo pip3` 可能导致系统包混乱,推荐使用 `--user` 或虚拟环境 - **硬件访问**:需要将用户加入 `gpio` 组: ```bash sudo usermod -aG gpio $USER ``` 然后注销重新登录 #### 原理解析 `board` 模块属于 [Adafruit Blinka](https://github.com/adafruit/Adafruit_Blinka),这是一个硬件抽象层,使为莓派编写的 CircuitPython 代码能在普通 Linux 系统运行。它通过 libgpiod 实现 GPIO 访问,无需莓派专用固件[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值