【问题标题】:Problems with serial communicaiton on Raspberry Pi 3Raspberry Pi 3 上的串行通信问题
【发布时间】:2017-04-18 12:28:51
【问题描述】:

我正在尝试在 Raspberry Pi3 和具有 RS-232 连接的数字传感器之间建立通信。我买了一顶帽子,上面也有一个 RS-232 端口,可以连接到 Pi 上的 rx 和 tx 引脚。 Pi 安装了 raspbian,我正在使用 Python 3 编写代码。

在我阅读的教程中,我必须先配置 Pi 以允许串行通信。我已经完成了以下步骤:

第 1 步:

sudo raspi-config -> Interfacing Options -> Serial -> [login shell accesible over serial? -> no] -> [serial port hardware enabled? -> yes]

第 2 步:

sudo nano /boot/cmdline.txt 

换行为:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

第 3 步:

sudo nano /boot/config.txt 

添加行:

dtoverlay=pi3-miniuart-bt
enable_uart=1
force_turbo=1

第 4 步:

 sudo apt-get install python-serial

在这个设置之后,我用 Python 3 编写了一个非常短的程序来测试它:

import serial
ser = serial.Serial('/dev/ttyAMA0', 9600)
ser.write(bytes(5, 'UTF8'))

数字 5 告诉传感器更改显示单位。代码运行时没有错误消息,但我没有看到传感器的单位发生变化。如果我使用串口转 USB 转换器将 RS232 连接到我的笔记本电脑并使用 Putty 监控串口,我也看不到任何发送。

如果有人能告诉我问题出在哪里,那就太好了。但我也很乐意为我自己找到解决方案提供任何意见。

提前非常感谢, 弗洛里安

【问题讨论】:

    标签: python-3.x serial-port raspberry-pi3


    【解决方案1】:

    我认为 Raspberry Pi 3 使用不同的设备作为串行端口。试试

    ser = serial.Serial('/dev/ttyS0', 9600)
    

    【讨论】:

    • 您能为您的贡献提供参考吗?例如。为什么你认为这是正确的端口?
    • 我不记得我在哪里看到的,但它是为了响应类似的问题。我知道这适用于最新的 Raspberry Pi Zero。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    • 1970-01-01
    • 2019-05-27
    相关资源
    最近更新 更多