Connect to device on I2C or SPI bus on BBC micro:bit board
microbitdevObj = device(microbitObj,'I2CAddress',"address")
microbitdevObj = device(microbitObj,'SPIChipSelectPin',"pin")
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
microbitObj— BBC micro:bit hardware connection
BBC micro:bit hardware connection, specified as a microbit object created with the
address— Address of I2C device
Address of the I2C device connected to I2C bus, specified as a hexadecimal value.
The address value is obtained using the
pin— Chip select pin number
Pin number that is used as the chip select pin on BBC micro:bit to communicate with the SPI device.
microbitdevObj— Device connection
Device connection to the specific I2C device or SPI device connected to the BBC micro:bit board, returned as a microbit object.