pyb — functions related to the board¶
The pyb module contains specific functions related to the board.
Miscellaneous functions¶
-
pyb.have_cdc()¶ Return True if USB is connected as a serial device, False otherwise.
Note
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.
Note
This function is deprecated. Use
pyb.USB_HID.send()instead.
-
pyb.info([dump_alloc_table])¶ Print out lots of information about the board.
-
pyb.main(filename)¶ Set the filename of the main script to run after boot.py is finished. If this function is not called then the default file main.py will be executed.
It only makes sense to call this function from within boot.py.
-
pyb.mount(device, mountpoint, *, readonly=False, mkfs=False)¶ Mount a block device and make it available as part of the filesystem.
devicemust be an object that provides the block protocol:readblocks(self, blocknum, buf)writeblocks(self, blocknum, buf)(optional)count(self)sync(self)(optional)
readblocksandwriteblocksshould copy data betweenbufand the block device, starting from block numberblocknumon the device.bufwill be a bytearray with length a multiple of 512. Ifwriteblocksis not defined then the device is mounted read-only. The return value of these two functions is ignored.countshould return the number of blocks available on the device.sync, if implemented, should sync the data on the device.The parameter
mountpointis the location in the root of the filesystem to mount the device. It must begin with a forward-slash.If
readonlyisTrue, then the device is mounted read-only, otherwise it is mounted read-write.If
mkfsisTrue, then a new filesystem is created if one does not already exist.To unmount a device, pass
Noneas the device and the mount location asmountpoint.
-
pyb.repl_uart(uart)¶ Get or set the UART object where the REPL is repeated on.
-
pyb.rng()¶ Return a 30-bit hardware generated random number.
-
pyb.sync()¶ Sync all file systems.
-
pyb.unique_id()¶ Returns a string of 12 bytes (96 bits), which is the unique ID of the MCU.
-
pyb.usb_mode([modestr, ]vid=0xf055, pid=0x9801, hid=pyb.hid_mouse)¶ If called with no arguments, return the current USB mode as a string.
If called with
modestrprovided, attempts to set USB mode. This can only be done when called fromboot.pybeforepyb.main()has been called. The following values ofmodestrare understood:None: disables USB'VCP': enable with VCP (Virtual COM Port) interface'VCP+MSC': enable with VCP and MSC (mass storage device class)'VCP+HID': enable with VCP and HID (human interface device)
For backwards compatibility,
'CDC'is understood to mean'VCP'(and similarly for'CDC+MSC'and'CDC+HID').The
vidandpidparameters allow you to specify the VID (vendor id) and PID (product id).If enabling HID mode, you may also specify the HID details by passing the
hidkeyword parameter. It takes a tuple of (subclass, protocol, max packet length, polling interval, report descriptor). By default it will set appropriate values for a USB mouse. There is also apyb.hid_keyboardconstant, which is an appropriate tuple for a USB keyboard.
Classes¶
- class Accel – accelerometer control
- class ADC – analog to digital conversion
- class CAN – controller area network communication bus
- class DAC – digital to analog conversion
- class ExtInt – configure I/O pins to interrupt on external events
- class I2C – a two-wire serial protocol
- class LCD – LCD control for the LCD touch-sensor pyskin
- class LED – LED object
- class Pin – control I/O pins
- class PinAF – Pin Alternate Functions
- class RTC – real time clock
- class Servo – 3-wire hobby servo driver
- class SPI – a master-driven serial protocol
- class Switch – switch object
- class Timer – control internal timers
- class TimerChannel — setup a channel for a timer
- class UART – duplex serial communication bus
- class USB_HID – USB Human Interface Device (HID)
- class USB_VCP – USB virtual comm port