Why ever would you want to do this?Siriushardware wrote: ↑Fri Nov 03, 2017 6:18 pm...
In theory, I should be able to make an INPUT generate a slow square wave output by going around in a loop periodically switching it from pulldown to pullup mode and back with a suitable pause in between each change.
Dynamically assign pin numbers for
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Dynamically assign pin numbers for
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
-
- Posts: 20
- Joined: Wed Nov 01, 2017 8:00 pm
Re: Dynamically assign pin numbers for
To check that the pullup resistor settings are working.
(An effect, easily observable with a scope or multimeter, which proves that set_pull is working).
If I really wanted to output a signal of any sort, then of course I would use the pin in output mode.
(An effect, easily observable with a scope or multimeter, which proves that set_pull is working).
If I really wanted to output a signal of any sort, then of course I would use the pin in output mode.
Last edited by Siriushardware on Tue Nov 07, 2017 12:11 am, edited 1 time in total.
Re: Dynamically assign pin numbers for
Do you actually have a micro:bit with MicroPython on it? Because if you do, it's pretty trivial to try things and figure out how it all works. It's not rocket surgery, and as I said, when you make a pull request, it will be reviewed by the people who wrote this code in the first place and if you got anything wrong, they will point it out.
Of course if you just don't want to do it, then that's fine too. Perhaps the next person who stumbles upon this will.
Of course if you just don't want to do it, then that's fine too. Perhaps the next person who stumbles upon this will.
-
- Posts: 20
- Joined: Wed Nov 01, 2017 8:00 pm
Re: Dynamically assign pin numbers for
Of course, and I believe much of what I've said previously indicates a willingness to try things but it has recently been difficult to get me, the Micro:Bit and the computer which has Mu on it all in the same place at the same time. I'm currently not at home: I'll report back when I have had a chance to sit down and try things out.
-
- Posts: 20
- Joined: Wed Nov 01, 2017 8:00 pm
Re: Dynamically assign pin numbers for
OK gentlemen: I have now had a chance to play around and I have to come to the conclusion that 'set_pull' is not implemented in the version of MicroPython which is incorporated into the version of 'Mu' that I am currently running.
If I try out this little bit of code
I get this result (in REPL, the built in terminal interface in Mu)
If I ask REPL for information on pin0 using 'dir (pin0)' the result is:
OK, so pin0 happens to be one of the pins which can be used as a 'touch sensitive' input thanks to it having a very high (in the megaohms range) pullup resistor. Let's try a more 'normal' I/O pin, pin 12.
This results in:
Enquiring about attributes for pin12 yields the following:
No sign of set_pull in this list either. The version of 'Mu' I'm using came from this source:-
https://codewith.mu/
As you can see from the MicroPython ident in one of the above segments the version embedded in my current version of Mu is quite an old version. I'd be grateful if anyone can point me to the most current version (of Mu), if there is a later 'stable' version than this.
This discussion (around June 2016) seems to suggest that at that time, set_pull was not implemented. It also makes a reasonable case for making the default behaviour pull-down (basically, a vanilla user will, quite reasonably, expect to see 'no input' if nothing is connected to the input).
https://github.com/bbcmicrobit/micropython/issues/288
If I try out this little bit of code
Code: Select all
from microbit import *
#Initial read from Pin0 to switch on digital input mode
x=pin0.read_digital()
# Try to set pin0 PULL_UP mode (default is PULL_DOWN)
pin0.set_pull(PULL_UP)
Code: Select all
>>> Traceback (most recent call last):
File "__main__", line 5, in <module>
AttributeError: 'MicroBitTouchPin' object has no attribute 'set_pull'
MicroPython v1.7-9-gbe020eb on 2016-04-18; micro:bit with nRF51822
Code: Select all
dir(pin0)
['write_digital', 'read_digital', 'write_analog', 'read_analog', 'set_analog_period', 'set_analog_period_microseconds', 'is_touched']
Code: Select all
from microbit import *
x=pin12.read_digital()
pin12.set_pull(PULL_UP)
Code: Select all
Traceback (most recent call last):
File "__main__", line 5, in <module>
AttributeError: 'MicroBitDigitalPin' object has no attribute 'set_pull'
Code: Select all
>>> dir(pin12)
['write_digital', 'read_digital', 'write_analog', 'set_analog_period', 'set_analog_period_microseconds', 'get_analog_period_microseconds']
https://codewith.mu/
As you can see from the MicroPython ident in one of the above segments the version embedded in my current version of Mu is quite an old version. I'd be grateful if anyone can point me to the most current version (of Mu), if there is a later 'stable' version than this.
This discussion (around June 2016) seems to suggest that at that time, set_pull was not implemented. It also makes a reasonable case for making the default behaviour pull-down (basically, a vanilla user will, quite reasonably, expect to see 'no input' if nothing is connected to the input).
https://github.com/bbcmicrobit/micropython/issues/288