Scan the I2C bus for slave devices.
I2C and SPI are protocols that can link the microbit to other devices, such as an LED matrix or an accelerometer.
There is more about connecting I2C devices to you microbit in this how to article.
There are devices already on the I2c bus: the microbit’s onboard accelerometer and magnetometer (or compass).
The I2C bus is exposed on the microbit’s
pin20. Additional devices can be attached to the bus with these pins.
Connecting components in this way results in fewer wires for communication: SPI uses three wires, I2C requires two.
As mentioned, there are already two devices connected to the microbit on the I2C bus:
Each component added to
pin20 requires an address. Each device has an address ‘hard coded’ into the component. These are usually these are written in the datasheet of the I2C device. Often the address of the device can be changed with jumpers or soldering contact points.
It is also possible to scan the I2C bus for the device if you cannot find it in the datasheet. This program will return a list of the connected devices when button_a is pressed. You’ll need to be connected over serial to the microbit to read it.
It’s based on micropython’s
Published: December 23, 2016 Updated: December 23, 2016