1、Here is the Pin mapping diagram
2、Those pins are available as attributes on the module : microbit.pin0 - microbit.pin20.
Pin 0, Pin 1, Pin 2 are used to control the servo,
Test with the following code:
from microbit import *
while True:
if pin0.read_digital():
display.show(Image.HAPPY)
else:
display.show(Image.SAD)
This will show different pic when Pin 0 is applied with digital input.
3. The principle of servo
This servo can is controlled by 20ms PWM cycles, 0.5-2.5ms is period of HIGH corresponding to 0-180 degree rotary status, is. 2.5% to 12.5% ratio.
with 0-1023 value for write_analog value. That is 26 - 127.
0.5/20+1023=25.575
2.5/20+1023=127.875
4. Use of Radio
Since there BLE are not supported by Micropython in MicroBit for larger stack, Radio is proposed for wireless control.
First radio shall be imported and radio.on() is called , the radio.receive() can trace message sent by mobile APP with text message sent to control.
5. Proposed codes
# Radio controlled servo
import radio
from microbit import *
# Set start parameters and start Radio
display.scroll('Hello, Motors!')
sleep(2000)
radio.on()
set_analog_period(200)
angleAstep=0
angleBstep=0
angleA =0
angleD =0
display.scroll('Ready')
while(True):
incoming = radio.receive()
if incoming == 'up1':
angleAstep= 1
elif incoming == 'up2':
angleBstep= 1
elif incoming == 'down1':
angleAstep=-1
elif incoming == 'down2':
angleBstep= -1
'''
Move servo according to direction of angleAstep and angleBstep,
with value +1 or -1,
the data reset to 0 after each move
'''
if (angleA>26 and angleA < 127):
pin0.write_analog(angleA)
angleA +=5*angelAstep
sleep(200)
if (angleB>26 and angleB < 127):
pin1.write_analog(angleB)
angleB +=5*angelBstep
sleep(200)
angleAstep=0
angleBstep=0
#Coding on Python editor
#With referrence to Radio — BBC micro:bit MicroPython 0.0.1 documentation
6. Pin0 and pin1 are output pins for PWM control with servo. It can move up and down and ready for cotton button arrow to fly. For this servo, 5V power shall be needed. Therefore, extra power pack conntected with Vcc and GND to drive the servo.

Top Comments