我遇到了以下问题,经过长时间的挫折后,我无法让它发挥作用,有人可以帮助一个菜鸟吗?
我想在我的Raspberry Pi 3B Jessie上通过I2C使用了几个SRF02 Ranging sensors .
我按照教程并将第一个传感器更改为地址0xF2(从Raspberry看到的0x79),这一切都完美无缺 . 但问题是地址0x78到0x7B是为10位I2C Adressing保留的,所以我必须使用另一个 . But since I cannot access it anymore through I2C since I changed the address I decided to do it through the serial port.
我尝试按tutorial中的描述更改它,但它不起作用 . 以下是代码以及我在完成研究后所做的工作:
-
我检查了传感器的地址 . 上电时,它会发送一个长闪码和9个短闪烁,因此在串行模式下其地址应为0x09 .
-
我更新并升级了我的Raspberry .
-
我将传感器RX引脚连接到Rasp TX,反之亦然 . 5V的传感器到3p的Rasp(这是一个问题吗?) . 传感器接地并将模式引脚接地 .
-
在raspi-config上,我将串口控制台更改为禁用,并将串口硬件端口更改为启用 .
这是我的/boot/cmdline.txt:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
我在/boot/config.txt中添加了以下内容:
enable_uart=1
dtoverlay=pi3-disable-bt
core_freq=250
我的python代码(通过发送范围命令,传感器应该闪一次,但它没有,我也没有得到任何结果):
import serial
import time
ser = serial.Serial(port='/dev/serial0', baudrate = 9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_TWO, timeout=1, write_timeout=5)
USED_ADDRESS = '0x09'
TARGET_ADDRESS = '0x03'
# GET DISTANCE IN CM
ser.write(USED_ADDRESS)
ser.write('0x51')
time.sleep(0.07)
ser.write(USED_ADDRESS)
ser.write('0x5E')
results = ser.read(2)
if(results != None and len(results) > 0):
print 'RESULTS:'
for result in results:
print result
else:
print 'NO RESULT'
#CHANGING ADDRESS
#First command
ser.write(USED_ADDRESS)
ser.write('0xA0')
#Second command
ser.write(USED_ADDRESS)
ser.write('0xAA')
#Third command
ser.write(USED_ADDRESS)
ser.write('0xA5')
#Target Address
ser.write(USED_ADDRESS)
ser.write(TARGET_ADDRESS)
print "DONE"
dmesg的结果| grep tty:
[ 0.000000] Kernel command line: 8250.nr_uarts=1 bcm2708_fb.fbwidth=640 bcm2708_fb.fbheight=480 bcm2708_fb.fbswap=1 vc_mem.mem_base=0x3dc00000 vc_mem.mem_size=0x3f000000 dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles
[ 0.000312] console [tty1] enabled
[ 0.748748] 3f201000.serial: ttyAMA0 at MMIO 0x3f201000 (irq = 87, base_baud = 0) is a PL011 rev2
ls -l / dev / serial *的结果:
lrwxrwxrwx 1 root root 7 Feb 16 15:06 /dev/serial0 -> ttyAMA0
lrwxrwxrwx 1 root root 5 Feb 16 15:06 /dev/serial1 -> ttyS0
有人有个主意吗?对于任何提示,我都会感激不尽 .
1 回答
好的,我解决了!我在这里找到了解决方案:https://www.raspberrypi.org/forums/viewtopic.php?t=63419