0

I have code for sending analog data from a microbit that should print it out in the shell in Python. I've done this exact code before using an internal microbit sensor (light sensor) but now I'm using an external sensor that reads from the microbit's PIN1 and the code isn't working. Any fixes? The COMS port prints to the screen but the gathered data does not.

import serial.tools.list_ports as myPorts
for port in myPorts.comports():
    print(port) #finding the COMS port I'm connected to (8)
    myComm = port [0]
    
myMB = serial.Serial()
myMB.baudrate = 115200
myMB.port = myComm
myMB.open()

while True:
    dataMB= str(myMB.readline())[2:-5].replace(" ","") #removing spaces and "b'" and "\\r\\n"
    print(dataMB) #show data

And here's the microbit serial connection when Moisture = analog read PIN1 enter image description hereenter image description here

Lucia
  • 31
  • 1
  • 12
  • @ukBaz I have fixed this problem, but thank you for your input. The issue was conflicting while True loops in the python and the microbit. I have changed the microbit code so that this is no loner an issue – Lucia Jan 27 '22 at 13:44

1 Answers1

0

I have fixed this problem. The issue was conflicting while True loops in the microbit code and the python code. I have changed the microbit code so that there is now output in the python shell, as intended

Lucia
  • 31
  • 1
  • 12