02 Microbit talks to PC via Serial and Python

preview_player
Показать описание
Have your Microbit talk to your PC/Laptop/Raspberry Pi etc. using a serial connection over USB. Coded using Python.

Рекомендации по теме
Комментарии
Автор

Thanks very much for this mate, going to convert it now to do accelerometer data, you’re a life saver 👍

deanpaul
Автор

Thanks Pauric, these videos are very useful. Very clear and easy to follow. Thanks for taking the time to create them.

christinecarew
Автор

Pauric, I'm getting garbled data from the microbit in both Thonny and Teraterm (terminal program). This is happening on two different PCs. The serial monitor in Makecode works fine.

paulmulvey
Автор

# Import Libraries
import serial
import time

# Set up the Serial connection to capture the Microbit communications
ser = serial.Serial()
ser.baudrate = 115200
ser.port = "COM9"
ser.open()

# Loop forever
while True:

# Read in a line from the Microbit, store it in variable 'microbitdata' as a string
microbitdata = str(ser.readline())

# Print the returned unique ID from Firebase on receipt of our data
print(microbitdata)

Error msg: SerialException: could not open port 'COM9': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)

error opening port, but I checked the port, it's correct

kmhooibg
Автор

is it almost the same that send from computer to microbit?

jacobstech
Автор

Using PuTTY (terminal emulator) in the PC, I am able to send strings and numbers from the Micro:bit )language = Makecode) and display them in the PC screen - but they all come out in one, long line. How can I send a CR or NL character (Carriage Return / New Line)

DownhillAllTheWay
Автор

Doing all exactly as you did it, same micro:bit code and java code. Copied from your GitHub, but got these error codes:

Traceback (most recent call last):
File "D:\Apps\Thonny\Project Files\Microbit input.py", line 9, in <module>
ser.open ()
File "D:\Apps\Thonny\lib\site-packages\serial\serialwin32.py", line 62, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
could not open port 'COM13': FileNotFoundError(2, 'Systemet finner ikke angitt fil.', None, 2)



Anyone who now what I can do?

alfredundheim
Автор

[Running] python -u
Traceback (most recent call last):
File programs\microbitsender\microbutton.py", line 9, in <module>
ser.open()
File "C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\serial\serialwin32.py", line 64, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
could not open port 'COM13': FileNotFoundError(2, 'El sistema no puede encontrar el archivo especificado.', None, 2)

[Done] exited with code=1 in 0.145 seconds

littlepiggames
welcome to shbcf.ru