micro:bit connection library
    Preparing search index...
    interface MicrobitUSBConnection {
        status: ConnectionStatus;
        type: "usb";
        addEventListener(
            type: "status",
            listener: (data: ConnectionStatusChange) => void,
        ): void;
        addEventListener(
            type: "backgrounderror",
            listener: (data: BackgroundErrorData) => void,
        ): void;
        addEventListener(type: "beforerequestdevice", listener: () => void): void;
        addEventListener(type: "afterrequestdevice", listener: () => void): void;
        addEventListener(type: "flash", listener: () => void): void;
        addEventListener(
            type: "serialdata",
            listener: (data: SerialData) => void,
        ): void;
        addEventListener(type: "serialreset", listener: () => void): void;
        checkAvailability(): Promise<ConnectionAvailabilityStatus>;
        clearDevice(): void | Promise<void>;
        connect(options?: ConnectOptions): Promise<void>;
        disconnect(): Promise<void>;
        dispose(): void;
        flash(dataSource: FlashDataSource, options: FlashOptions): Promise<void>;
        getBoardVersion(): BoardVersion;
        getDevice(): USBDevice | undefined;
        getDeviceId(): number;
        initialize(): Promise<void>;
        removeEventListener(
            type: "status",
            listener: (data: ConnectionStatusChange) => void,
        ): void;
        removeEventListener(
            type: "backgrounderror",
            listener: (data: BackgroundErrorData) => void,
        ): void;
        removeEventListener(
            type: "beforerequestdevice",
            listener: () => void,
        ): void;
        removeEventListener(type: "afterrequestdevice", listener: () => void): void;
        removeEventListener(type: "flash", listener: () => void): void;
        removeEventListener(
            type: "serialdata",
            listener: (data: SerialData) => void,
        ): void;
        removeEventListener(type: "serialreset", listener: () => void): void;
        serialWrite(data: string): Promise<void>;
        setRequestDeviceExclusionFilters(exclusionFilters: USBDeviceFilter[]): void;
        softwareReset(): Promise<void>;
    }

    Hierarchy (View Summary)

    Index
    type: "usb"
    • Flash the micro:bit.

      Not all connection types support flashing. For example, radio bridge connections do not support flashing, and Bluetooth connections only support flashing on native platforms (not Web).

      Post-flash connection state differs by transport:

      • USB: The connection remains in ConnectionStatus.Connected state. USB connects to the micro:bit's interface chip (running DAPLink firmware), which is not affected by flashing the application processor, so the connection persists and serial communication is automatically reinitialised.

      • Bluetooth: The connection is always left in ConnectionStatus.Disconnected state. Bluetooth connects to the application processor directly, which reboots after flashing, so the connection is necessarily lost. Callers must call connect again after flashing.

      Parameters

      Returns Promise<void>

      On flash failure. The error.code property indicates the failure type.

      If data preparation fails.

    • Write serial data to the device.

      Parameters

      • data: string

        The data to write.

      Returns Promise<void>

      A promise that resolves when the write is complete.

      with code not-connected if there is no connection.