The Alpha Geek – Geeking Out

Project #24 – RTOS – Magnetometers HMC5883L – Mk02

——

#DonLucElectronics #DonLuc #SparkFunRedBoard #RTOS #FreeRTOS #Magnetometer #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Magnetometers HMC5883L

——

Magnetometers HMC5883L

——

Magnetometers HMC5883L

——

SparkFun Triple Axis Magnetometer Breakout – HMC5883L

This is a breakout board for Honeywell’s HMC5883L, a 3-axis digital compass. Communication with the HMC5883L is simple and all done through an I2C interface. There is no on-board regulator, so a regulated voltage of 2.16-3.6VDC should be supplied. The breakout board includes the HMC5883L sensor and all filtering capacitors as shown. The power and 2-wire interface pins are all broken out to a 0.1″ pitch header.

Magnetometers have a wide range of uses. The most common include using the chip as a digital compass to sense direction or using them to detect ferrous (magnetic) metals. Magnetic fields and current go hand-in-hand. When current flows through a wire, a magnetic field is created. This is the basic principle behind electromagnets. This is also the principle used to measure magnetic fields with a magnetometer. The direction of Earth’s magnetic fields affects the flow of electrons in the sensor, and those changes in current can be measured and calculated to derive a compass heading or other useful information.

DL2210Mk03

1 x SparkFun RedBoard Qwiic
1 x SparkFun Triple Axis Magnetometer Breakout – HMC5883L
1 x SparkFun Cerberus USB Cable

SparkFun RedBoard Qwiic

SDA – Analog A4
SCL – Analog A5
VIN – +3.3V
GND – GND

DL2210Mk03p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #24 - RTOS - Magnetometer - Mk02
24-02
DL2210Mk03p.ino
1 x SparkFun RedBoard Qwiic
1 x SparkFun Triple Axis Magnetometer Breakout - HMC5883L
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// FreeRTOS
#include <Arduino_FreeRTOS.h>
// Two Wire Interface (TWI/I2C)
#include <Wire.h>
// Triple Axis Magnetometer
#include <HMC5883L.h>

// Define two tasks for Triple Axis Magnetometer
void isTaskMagnetometer( void *pvParameters );

// Software Version Information
String sver = "24-02";

void loop() {

  // Empty. Things are done in Tasks.
  
}

getTasks.ino

// Tasks
// Setup Task
void isSetupTask(){

  // Now set up one tasks to run independently
  // Magnetometer
  //xTaskCreatePinnedToCore(
  xTaskCreate(
    isTaskMagnetometer
    ,  "Magnetometer"
    ,  128  // Stack size
    ,  NULL
    ,  1  // Priority
    ,  NULL);

  // Now the task scheduler, which takes over control of scheduling individual tasks,
  // is automatically started.
  
}
// This is a Task Magnetometer Serial
void isTaskMagnetometer(void *pvParameters)
{
  
  (void) pvParameters;
  
  // Triple Axis Magnetometer
  HMC5883L compass;

  // Magnetometer Serial
  // Initialize HMC5883L
  Serial.println("Initialize HMC5883L");
  while (!compass.begin())
  {
    Serial.println("Could not find a valid HMC5883L sensor, check wiring!");
    delay(500);
  }

  // Set measurement range
  // +/- 1.30 Ga: HMC5883L_RANGE_1_3GA (default)
  compass.setRange(HMC5883L_RANGE_1_3GA);

  // Set measurement mode
  // Continuous-Measurement: HMC5883L_CONTINOUS (default)
  compass.setMeasurementMode(HMC5883L_CONTINOUS);
 
  // Set data rate
  // 15.00Hz: HMC5883L_DATARATE_15HZ (default)
  compass.setDataRate(HMC5883L_DATARATE_15HZ);

  // Set number of samples averaged
  // 1 sample:  HMC5883L_SAMPLES_1 (default)
  compass.setSamples(HMC5883L_SAMPLES_1);

  for (;;)
  {
    
    // Vector Norm
    Vector norm = compass.readNormalize();
    // Vector X, Y, Z
    Serial.print("Xnorm = ");
    Serial.print(norm.XAxis);
    Serial.print(" Ynorm = ");
    Serial.print(norm.YAxis);
    Serial.print(" ZNorm = ");
    Serial.print(norm.ZAxis);
    Serial.println();  
    // One tick delay in between reads
    vTaskDelay(500);
    
  }
  
}

setup.ino

// Setup
void setup() {

  // Initialize serial communication
  // at 9600 bits per second:
  Serial.begin(9600);

  // Setup Task
  isSetupTask();
  
}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories
Archives