关闭MU系列时,微控制器串行停止工作
我正在尝试控制一些Neopixel灯,并且由于Raspberry Pi只能在任何给定时间控制一个灯,所以我决定我只能得到一个微控制器来执行此操作,特别是Adafruit Itsybitsy M4 Express,只需通过USB连接两者以控制它们。我可以使用四义性的词,将数据发送给微控制器。但是,在RPI脚本发送数据8次之后,它停止工作,我必须重新加载脚本。添加剂,通过停止工作,我的意思是脚本被卡住了发送数据而永无止境。奇怪的部分是,如果我在脚本开始运行后打开MU序列号,我可以:查看发送的数据,B:它永远不会停止。它已经超越了8期并继续前进。 RPI代码:
import serial
import time
from random import randint
a = time.time() #Unimportant, was looking to see how quickly Serial could be re-defined
try:
ser = serial.Serial(port='/dev/ttyACM1', baudrate=115200, write_timeout=0.05)
except:
ser = serial.Serial(port='/dev/ttyACM0', baudrate=115200, write_timeout=0.05)
print(time.time() - a)
EnterKey = "\x1A\r\n"
e = 0
while True:
e+=1
d = []
for number in range(0, 30):
d.append([randint(0, 255), randint(0, 255), randint(0, 255)])
d = ((str(d)) + EnterKey).encode()
ser.write(d)
time.sleep(1)
print(e)
微控制器代码:
import board
import supervisor
import neopixel
import time
a = neopixel.NeoPixel(board.D5, 30, auto_write=False)
supervisor.diable_autoreload()
while True:
b = input("automated")
RST = []
c = ""
R3T = []
started = False
for value in b:
if started == True:
if value == '[':
started2 = True
ending = False
elif value == ']':
if ending == True:
started=False
else:
RST.append(int(c))
c = ""
ending = True
started2 = False
R3T.append(RST)
RST = []
elif started2 == True:
if value.isdigit():
c += value
elif value == ",":
RST.append(int(c))
c = ""
elif value == '[':
started = True
for value in range(0, 30):
a[value] = R3T[value]
a.show()
print(a)
我尝试懒惰,只是在写入超时后重新定义串行对象,但这不起作用。 (ERRNO 16]设备或资源忙)。然后,我四处寻找Raspberry Pi设置,看看是否有任何妨碍我的路,但什么也没发现。我最终放弃了,来到这里。如果您有任何想法,请告诉我!
I am trying to control some NeoPixel lights, and because the Raspberry Pi can only control one light at any given time, I decided I would just get a microcontroller to do it, specifically the Adafruit ItsyBitsy M4 Express, and just send serial data through the USB connecting the two to control them. I got that working, using PySerial to send data to the microcontroller. However, after the RPi script sends data 8 times, it stops working and I have to reload the script. Additonally, by stop working, I mean that the script gets stuck sending data and never ends. The strange part is that if I open the MU serial after my script has started running, I can A: see the data being sent in, and B: it never stops. It goes past the 8 issue and keeps going.
RPi Code:
import serial
import time
from random import randint
a = time.time() #Unimportant, was looking to see how quickly Serial could be re-defined
try:
ser = serial.Serial(port='/dev/ttyACM1', baudrate=115200, write_timeout=0.05)
except:
ser = serial.Serial(port='/dev/ttyACM0', baudrate=115200, write_timeout=0.05)
print(time.time() - a)
EnterKey = "\x1A\r\n"
e = 0
while True:
e+=1
d = []
for number in range(0, 30):
d.append([randint(0, 255), randint(0, 255), randint(0, 255)])
d = ((str(d)) + EnterKey).encode()
ser.write(d)
time.sleep(1)
print(e)
Microcontroller code:
import board
import supervisor
import neopixel
import time
a = neopixel.NeoPixel(board.D5, 30, auto_write=False)
supervisor.diable_autoreload()
while True:
b = input("automated")
RST = []
c = ""
R3T = []
started = False
for value in b:
if started == True:
if value == '[':
started2 = True
ending = False
elif value == ']':
if ending == True:
started=False
else:
RST.append(int(c))
c = ""
ending = True
started2 = False
R3T.append(RST)
RST = []
elif started2 == True:
if value.isdigit():
c += value
elif value == ",":
RST.append(int(c))
c = ""
elif value == '[':
started = True
for value in range(0, 30):
a[value] = R3T[value]
a.show()
print(a)
I tried being lazy and just re-defining the serial object after a write timeout, but that does not work. (Errno 16] Device or resource busy). I then went around looking for Raspberry Pi settings seeing if anything was getting in my way, but found nothing. I ultimately gave up and came here. If you have any ideas, please tell me!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论