Thumbnail

HMC5883 Compass

Reads HMC5883 3-axis compass via I2C and updates EZ-Script variables on demand; polled control offers periodic heading data, for connected sensors.

How to add the HMC5883 Compass robot skill

  1. Load the most recent release of ARC (Get ARC).
  2. Press the Project tab from the top menu bar in ARC.
  3. Press Add Robot Skill from the button ribbon bar in ARC.
  4. Choose the I2C category tab.
  5. Press the HMC5883 Compass icon to add the robot skill to your project.

Don't have a robot yet?

Follow the Getting Started Guide to build a robot and use the HMC5883 Compass robot skill.


How to use the HMC5883 Compass robot skill

Before You Start (Beginner Checklist)
  • Hardware: An EZ-B v4 and an HMC5883 (EZ-Bit) compass module.
  • Wiring: The compass must be connected to the EZ-B’s I2C port.
  • ARC project: Add the HMC5883 Skill to your ARC project.
  • Important: If the sensor is not connected correctly and you try to communicate with it, the EZ-B v4 can lock up. Double-check wiring before running any script.
How This Skill Works

This Skill does not continuously read the sensor by itself. Instead, you request a reading whenever you want one.

  1. Initialize the sensor (required): You must run Init once after the Skill loads (or once when your project starts).
  2. Request readings: Each time you want new compass data, call RunOnce. The Skill will query the sensor and then update its EZ-Script variables.
Example: Update the Compass Every 100 ms

The script below initializes the HMC5883, then loops forever and requests a new reading every 100 milliseconds.

Make sure you do all of the following first:
  • Add the HMC5883 Skill to your ARC project.
  • Connect the HMC5883 module to the EZ-B’s I2C port.
  • Create/open an EZ-Script control and paste in the script.
  • Confirm the control name in the script matches your Skill’s name exactly (including spaces).
ControlCommand("HMC5883 ", Init)

:loop

ControlCommand("HMC5883 ", RunOnce)
  
sleep(100)

goto(loop)

What this script is doing
  • ControlCommand("HMC5883 ", Init) initializes the compass sensor (do this once).
  • :loop creates a label for the loop.
  • ControlCommand("HMC5883 ", RunOnce) requests one fresh sensor reading and updates the variables.
  • sleep(100) waits 100 ms to avoid spamming the I2C bus.
  • goto(loop) repeats the process forever until you stop the script.
Common Problems (Quick Fixes)
  • EZ-B locks up when running the script: Usually means the sensor is not detected on I2C (loose cable, wrong port, incorrect wiring, or no power). Power down, re-check wiring, then try again.
  • No data changes: Confirm you ran Init first, then call RunOnce repeatedly (the Skill does not auto-refresh).
  • Control name mismatch: The name in ControlCommand("HMC5883 ", ...) must match the Skill’s control name in ARC exactly.

ARC Pro

Upgrade to ARC Pro

Take control of your robot's destiny by subscribing to Synthiam ARC Pro, and watch it evolve into a versatile and responsive machine.