Example Code for MakeCode-Upload Data-I2C

Realize data transmission between the micro:bit and the WiFi IoT module via I2C communication, and send the message "Hi, DFRobot" to the Easy IoT platform.

Hardware Preparation

  • MBT0039 micro:bit board x 1
  • MBT0008 IO Extender for micro:bit x1
  • WiFi IoT module x1
  • Wires

Wiring Diagram

Software Preparation

This section mainly introduces how to use the WiFi IoT module and how to program it using MakeCode.

MakeCode Programming Platform:
https://makecode.microbit.org/

I2C Library:
MakeCode I2C Library – DFRobot WiFi IoT

Configure IoT Platform

The platform configuration of project 1 can be directly used here.

Sample Code

Program Link

https://makecode.microbit.org/_FxkY6MLgmJ2M

Program Blocks

2-4

Result

Since we use I2C communication mode here, the control switch on the WiFi IOT module needs to be turned to the I2C side, otherwise the initialization of the module will fail and the data transmission will not be possible.

3

Press down the button A on the micro:bit, the WiFi IoT module send a message "Hi, DFRobot" to Easy IoT platform.

4

From the two projects above, it can be seen that when we use UART or I2C, the fininal function is basically the same. However, I2C communication will not occupy the serial port, and more convenientto use. So we will use I2C in the later projects.

Was this article helpful?

TOP