Example mblock code for Me compass and 3-axis accelerometer/gyro?


#1

Can anyone share sample mblock code for these?

  • Me compass
  • 3-axis accelerometer/gyro

Received both modules from makeblock today with the typical no instructions, no help, no nothing.

I see Arduino code instructions online for the compass, but I need this to work in mblock to teach my son.

I’ve tried creating a very basic program to set a variable to the output of each of the above modules, but the variable never receives any value. See code attachment.

Note: both modules show a continuous red light. I have no idea if that means anything. I am connecting to an mBot board.


How to make mbot turn for a specific angle?
I2C Sensors (Compass & Gyro) w/ mBot Serial
#2

Update:

Updating the firmware of the mbot each time I connect or disconnect one of these modules seems to help.

I noticed that I have to be logged into my Windows 10 computer as an administrator for the “Update Firmware” USB connection to the mBot to actually work.

It appears that the Me compass and the accelerometer/gyro both require port 1 on the mBot, so you are using 1 or the other.

So, the following process actually seems to populate compass and accelerometer results in the variables of my sample code:

  1. Connect either the Me compass or the 3-axis accelerometer/gyro to port 1 of the mBot
  2. In mBlock, click Connect/Upgrade Firmware
  3. Write code similar to my example
  4. Click the Green Flag
  5. Now you should see the variables populate with values from the compass or 3-axis modules

#3