Main Content

device

Connect to device on I2C or SPI bus on BBC micro:bit board

Description

microbitdevObj = device(microbitObj,'I2CAddress',"address") creates an object that represents the connection to an I2C device connected to the I2C bus on the BBC micro:bit board, specified as a microbit object.

example

microbitdevObj = device(microbitObj,'SPIChipSelectPin',"pin") creates an object that represents the connection to a SPI device connected to the SPI bus on the BBC micro:bit board, specified as a microbit object.

example

Examples

collapse all

Create a microbit object and scan for devices connected to the I2C bus.

microbitObj = microbit('COM3');
scanI2CBus(microbitObj)
ans =  
  1×2 string array 
    "0xE"    "0x1D" 

Use one of the addresses to create an I2C device connection.

i2cdev1 = device(microbitObj,'I2CAddress',"0xE");
i2cdev1 =  

  device with properties: 

             Interface: "I2C" 
            I2CAddress: 14 ("0xE") 
                SCLPin: "P19" 
                SDAPin: "P20" 
               BitRate: 100000 (bits/s) 

Show functions 
 

Create a microbit object and create a device object to connect to an SPI device on pin P16.

microbitObj = microbit('COM3');
spidev1 = device(microbitObj, 'SPIChipSelectPin',"P16");
spidev1 =  
  device with properties: 

      SPIChipSelectPin: "P16" 
                SCLPin: "P13" 
               MISOPin: "P14" 
               MOSIPin: "P15" 

Show all properties, functions 
 

Input Arguments

collapse all

BBC micro:bit hardware connection, specified as a microbit object created with the microbit function.

Address of the I2C device connected to I2C bus, specified as a hexadecimal value. The address value is obtained using the scanI2CBus function.

Pin number that is used as the chip select pin on BBC micro:bit to communicate with the SPI device.

Output Arguments

collapse all

Device connection to the specific I2C device or SPI device connected to the BBC micro:bit board, returned as a microbit object.

Version History

Introduced in R2017b