Description:
1.The issue only happens when I open too many Arduino ports at the same time.
2.The mouse and keyboard did not respond, but the program keeps running.
3.Once I unplug and plug the USB hub, the issue is resolved.
4.At first, I thought this is related to hardware or kernel because I have two Ubuntu machines, running on Intel’s CPU, and they do not have this problem.
5.However, after some googling, I noticed that the serial communication is blocking, and so one needs to use multiprocessing or thread under certain situation.
6.Anyway, I am not sure whether the problem lies on Python, Pyserial, OS, or Pi itself. Please give me some suggestions.
Hardware:
1. Model: Raspberry Pi 4B (official power supply, fan, case, and SD card)
2. USB Hub: Sipolar - 10 Ports USB3.0 Splitter (with external power supply)
3. Arduino Nano (not the official one)
Software
1. OS: Raspberry Pi OS (64-bit) Bookworm (2023-12-05)
2. Python: 3.11.2
Setup:
Arduino Nano x 8 => USB Hub => Raspberry Pi
Code 1 - The code I used to test.Code 2 - This Code works for some reasons.
1.The issue only happens when I open too many Arduino ports at the same time.
2.The mouse and keyboard did not respond, but the program keeps running.
3.Once I unplug and plug the USB hub, the issue is resolved.
4.At first, I thought this is related to hardware or kernel because I have two Ubuntu machines, running on Intel’s CPU, and they do not have this problem.
5.However, after some googling, I noticed that the serial communication is blocking, and so one needs to use multiprocessing or thread under certain situation.
6.Anyway, I am not sure whether the problem lies on Python, Pyserial, OS, or Pi itself. Please give me some suggestions.
Hardware:
1. Model: Raspberry Pi 4B (official power supply, fan, case, and SD card)
2. USB Hub: Sipolar - 10 Ports USB3.0 Splitter (with external power supply)
3. Arduino Nano (not the official one)
Software
1. OS: Raspberry Pi OS (64-bit) Bookworm (2023-12-05)
2. Python: 3.11.2
Setup:
Arduino Nano x 8 => USB Hub => Raspberry Pi
Code 1 - The code I used to test.
Code:
Import pyserialImport time# InitializationArduino0 = serial.Serial(‘/dev/ttyUSB0’)Arduino1 = serial.Serial(‘/dev/ttyUSB1’)Arduino2 = serial.Serial(‘/dev/ttyUSB2’)Arduino3 = serial.Serial(‘/dev/ttyUSB3’)Arduino4 = serial.Serial(‘/dev/ttyUSB4’)Arduino5 = serial.Serial(‘/dev/ttyUSB5’)# Arduino6 = serial.Serial(‘/dev/ttyUSB6’) # Issue happens as I open the 7th Arduino.# Arduino7 = serial.Serial(‘/dev/ttyUSB7’)# Main loopwhile(1): print(“Test to see if I can move mouse.”) time.sleep(1)
Code:
Import pyserialImport time# InitializationArduino0 = serial.Serial(‘/dev/ttyUSB0’)Arduino0.close()Arduino1 = serial.Serial(‘/dev/ttyUSB1’)Arduino1.close()Arduino2 = serial.Serial(‘/dev/ttyUSB2’)Arduino2.close()Arduino3 = serial.Serial(‘/dev/ttyUSB3’)Arduino3.close()Arduino4 = serial.Serial(‘/dev/ttyUSB4’)Arduino4.close()Arduino5 = serial.Serial(‘/dev/ttyUSB5’)Arduino5.close()Arduino6 = serial.Serial(‘/dev/ttyUSB6’) Arduino6.close()Arduino7 = serial.Serial(‘/dev/ttyUSB7’)Arduino7.close()# Main loopwhile(1): Arduino0.open() Arduino1.open() Arduino2.open() Arduino3.open() time.sleep(1) Arduino0.close() Arduino1.close () Arduino2.close () Arduino3.close () time.sleep(1) print(“Test to see if I can move mouse.”) Arduino4.open() Arduino5.open() Arduino6.open() Arduino7.open() time.sleep(1) Arduino4.close () Arduino5.close () Arduino6.close () Arduino7.close () time.sleep(1)
Statistics: Posted by 2e8ee5eb — Sat Feb 03, 2024 2:48 am