I've just installed Mu 1.0.0.beta.15. (Thank you for all the hard work.) I am using it to code the BBC micro:bit.
Have pullup and pulldown been included in pin?.read_digital() ? If so on which pins can they be used?
pullUP and pullDOWN with read_digital()
Re: pullUP and pullDOWN with read_digital()
See https://microbit-micropython.readthedoc ... -functions
I don't know if there are any limitations on the availability of set_pull depending on the pin identity.The pull mode for a pin is automatically configured when the pin changes to an input mode. Input modes are when you call read_analog / read_digital / is_touched. The default pull mode for these is, respectively, NO_PULL, PULL_DOWN, PULL_UP. Calling set_pull will configure the pin to be in read_digital mode with the given pull mode.
-
- Posts: 20
- Joined: Wed Nov 01, 2017 8:00 pm
Re: pullUP and pullDOWN with read_digital()
I had an earlier thread partly dealing with this, during which I found that you can query all the available properties for any given pin using repl.
For example, if I query pin 0 by entering dir(pin0) <enter> then I get this result for Pin0:
You can see that my earlier version of Mu did NOT support the pull up / pull down properties.
It would be interesting to hear if the same query on your newer setup returns a longer list which includes the pull up / pull down properties.
For example, if I query pin 0 by entering dir(pin0) <enter> then I get this result for Pin0:
Code: Select all
dir(pin0)
['write_digital', 'read_digital', 'write_analog', 'read_analog', 'set_analog_period', 'set_analog_period_microseconds', 'is_touched']
It would be interesting to hear if the same query on your newer setup returns a longer list which includes the pull up / pull down properties.
Re: pullUP and pullDOWN with read_digital()
I've got the answer from Carlos Pereira Atencio at micro:bit support :
(support.microbit.org)
Thanks for contacting micro:bit. I have tested Mu beta 15 and the set_pull function is present in this version of MicroPython. From the REPL:
MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit with nRF51822
Type "help()" for more information.
>>> import os
>>> os.uname()
(sysname='microbit', nodename='microbit', release='1.0', version='micro:bit v1.0-c8c4db8 on 2017-9-27; MicroPython v1.9.2-34-gd64154c73 on 2017-09-01', machine='micro:bit with nRF51822')
>>> from microbit import pin0
>>> dir(pin0)
['write_digital', 'read_digital', 'write_analog', 'read_analog', 'set_analog_period', 'set_analog_period_microseconds', 'is_touched', 'PULL_UP', 'PULL_DOWN', 'NO_PULL', 'get_pull', 'set_pull', 'get_mode']
>>> pin0.set_pull(pin0.PULL_UP)
>>>
I've tested both PULL_UP and PULL_DOWN on all pins. Works properly, as expected on all but pins 5 and 11, the button pins A and B.
Error message says they are in BUTTON MODE.
You need to insert display.off() to take control of the pins used for controlling the display
(support.microbit.org)
Thanks for contacting micro:bit. I have tested Mu beta 15 and the set_pull function is present in this version of MicroPython. From the REPL:
MicroPython v1.9.2-34-gd64154c73 on 2017-09-01; micro:bit with nRF51822
Type "help()" for more information.
>>> import os
>>> os.uname()
(sysname='microbit', nodename='microbit', release='1.0', version='micro:bit v1.0-c8c4db8 on 2017-9-27; MicroPython v1.9.2-34-gd64154c73 on 2017-09-01', machine='micro:bit with nRF51822')
>>> from microbit import pin0
>>> dir(pin0)
['write_digital', 'read_digital', 'write_analog', 'read_analog', 'set_analog_period', 'set_analog_period_microseconds', 'is_touched', 'PULL_UP', 'PULL_DOWN', 'NO_PULL', 'get_pull', 'set_pull', 'get_mode']
>>> pin0.set_pull(pin0.PULL_UP)
>>>
I've tested both PULL_UP and PULL_DOWN on all pins. Works properly, as expected on all but pins 5 and 11, the button pins A and B.
Error message says they are in BUTTON MODE.
You need to insert display.off() to take control of the pins used for controlling the display
-
- Posts: 20
- Joined: Wed Nov 01, 2017 8:00 pm
Re: pullUP and pullDOWN with read_digital()
Having finally installed Mu 1.0 with its support for PULL_UP and PULL_DOWN modes on the Micro:Bit, I can confirm that this slightly unorthodox bit of code produces a slow squarewave output on Pin 1 when pin 1 is programmed as an INPUT.
Not that you would ever intentionally use an input to generate an output waveform, but this proves that the PULL_UP and PULL_DOWN modes are working by alternately pulling the input high and low.
Code: Select all
from microbit import *
x = pin1.read_digital()
while(1):
pin1.set_pull(pin1.PULL_UP)
sleep(250)
pin1.set_pull(pin1.PULL_DOWN)
sleep(250)