GPIO pin dafault settings

Questions and discussion about running MicroPython on a micro:bit board.
Target audience: MicroPython users with a micro:bit.
Post Reply
RobD
Posts: 2
Joined: Wed Jun 10, 2020 12:35 pm

GPIO pin dafault settings

Post by RobD » Wed Jun 10, 2020 1:00 pm

Hi,
I'm a newbie to the Micro:bit board, and wondered if anyone might be able to assist with a question about changing the default behaviour of the interface edge connector pins please.

Is it possible to change the default use/behaviour of the edge connector pins eg disabling the i2c mode in order to use the associated pins as GPIO or similarly for pin12 enabling GPIO rather than accessibility?

Can the default direction of the GPIOs be changed as suggested in the datasheet ie inputs to outputs and vice versa.

I am aware that the pins used for the led matrix can have the display disabled, but would rather keep the display enabled and use other interface pins for general purpose in/out.

Many thanks for any advice.

lujo
Posts: 24
Joined: Sat May 11, 2019 2:30 pm

Re: GPIO pin dafault settings

Post by lujo » Thu Jun 11, 2020 8:45 am

Hi,

9 pins for GPIO input/output, NO_PULL, PULL_UP, PULL_DOWN,
8 pins control display and buttons (display.on(), display.off()),
2 pins for I2C (accelerometer and compass).

If 9 pins won't do, get a second micro:bit and use the radio
to control the first, get its data and show its messages.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: GPIO pin dafault settings

Post by jimmo » Thu Jun 11, 2020 8:47 am

Hi,
RobD wrote:
Wed Jun 10, 2020 1:00 pm
Is it possible to change the default use/behaviour of the edge connector pins eg disabling the i2c mode in order to use the associated pins as GPIO or similarly for pin12 enabling GPIO rather than accessibility?
Yes, this should "just work" -- you can use any of the pins on the edge connector as GPIO. It's only if you choose to initialise the I2C or SPI do they become set to that mode.
RobD wrote:
Wed Jun 10, 2020 1:00 pm
Can the default direction of the GPIOs be changed as suggested in the datasheet ie inputs to outputs and vice versa.
If you use write_digital() then it will set the pin to output mode automatically. Similarly for read_digital and read_analog, which will set the pin to input.
You can also set the pull resistors -- see https://microbit-micropython.readthedoc ... t/pin.html

RobD
Posts: 2
Joined: Wed Jun 10, 2020 12:35 pm

Re: GPIO pin dafault settings

Post by RobD » Sat Jun 13, 2020 4:11 pm

Hi, Lujo & Jimmo

Many thanks for your replies.

It was more a academic question as I had noticed that some of the pins can't be used for general purpose io. However having just whizzed through all the available pins and ran the write_digital line, all do work with the exception of the two button pins and the two i2c pins. I should have been more rigorous in testing before I posted my question

The i2c pins if using the repl function on the editor, indicates that the i2c is enabled. Similar error for the button A & B inputs.

I appreciate if something else is wired to the pins then using as gpio, would have to be cautious, I just wondered if the two modes could be disabled.

Using the radio option sounds interesting and I'll try that, however you are correct I don't need that many IOs.

Thanks again.

Post Reply