Level 1

micro:bit

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

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

accelerometer

Read the values of the accelerometer on the microbit :return: return a list in the order of x, y & z

bearing

Compass bearing in degrees from North. :return: 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. :return: 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. :return: 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. :return: List of x, y & z value

pin_values

Get the values of all the pins that are set as outputs :return: Dictionary (keys are pins)

pixels

Returns a list of 5 binary numbers. Each number represents a row from top to bottom :return: Example [0b01110, 0b01000, 0b10000, 0b10000, 0b01110]

quit_async()

Stops asynchronose mode :return:

run_async()

Puts the code into asynchronous mode :return:

scroll_delay

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

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 :param user_callback: :return:

subscribe_button_b(user_callback)

Execute user_callback on Button B being press on micro:bit :param user_callback: :return:

subscribe_calibrate(user_callback)

Execute user_callback when calibration of magnetometer is complete :param user_callback: :return:

subscribe_pins(user_callback)

Execute user_callback on input pin being changed on micro:bit :param user_callback: :return:

temperature

Temperature from sensors in micro:bit processors :return: 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. :param words:

class bluezero.microbit.MIpower(device_addr, adapter_addr=None)
beep(duration=1)

If a buzzer is attached to pin 0 then a beep will be played :param duration: time in seconds

class bluezero.microbit.BitBot(device_addr, adapter_addr=None)

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 :return:

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 :param left: percentage of power (negative numbers are reverse) :param 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 :return: False = No line True = Line

line_sensors

Get the value of both line sensors :return: (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 :return: 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)