Description
If a script calls read_analog() for more than one pin in a loop, incorrect measurements are returned periodically. The errors were evident in micro:bit V2, but not micro:bit V1. Micro:bit Education Foundation Tech Support noticed an issue that might be related in lancaster-university
/ codal-microbit-v2 / Erratic output when reading multiple analog pins #81.
Edits: Initial post had swapped pin labels in the print statements. Corrected and updated within 2 hr.
Test Script
# read_analog_issue_test
# connect pin0 to 3.3 V and pin2 to 0 GND.
from microbit import *
while True:
v0 = pin0.read_analog()
v2 = pin2.read_analog()
print("v0 =", v0, "v2 =", v2)
if v0 < 1010:
print("pin0 measurement error")
sleep(2000)
if v2 > 10:
print("pin2 measurement error")
sleep(2000)
sleep(100)
Samples from Terminal Output
v0 = 1020 v2 = 0
v0 = 1022 v2 = 0
v0 = 0 v2 = 0
pin0 measurement error
v0 = 1021 v2 = 1
v0 = 1020 v2 = 1
...
v0 = 1020 v2 = 0
v0 = 1021 v2 = 1021
pin2 measurement error
v0 = 1020 v2 = 1
v0 = 1021 v2 = 1
v0 = 1021 v2 = 0
Full Speed Test
# read_analog_issue_test_full_speed
# connect pin0 to 3.3 V and pin2 to 0 GND.
from microbit import *
while True:
v0 = pin0.read_analog()
v2 = pin2.read_analog()
if v0 < 1010:
print("v0 =", v0, "v2 =", v2)
print("pin0 measurement error")
sleep(2000)
if v2 > 10:
print("v0 =", v0, "v2 =", v2)
print("pin2 measurement error")
sleep(2000)
#sleep(100)
Samples from Terminal Output
v0 = 1 v2 = 0
pin0 measurement error
v0 = 1019 v2 = 1021
pin2 measurement error
v0 = 1021 v2 = 1019
pin2 measurement error
v0 = 1022 v2 = 1020