pyb — functions related to the board

The pyb module contains specific functions related to the board.

Miscellaneous functions


Return True if USB is connected as a serial device, False otherwise.


This function is deprecated. Use pyb.USB_VCP().isconnected() instead.

pyb.hid((buttons, x, y, z))

Takes a 4-tuple (or list) and sends it to the USB host (the PC) to signal a HID mouse-motion event.


This function is deprecated. Use pyb.USB_HID().send(...) instead.[dump_alloc_table])

Print out lots of information about the board.


Set the filename of the main script to run after is finished. If this function is not called then the default file will be executed.

It only makes sense to call this function from within

pyb.mount(device, mountpoint, *, readonly=False, mkfs=False)

Mount a block device and make it available as part of the filesystem. device must be an object that provides the block protocol:

  • readblocks(self, blocknum, buf)
  • writeblocks(self, blocknum, buf) (optional)
  • count(self)
  • sync(self) (optional)

readblocks and writeblocks should copy data between buf and the block device, starting from block number blocknum on the device. buf will be a bytearray with length a multiple of 512. If writeblocks is not defined then the device is mounted read-only. The return value of these two functions is ignored.

count should return the number of blocks available on the device. sync, if implemented, should sync the data on the device.

The parameter mountpoint is the location in the root of the filesystem to mount the device. It must begin with a forward-slash.

If readonly is True, then the device is mounted read-only, otherwise it is mounted read-write.

If mkfs is True, then a new filesystem is created if one does not already exist.

To unmount a device, pass None as the device and the mount location as mountpoint.


Get or set the UART object where the REPL is repeated on.


Return a 30-bit hardware generated random number.


Sync all file systems.


Returns a string of 12 bytes (96 bits), which is the unique ID of the MCU.