是什么意思,树莓派 串口串口ttyAMA0是啥

> 博客详情
摘要: 树莓派串口的使用 - 蓝牙模块BT-HM10
首先树莓派得安装 python-serial& ,Raspbian还需要在raspi-config中激活UART.
然后修改文件1:sudo nano /boot/cmdline.txt, 删除红色部分:&
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
最终变为: dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
然后修改文件2:sudo nano /etc/inittab, 注释最后一行内容:&
#T0:23:respawn:/sbin/getty-L ttyAMA0 115200 vt100,
模块HM-10的配置方法:在蓝牙模块未连接蓝牙4.0设备的情况下,使用串口调试工具minicom,复制命令后,粘贴在工具里发送给模块。具体参见该模块的手册。蓝牙4.0设备如手机用app与模块相连,最后用该模块公司出的那个 BLE蓝牙串口调试助手 app。
写程序用uart与模块通信 BT_demo.py
import&serial
import&time
ser&=&serial.Serial('/dev/ttyAMA0',&115200,&timeout=1)
#ser&=&serial.Serial('COM3',&115200,&timeout=1)
print&ser.isOpen()
words="abcd"
while&1:&&&&&&
&&&&getchr&=&ser.read()
&&&&#print&getchr
&&&&if&getchr&==&'h':
&&&&&&&&ser.write(words)
&&&&time.sleep(5)
ser.close()
调试过程出现错误:
如果安卓app发送字符出现发送不成功,比如点一下发一大串:
1, 可能是树莓派上串口没打开,Raspbian在raspi-config 中打开,并确认串口文件修改配置正常。
2,由于先连接了模块后运行程序,正确的应该是先运行程序后连接模块。
如果收发没反应,或者是乱码,确认连接正确,速率是否匹配。
人打赏支持
码字总数 2689
支付宝支付
微信扫码支付
打赏金额: ¥
已支付成功
打赏金额: ¥树莓派学习笔记 - 简书
树莓派学习笔记
sudo apt-get install ttf-wqy-zenhei
sudo apt-get install scim-pinyin
然后设置locale。
树莓派3代串口设置
图片发自简书App
作为一个准·软件工程师,我购买了一块Arduino。
其实是。这东西对控制时序要求比较高并且需要AD转换,手上的PCF8591不仅精度低、I2C接口也决定了它很难满足GP2Y的时序要求,因此选择了内置ADC的Ardunio,并使用它作为从机,将采集到的数据发送到树莓派。
那么问题来了,如何使用树莓派(3代)的串口呢?
执行下列命令:
sudo apt-get update
sudo apt-get upgrade
然后,安装串口工具minicom:
sudo apt-get install minicom
一切就绪。现在开始配置树莓派方面的串口。
一、树莓派串口配置
1. 关闭串口控制台
首先,修改/boot/cmdline.txt,将含有console=&关于串口的&删掉,关闭串口控制台。
2. 将硬件串口绑定到GPIO
查看/boot/overlays/目录下有没有pi3-miniuart-bt-overlay.dtb这个文件,如果没有,。
然后修改/boot/cmdline.txt,添加
dtoverlay=pi3-miniuart-bt-overlay
force_turbo=1
3. 关闭板载蓝牙模块
由于树莓派的硬件串口被蓝牙模块占用,因此需要解除占用。首先输入
sudo systemctl disable hciuart
关闭hciuart。
然后编辑/lib/systemd/system/hciuart.server将 “serialX”修改为“ttyS0”。
4. 关于串口设备文件的名字
实际上目前的Raspbian中串口文件是/dev/serial0,有文章指出树莓派还有一个软串口miniuart,不知道serial0和ttyAMA0之间是什么关系。在此不予深究,反正就是使用/dev/serial0就可以。
二、硬件连线
如果安装了wiringPi的话,输入
gpio readall
可以查看串口对应的硬件引脚。一般来说,物理引脚6、8、10分别对应GND、TxD、RxD。
需要注意,Arduino是5V电平(据说是,我也不知道),树莓派是3V3电平,因此必须使用电平转换芯片,或者其他匹配措施。我使用的是TXS0108E电平转换芯片,有一个使能端OE,需要接3V3高电平使能。
三、树莓派端串口操作
我使用了一款GPS接收模块,默认波特率为9600,以1Hz的频率从串口输出NMEA协议数据。
树莓派端执行sudo minicom -s,设置串口文件为/dev/serial0,波特率9600,软硬件流量控制都关掉。保存为dfl(默认),Exit回到minicom,正常情况下树莓派这边应该能收到串口数据。
树莓派与电脑共享Internet
操作系统是官方Raspbian。下文中,树莓派的IP固定为192.168.0.3/24,网关(路由器)为192.168.0.1,校园网的DNS是101.7.8.9和121.248.60.11。
条件所限,笔记本电脑无线网卡用来连接外网,以太网口用来连接树莓派。
Windows 10 上,打开【控制面板】-【网络连接】,右键选择无线网卡,在属性的【共享】选项卡中将网络共享给以太网。
以太网卡方面,手动设置其IP为192.168.0.1/24,默认网关192.168.0.1,手动设置DNS为101.7.8.9和121.248.60.11,即可。
Windows XP 上,差不多的步骤,但需要注意一点是,开启无线网卡共享后,以太网的IP会被自动设置,确认后重新设置即可。
Ubuntu14.04 上(没有试过),先放在这里。
树莓派静态IP设置
首先修改/etc/network/interfaces,将iface eth0 inet manual改成static,添加一些内容,结果如下:
iface eth0 inet static
address 192.168.0.3
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 101.7.8.9 121.248.60.11
正如文件中的提示所说,只修改这个文件还不够,还需要修改/etc/dhcpcd.conf,添加以下内容:
# static ip config
interface eth0
static ip_address=192.168.0.3/24
static routers=192.168.0.1
static domain_name_servers=101.7.8.9
存退,重启机器即可。
服务器搭建
sudo apt-get install nginx
sudo apt-get install php5-fpm
sudo apt-get install php5-sqlite
之前最好update一下。另,软件源推荐使用USTC的软件源,比较靠谱。
然后将/etc/nginx/sites-available/default的PHP部分改成:
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \\\\\\\\\\\\\\\\.php$ {
include snippets/fastcgi-php.
# With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.
启用PHP5。
有的时候,使用exec()之类的函数执行系统命令行,需要为我们的cgi设置超级用户权限。尽管为安全起见,并不推荐这么做,但考虑到开发需要,我们可以在
/etc/sudoers
里面适当位置加上这样一行
www-data ALL=(ALL:ALL) NOPASSWD:ALL
即可赋予PHP以执行sudo命令的权限。
此时,在(默认的)
/var/www/html
目录下新建index.php并添加其内容
phpinfo();
然后用浏览器访问该页,如果输出php相关的内容,说明配置成功。
本节参考资料
修改开机启动信息
vncserver开机自启动
共产党员 / 程序员 / 言和【树莓派】树莓派串口配置和使用
日 | 标签:  | 浏览: 3,992  |   
树莓派大家应该不陌生了。作为一个小型电脑,吸引了很多硬件开发者的关注。但是如果我们要使用树莓派的串口,那么必须要自己配置一下。和其他的ARM9等处理器一样,这个串口是作为终端输出信息的。因此我们可以通过这个串口,使用超级终端等工具来控制树莓派里的Linux系统。
如果我们使用树莓派的串口通信,比如连接GPS设备,或者与其他单片机通过串口通信。那么我们就要配置一下了。
首先我们先要知道串口的接线方式,如果所示。
其引脚分布图如下。
我们只需要RXD,TXD,GND三条线就可以通信了。但是注意这个是TTL电平的信号,如果要和电脑想链接,必须要转换电平。当然,如果和单片机相连接,一般就不需要了。
下面说一下如果配置。主要是修改 /boot/cmdline.txt这个文件。
使用vi或者vim打开 /boot/cmdline.txt。
$ sudo vi /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
即删除console=ttyAMA0,115200
和 kgdboc=ttyAMA0,115200然后保存。
然后修改/etc/inittab 注释掉下面这一行,一般是文件的最后一行。注释掉就是在行首添加一个英文#号。
$sudo vi/etc/inittab
注释掉 T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
然后保存。
重启一下树莓派,这个时候就可以使用串口发送和接收数据了。
如果要测试串口,可以在树莓派上安装minicom串口工具。
下面简单介绍一下树莓派串口的编程,使用C语言
具体参考这个文档吧。
/developerworks/cn/linux/l-serials/
作者:靳小都
除非注明,本文原创:,欢迎转载!转载请以链接形式注明本文地址,谢谢。原文链接:
相关文章近期热评最新日志
最新评论分类目录raspberry(7)
转载来源:
树莓派的串口接口是P1接口上面一排(靠近板子边缘的一排)左数第4针(TX)和第五针(RX)
系统中对应的串口设备是/dev/ttyAMAO,但默认用于内核输出日志的。若想连接串口设备,比如GPS模块,需要改动系统这个默认配置。
配置方法如下(修改2个文件,记得先备份好原始文件):
修改 /boot/cmdline.txt
$ sudo vi /boot/cmdline.txt
将原来的内容
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
修改/etc/inittab 注释掉下面这一行,一般是文件的最后一行。注释掉就是在行首添加一个英文井号。
$ sudo vi /etc/inittab
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
顺便说下命令行下用什么编辑器,我比较习惯用vi。对命令行不太熟悉的同学就用nano吧,用之前google下教程,非常简单。
改好这两个文件后,关机。接好串口设备开机,为了检查串口有没有工作,需要安装个串口通讯软件minicom。
$ wajig install minicom
这里我使用了wajig这个工具,它对apt系列工具进行了封装,更易用,强烈推荐。
安装好minicom后,需要先根据你的串口设备进行相应的设置,比如速率什么的
$ sudo minicom -s
选择主菜单的第三项Serial Port Setup,进入下一级菜单。
用菜单项的第一个提示字母选择:按A 修改串口设备为 /dev/ttyAMA0,按E修改速率等设置
设置好后,主菜单里选择Save setup as dfl保存,然后选择Exit(最后一项Exit from Minicom是退出程序)。如果设置正确,就应该收到一些数据了。按Ctrl+A,再按Z可以查看minicom的帮助,Ctrl+A再按Q退出minicom。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:18587次
排名:千里之外
转载:18篇SHA - - - Raspberry Pi - RS232 Serial Interface Options&(Revisit)
d.i.y. home automation projects
Contributions
Contributions are appreciated and used to host this site.
Thank You for your support.
Recent Projects / Posts
Featured Articles
& RASPBERRY&PI
Feature Products
Raspberry Pi with Java: Programming the Internet of Things (IoT)
Raspberry Pi 2 Model B Project Board - 1GB RAM - 900 MHz Quad-Core CPU
Premium Clear Case for Raspberry Pi 2 Model B Quad Core and Raspberry Pi Model B+ (B PLUS)
Edimax EW-7811Un 150 Mbps Wireless 11n Nano Size USB Adapter with EZmax Setup Wizard
Getting Started with Raspberry Pi
Raspberry Pi User Guide
PiBrella LED Add On Board
Diversitech(R) WS-1 - Wet Switch Flood Detector
Onsite Pro FS1NPTW Whole Home Wireless FloodStop with 1 Inch Valve
Floodstop Washing Machine Valve Shutoff Kit
Onsite Pro FS3/4H Washing Machine FloodStop with Straight Valves
Floodstop Individual Water Appliance Additional Water Sensor XS-01
Aqua Managers - FS 1 1/4-NPT - Floodstop for Water Heaters Water Leak Detection System - White - 1.25 in. pipe
Furman MP-20 Power Relay Accessory, 20 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
Furman MP-15 Power Relay Accessory, 15 Amp, Two Outlets, Remote Turn-on from Momentary or Maintained Contact Switches
Metra 70-2002 Radio Wiring Harness for Saturn 00-05
Metra Reverse Wiring Harness 71-2002 for Select
Saturn Vehicles OEM Radio
In the previous article
we discussed how to install a RS232 port on the Raspberry Pi. &This is a follow up article to suggest a few alternative interface options as the XBit RS232 level-shifter board has been unavailable (sold out) for while now.
There are two primary RS232 interface options you can choose from for serial connectivity: &
&(USB to Serial Adapter)
&(Level Shifter)
Once you have a serial interface connected you can use the serial port for
(Click one of the above options to jump to that part of the article.)
Shopping List
The following items are included in this article:
Serial Communication via USB
If you are just looking to communicate to your Raspberry Pi via its serial UART, then you may prefer a USB interface. &Most recent models of computers and laptops do not have the traditional RS232 DB9 port anymore, so connecting using a USB port may be preferred. &&
The following adapter is only $5.47 USD and it provides a USB to serial converter chip: & &&
This adapter is based on the Prolific PL2303HX chipset. &To use this USB to serial interface you will have to install a USB serial port driver on your host operating system. &Many operating systems already include support for theserolific drivers. &But in case you need it, the drivers can be found here: &
Below is a wiring diagram illustrating how to connect the USB to serial interface:
Photos of the connected USB to Serial interface (click to enlarge):
NOTE:&&Please secure the RED lead from the USB adapter so that it does not come into contact with any of the other pins or components on the Raspberry Pi. &This RED pin carries +5VDC and could damage the Pi if it makes contact.
Now that you have the serial interface connected, you can skip down to the
section to test the interface.
Serial Communication via DB9 (Level Shifter)
For certain applications and especially project involving interfacing with other hardware devices a standard RS232 serial device with a DB9 connector is preferred. &A standard serial port such as this does not require any drivers. &RS232 serial communication is standardized at the hardware layer. &RS232 communication can also achieve longer distance runs (maximum distance depends on baud rate). &
The following interface adapter is available for $9.99 USD:
In addition to the adapter, you will need at least 4 female to female 2.54mm .1 in jumper wires.&
Here are a couple of purchase options:
Why is special circuitry (level shifter) needed for RS232 serial communication?
So .. what a&level shifter& and why is it needed you ask. &A level shifter is a circuit that can take the low voltage (&3.3VDC) TTL signals for serial transmit (TX) and receive (RX) from the UART on the Pi and shift them to &5VDC the voltage signals required for RS232 standard communication. &Want to know more? &Click&. &&
Below is a wiring diagram illustrating how to connect the level shifter serial interface:
Now that you have the serial interface connected, you can skip down to the&&section to test the interface.(Use a straight-thru cable for connecting to a computer.)&
Serial Console
The Debian/Raspbian distribution images include support out-of-the-box for accessing the shell console via the hardware serial port. &This can be extremely convenient if you need to access your Raspberry Pi when it is not connected to a monitor and network remote access is not available.
Open a terminal emulation software such as Hyperterminal, Procom Plus, or Indigo Terminal Emulator and connect to the serial port using settings "115200, N, 8, 1". & You may need to press the enter key a time or two to see the prompt. &Authenticate using your credentials and you are good to go. && & & &
Here is a screenshot of the terminal displaying the boot up information and then prompting for a login:
Software use of the Serial Port
If you intend to use the serial port for a software application running on the Raspberry Pi, there is a bit of configuration required to disable the console from using this port. &&By default, the serial port is configured as a console port for interacting with the Linux OS shell. &The following steps will guide you through disabling the port from console access.
First, lets make of backup of the two files that we intend to modify.
sudo cp /boot/cmdline.txt /boot/cmdline.baksudo cp /etc/inittab /etc/inittab.bak
Next, we need to remove the "console=ttyAMA0,115200" and "kgdboc=ttyAMA0,115200" configuration parameters from the "/boot/cmdline.txt" configuration file.&
To edit the file use this command:
sudo nano /boot/cmdline.txt
The file probably contains this default configuration line:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
After removing the two configuration parameters, it will look similar to this:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
The last step is to edit the "/etc/inittab" file and comment out the use of the "ttyAMA0" serial port. &To edit the file use this command:
sudo nano /etc/inittab
Now towards the bottom of the file, look for a configuration line that includes the "ttyAMA0" port address.
Place a pound sign ("#") in front of the line to comment it out. &With a pound sign ("#") at the beginning of the line, Linux will ignore this configuration line. &
Save the "/etc/inittab" file and then issue this command to reboot the Raspberry Pi:
sudo reboot
Now you are ready to use the serial port with a software application and the operating system won't interfere with the port. &Use the device address "ttyAMA0" in your application to access this serial port. &
If are interested in using the serial port with Java programming, please see this page:&
Update on Wednesday, October 8, 2014 at 8:55AM by
I have updated the wiring diagram and photos for the USB TTL adapter approach to remove the 5VDC RED pin connection. &It was technically working, but I felt it was safer to eliminate this connection to prevent current from being sourced from the USB connection/adapter back into the Raspberry Pi.
October 30, 2012 |
December 12, 2012 |
December 16, 2012 |
January 25, 2013 |
January 25, 2013 |
February 6, 2013 |
February 7, 2013 |
March 10, 2013 |
April 5, 2013 |
April 5, 2013 |
July 11, 2013 |
July 11, 2013 |
July 11, 2013 |
July 11, 2013 |
July 11, 2013 |
July 11, 2013 |
July 11, 2013 |
July 11, 2013 |
July 11, 2013 |
July 31, 2013 |
Author Email (optional):
Author URL (optional):
Some HTML allowed: &a href=&& title=&&& &abbr title=&&& &acronym title=&&& &b& &blockquote cite=&&& &code& &em& &i& &strike& &strong&
Link an External Response
Have a response on your own site?
You can either use the [] for this entry, or link to your response directly.
Article Title:
Article URL:
Article Excerpt (optional):
Site Name:
Site URL (optional):
Author Name:
References will be subject to editor approval before appearing.
Your reference will not appear until it has been cleared by a website editor.}

我要回帖

更多关于 树莓派串口通信 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信