Level 1

micro:bit

class bluezero.microbit.Microbit(device_addr, adapter_addr=None, **kwargs)

Class to simplify interacting with a micro:bit over Bluetooth Low Energy

accelerometer

Read the values of the accelerometer on the microbit

Returns:return a list in the order of x, y & z
address

Read the devices Bluetooth address

static available(adapter_address=None)

Generator to find already discovered micro:bit’s and return a tuple of their address and name

Parameters:adapter_address – Optional if you want o find devices on specific adapter
Returns:Microbit Object
bearing

Compass bearing in degrees from North.

Returns:degrees in integer
button_a

Read the state of button A on a micro:bit 3 button states are defined and represented by a simple numeric enumeration: 0 = not pressed, 1 = pressed, 2 = long press.

Returns:integer representing button value
button_b

Read the state of button B on a micro:bit 3 button states are defined and represented by a simple numeric enumeration: 0 = not pressed, 1 = pressed, 2 = long press.

Returns:integer representing button value
calibrate()

Request a calibration of the magnetometer

clear_display()

Clear the LED display on the microbit

connect()

Connect to the specified micro:bit for this instance

connected

Indicate whether the remote device is currently connected.

disconnect()

Disconnect from the micro:bit

magnetometer

Exposes magnetometer data. A magnetometer measures a magnetic field such as the earth’s magnetic field in 3 axes.

Returns:List of x, y & z value
name

Read the devices Bluetooth address

on_disconnect

Add callback for on_disconnect action

pin_values

Get the values of all the pins that are set as inputs

Returns:Dictionary (keys are pins)
pixels

Returns a list of 5 binary numbers. Each number represents a row from top to bottom

Returns:Example [0b01110, 0b01000, 0b10000, 0b10000, 0b01110]
quit_async()

Stops asynchronous mode

Returns:
run_async()

Puts the code into asynchronous mode

Returns:
scroll_delay

Specifies a millisecond delay to wait for in between showing each character on the display.

services_available()

Return a list of service names available on this micro:bit

set_pin(pin_number, pin_input, pin_analogue)

For a given pin, set the direction and type for the microbit pin.

Parameters:
  • pin_number – Pin number of the microbit
  • pin_input – False for output, True for input
  • pin_analogue – False for digital, True for analogue
Returns:

subscribe_button_a(user_callback)

Execute user_callback on Button A being press on micro:bit

Parameters:user_callback – User callback method receiving the button state
Returns:
subscribe_button_b(user_callback)

Execute user_callback on Button B being press on micro:bit

Parameters:user_callback – User callback method receiving the button state
Returns:
subscribe_calibrate(user_callback)

Execute user_callback when calibration of magnetometer is complete

Parameters:user_callback
Returns:
subscribe_pins(user_callback)

Execute user_callback on input pin being changed on micro:bit

Parameters:user_callback
Returns:
subscribe_uart(user_callback)

Execute user_callback on data being received on UART service

Parameters:user_callback
Returns:
temperature

Temperature from sensors in micro:bit processors

Returns:Integer of temperature in Celsius
text

Specify text to be displayed. Limit of 20 characters. The content will be restricted to that number of characters.

Parameters:words
uart

Write string to micro:bit UART service. To read from UART, use

Returns:
class bluezero.microbit.MIpower(device_addr, adapter_addr=None, accelerometer_service=True, button_service=True, led_service=True, magnetometer_service=False, pin_service=False, temperature_service=True)

Initialization of an instance of a remote micro:bit with a MI:power board attached

Parameters:
  • device_addr – Connect to a BLE device with this address
  • adapter_addr – Use the adapter with this address
beep(duration=1)

If a buzzer is attached to pin 0 then a beep will be played

Parameters:duration – time in seconds
class bluezero.microbit.BitBot(device_addr, adapter_addr=None, accelerometer_service=False, button_service=True, led_service=True, magnetometer_service=False, pin_service=True, temperature_service=False)

Class to simplify interacting with a microbit attached to a bit:bot over Bluetooth Low Energy The bit:bot is a micro:bit robot available from 4tronix.co.uk

buzzer_off()

Stop the buzzer

buzzer_on()

Play the buzzer

clean_up()

Stop bitbot and turn buzzer is off

Returns:
connect()

Connect to the bit:bot

connected

Returns true if bit:bot is connected

disconnect()

Disconnect from the bit:bot

drive(left=100, right=100)

Set the drive power of both wheels at same time

Parameters:
  • left – percentage of power (negative numbers are reverse)
  • right – percentage of power (negative numbers are reverse)
forward()

Spin both wheels forward

left_light_sensor

Get the value of the left light sensor

left_line_senor

Value ofthe left line sensor

Returns:False = No line True = Line
line_sensors

Get the value of both line sensors

Returns:(left, right)
reverse()

Spin both wheels backwards

right_light_sensor

Get the value of the left light sensor

right_line_sensor

Value of the right line sensor

Returns:False = No line True = Line
spin_left()

Spin left wheel forward and right wheel backwards so bit:bot spins

spin_right()

Spin right wheel forward and left wheel backwards so bit:bot spins

stop()

Stop both wheels of the bit:bot

Eddystone

class bluezero.eddystone_beacon.EddystoneURL(url, tx_power=8)

Create and start broadcasting a Eddystone URL beacon

The Eddystone-URL frame broadcasts a URL using a compressed encoding format in order to fit more within the limited advertisement packet. :Example:

>>> from bluezero import eddystone_beacon
>>> eddystone_beacon.EddystoneURL('https://github.com/ukBaz')
Parameters:
  • url – String containing URL e.g. (‘http://camjam.me’)
  • tx_power – Value of Tx Power of advertisement (Not implemented)