串行通信raspberrypi2 [英] serial communication raspberrypi2
本文介绍了串行通信raspberrypi2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有raspberrypi 2 modlde。我需要从pi模块生成串行数据。这是我的代码
#!/ usr / bin / env python
import时间
导入序列
ser = serial.Serial(
port = ' / dev / ttyAMA0',
baudrate = 9600 ,
parity = serial。 PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
bytesize = serial.EIGHTBITS,
timeout = 1
)
counter = 0
而 1:
ser.write(' 写计数器:%d \ n'%(计数器))
time.sleep( 1 )
counter + = 1
这是错误信息
Traceback(最近一次调用最后一次):
文件/home/pi/Desktop/serial.py,第3行,< 模块 >
import serial
文件/home/pi/Desktop/serial.py,第6行,< module >
ser = serial.Serial(
AttributeError:'module'对象没有属性'serial'
> >>
什么是error.pls帮我...
谢谢你
解决方案
请从这里开始: http://www.elinux.org/Serial_port_programming [ ^ ]。
-SA
i have raspberrypi 2 modlde. i need to make serial data from the pi module. this is my code
#!/usr/bin/env python
import time
import serial
ser = serial.Serial(
port='/dev/ttyAMA0',
baudrate = 9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)
counter=0
while 1:
ser.write('Write counter: %d \n'%(counter))
time.sleep(1)
counter += 1
this is the error msg
Traceback (most recent call last):
File "/home/pi/Desktop/serial.py", line 3, in <module>
import serial
File "/home/pi/Desktop/serial.py", line 6, in <module>
ser=serial.Serial(
AttributeError: 'module' object has no attribute 'Serial'
>>>
what is the error.pls help me...
thank you
解决方案
Please start here: http://www.elinux.org/Serial_port_programming[^].
—SA
这篇关于串行通信raspberrypi2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文