Problem with micro:bit LED's

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
Barrowman
Posts: 5
Joined: Wed Aug 03, 2016 1:35 pm

Problem with micro:bit LED's

Post by Barrowman » Wed Aug 03, 2016 2:23 pm

Hi all,
I got my micro:bit a few weeks ago and have been teaching 2 of my grand daughters with the block editor but yesterday I thought it was time to move on to python. I have done some python on my Linux box so it hasn't been too hard using it on the micro:bit.
However I have hit a snag. My code is here:
[code]from microbit import *
pos = 0
thestring = "This is a demo of input - output pin use"
mystring = thestring[pos:]
# Add 4 spaces to the start of the string
mystring = " " + mystring
q = len(mystring)

while True:
if pin0.read_digital():
for j in range(q):
display.scroll(mystring[j])
sleep(200)[/code]
This works without any problems.
However if I change pin0 to pin1 or another one ( I have tried 1, 2, 3, 4, and 7 )
I always get 2 or 3 LED's lighting up faintly. A different set for each number.The code does run but it is only if i read pin0 that all the LED's are off until I raise the pin to 3.3 volts.
I don't think it's anything to do with the code but could you just check it over please?
Last edited by Barrowman on Sun Aug 07, 2016 9:07 pm, edited 3 times in total.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Problem with micro:bit LED's

Post by deshipu » Wed Aug 03, 2016 3:38 pm

This definitely shouldn't happen. Not only pins 0, 1 and 2 are not connected to the display (pins 3, 4, 6, 7, 9 and 10 are, see http://microbit-micropython.readthedocs ... t/pin.html), but also you are using them in input mode, which should be high-impedance (although I seem to remember some mentions of enabling the pullup reistors on the by default).

I would check the micro:bit for anything stuck on it and causing a short. Also, make sure you are not putting the micro:bit on a metal surface (such as an aluminium surface of a macbook)...

Barrowman
Posts: 5
Joined: Wed Aug 03, 2016 1:35 pm

Re: Problem with micro:bit LED's

Post by Barrowman » Wed Aug 03, 2016 7:34 pm

Okay, thanks for the reply. Truth is electronics has been a hobby of mine for over 60 years. So I decided to check the adaptor. As my eyesight isn't what it was I decided to purchase a ready built one. I unplugged it from the MB ( micro:bit ) and reconnected it. Now I find that 0, 1,and 2 are fine.
Let's assume for columns of LED's we count left to right and for rows bottom to top. so for the LEDs which light I will use;
Pin,Column,Row
I get the following:
( 3,1,5 ) ( 3,3,1) ( 3,5,3 ) and the loop runs without raising pin to 3.3 volts
( 4,1,3 ) ( 4,3,5 ) ( 4,5,1 ) and the loop runs without raising pin to 3.3 volts
5 is different again. As soon as the file is downloaded and my PC displays the MB files ( Linux mint 17.3 ) the loop runs.but no dim LED's
( 6,2,3 ) ( 6,4,3 ) and the loop runs without raising pin to 3.3 volts
( 7,1,2 ) ( 7,5,4 ) and the loop runs without raising pin to 3.3 volts
8 normal response
( 9,2,1 ) ( 9,2,2 ) loop runs without raising pin to 3.3 volts
( 10, 1,1 ) ( 10, 3,3 ) ( 10, 5,5 ) loop runs without raising pin to 3.3 volts
11 same as 5
12 works correctly
16 works correctly
I decided not to go any further with these tests.
I guess there are at least 6 possibilities
1/ faulty MB
2/ faulty interface board
3/ I need pulldown resistors on all I/O pins as they are probably all floating
4/ I could enable pullups and reverse the logic test and see if that works.
5/ It could be something to do with interference from the computer.
6/ It could be something to do with pin assignments within the MB

As far as 6/ is concerned I do see some pattern emerging:
0, 1, 2, 8, 12 and 16 are touch or just digital
5 and 11 are connected to Button A and B
3, 4, 6, 7, 9 and 10 are connected to rows or columns
All in each group respond in the same way as the rest in the group.
Does this mean there is some problem with MB or the interface board or micropython on this board?
I will be getting 3 more MB's and 3 interfaces in the next few days so i can see how the different combinations work.
I can try to eliminate some of the other problems such as running off a battery pack.
Just tried it with battery pack and pin 6 does the same :cry:

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Problem with micro:bit LED's

Post by deshipu » Wed Aug 03, 2016 9:33 pm

