Difference between one analog input and two analog inputs

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
laag2
Posts: 1
Joined: Sun Sep 05, 2021 3:20 pm

Difference between one analog input and two analog inputs

Post by laag2 » Sun Sep 05, 2021 5:40 pm

Hello,
i'm testing the analog pins of my micro:bit with two light sensors. When I read one pin individual, I get different values depending on the light detected by the sensor. When I read both pins, I get a "fixed" value.

Code Example 1:
Hardware: One Light Sensor. Connected to Pin1 and Ground
Software: Reading only Pin1
Result: Success

Code: Select all

from microbit import *

while True:
    pin1.write_digital(1)
    sleep(10)
    raw = pin1.read_analog()
    print("Raw 1: " + str(raw))
    print("#########################")
Output Values between ~400 and ~460, depending on lightsource.

Code Example 2:
Hardware: One Light Sensor. Connected to Pin0 and Ground
Software: Reading only Pin0
Result: Success

Code: Select all

from microbit import *

while True:
    pin0.write_digital(1)
    sleep(10)
    raw = pin0.read_analog()
    print("Raw 0: " + str(raw))
    print("#########################")
Output Values between ~410 and ~460, depending on lightsource.

Code Example 3:
Hardware: Two Light Sensors. One Connected to Pin0 and Ground. the other to Pin1 and Ground.
Software: Reading Pin0 and Pin1
Result: Failure. Fixed reading of ~800

Code: Select all

from microbit import *

while True:
    pin0.write_digital(1)
    pin1.write_digital(1)
    sleep(10)
    raw0 = pin0.read_analog()
    raw1 = pin1.read_analog()
    print("Raw 0: " + str(raw0))
    print("Raw 1: " + str(raw1))
    print("#########################")
Output Values ~790 on Pin0 and ~810 on Pin1 not depending on light source.

On a test with an arduino it worked...so what is the problem? Is there a fix?

Thanks!

jim200
Posts: 4
Joined: Tue Jul 13, 2021 10:59 pm

Re: Difference between one analog input and two analog inputs

Post by jim200 » Fri Sep 10, 2021 9:16 pm

It’s not exactly very scientific… which Arduino model are you referring to for a start? You’d also needed to start looking at the data sheets for the sensors etc to understand if the Microbit can handle such a setup versus the Arduino etc…

Things don’t happen in isolation, multiple components drawing on the same source of current can impact each other. Even the timing and sequence in which things are do can have an impact on the outcome when you are working with limited current.

Maybe try asking on an electronics forum there is more likely to be people knowledge in power consumption etc.

Post Reply