If you look closely at the picture to which I linked, you will see that some of the pins are connected to the display's rows and/or columns, so if you want to use them, I'm afraid you will have to switch the display off (with microbit.display.off()), otherwise the display-handling routines will keep switching the pins, and you will read pretty much random stuff, depending on what the display shows.

I guess I was wrong with the high-impedance mode, they seems to have pull downs enabled by default. Sorry about that.

Barrowman
Posts: 5
Joined: Wed Aug 03, 2016 1:35 pm

Re: Problem with micro:bit LED's

Post by Barrowman » Wed Aug 03, 2016 10:20 pm

Yes, I did say that some of the pins are connected to row or column.
What concerns me is that if you look at my tests it's not just those pins which do not work as simple digital I/O.
So actually there are only a few which can be used reliably as digital I/O.
I believe that means only Pins 0, 1, 2, 8, 12 and 16 can be used for such projects.
That's probably okay as long as you are aware of it.
My code in my first post is just really the skeleton of what I intend to create so when I get the other boards I will see if I can
do what I have in mind.
Thanks for your input it's helped me to focus on the problem and I now feel I know how to continue.
Last edited by Barrowman on Sun Aug 07, 2016 9:20 pm, edited 1 time in total.

Barrowman
Posts: 5
Joined: Wed Aug 03, 2016 1:35 pm

Re: Problem with micro:bit LED's

Post by Barrowman » Sun Aug 07, 2016 8:45 pm

Well I have now partially succeeded in getting my project to work.
i wanted to investigate the possibility of several micro:bits working together. At the same time I wanted to do something which would be useful in teaching my granddaughters.
So what I have is 4 MB's linked via I/O pin 1. One is the master and signals the other 3 to starting displaying letters in a common string.
The string scrolls from right to left. I haven't got the timing absolutely right just yet but I am hoping to do so reasonable soon.
So here is the code for the master ( the left hand one of the 4 )

Code: Select all

from microbit import *
pos = 1
numbits = 4
front=" "
mystring = "This is a demo of multiple micro:bits co-operating"
# pos is 1 for master. For others it is their position in the physical lineup
# This ensures that each microbit displays the correct letters so it all reads correctly

# Find how many characters there are in the string and make sure it is a multiple
#  of 4 so add the needed number 
# Calculation split up so children can follow it 
q = len(mystring)
r = q/4
s = int(r)
t =int((r - s)*4)
u=4-t
for v in range(u-1):
    mystring += " "
# Now add the number of blanks at the start of the string 
# depending on ( num of micro:bits - pos )
oldstring = mystring
mystring = "   " + oldstring # add 3 spaces as its the master
q = len(mystring)
while True:
    if button_a.is_pressed():
        pin1.write_digital(1)
        for j in range(q):
            display.show(mystring[j])
            sleep(800)
    pin1.write_digital(0)
And this is the code for slave3 ( the right hand one )

Code: Select all

from microbit import *
pos = 4
numbits = 4
mystring = "This is a demo of multiple micro:bits co-operating"
# pos is 1 for master. For others it is their position in the physical lineup
# This ensures that each microbit displays the correct letters so it all reads correctly
# Find how many characters there are in the string and make sure it is a multiple
#  of 4 so add the needed number 
# Calculation split up so children can follow it 
q = len(mystring)
r = q/4
s = int(r)
t =int((r - s)*4)
u=4-t
for v in range(u-1):
    mystring += " "
# then add 4 spaces so display ends up blank
mystring +="    "
# Now add the number of blanks at the start of the string 
# depending on ( num of micro:bits - pos )
oldstring = mystring
mystring = "" + oldstring   #  as this is the right hand slave no spaces are added at the start just kept syntax the same as the others
q = len(mystring)-1

while True:
    if pin1.read_digital():
        for j in range(pos-1:q):
            display.show(mystring[j])
            sleep(800)  # adjust to get reasonable display speed
        sleep(500)  # used to make sure that master has taken pin 1 low before
                        # a new iteration of the while loop 
The master displays 3 spaces before displaying the string, the 1st slave displays 2 and so on.
I need to get the sleep times adjusted because weird things can happen such as 2 of the slaves restarting because the master hasn't yet got pin 1 set low.
I don't know how much use this will be but I visualise possibly sending the string to be used from the master so I don't have to edit and download the script for each slave. Of course I expect most of you will think this is all crude stuff but I am learning as I go along.
However I really would be interested in your comments and any suggestions for improvements if you wish to make them.

Post Reply