The Alpha Geek – Geeking Out

Project #25 – Movement – Sensors – Mk01

——

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

——

Sensors

——

Sensors

——

Sensors

——

Movement

Accelerometers, gyroscopes, and magnetometers are the three main sensors we use for detecting motion and orientation. We can sense motion with an accelerometer.

Accelerometers are used to measure acceleration, that means linear motion in X, Y or Z. They can be used to detect when they are being moved around, detect motion, shock or vibration. They can also be used to detect gravitational pull in order to detect orientation or tilt.

Gyroscopes are used to measure rotational motion in X, Y or Z. They are often paired with accelerometers for inertial guidance systems, 3D motion capture and inverted pendulum type applications.

Magnetometers can sense where the strongest magnetic force is coming from, generally used to detect magnetic north, but can also be used for measuring magnetic fields. When combined with accelerometers and gyroscopes you can stabilize orientation calculations and also determine orientation with respect to the Earth.

Many 6-DoF sensors, which combine accelerometer and gyroscope or compass, accelerometer and magnetometer, and 9-DoF sensors that have 9DoF IMU accelerometers and gyroscopes and magnetometers.

DL2210Mk05

1 x SparkFun RedBoard Qwiic
1 x SparkFun Micro OLED (Qwiic)
1 x Qwiic Cable – 100mm
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

DL2210Mk05p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #25 - Movement - Sensors - Mk01
25-01
DL2210Mk05p.ino
1 x SparkFun RedBoard Qwiic
1 x SparkFun Micro OLED (Qwiic)
1 x Qwiic Cable - 100mm
1 x SparkFun Triple Axis Magnetometer Breakout - HMC5883L
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Two Wire Interface (TWI/I2C)
#include <Wire.h>
// Triple Axis Magnetometer
#include <HMC5883L.h>
// SparkFun Micro OLED
#include <SFE_MicroOLED.h>

// Triple Axis Magnetometer
HMC5883L compass;

// SparkFun Micro OLED
#define PIN_RESET 9
#define DC_JUMPER 1
// I2C declaration
MicroOLED oled(PIN_RESET, DC_JUMPER);

// Triple Axis Magnetometer
int X = 0;
int Y = 0;
int Z = 0;

// Software Version Information
String sver = "25-01";

void loop() {

  // Triple Axis Magnetometer
  isMagnetometer(),
  
  // Micro OLED
  isMicroOLED();

  // One delay in between reads
  delay(1000);
  
}

getMagnetometer.ino

// Magnetometer
// Setup Magnetometer
void isSetupMagnetometer(){

  // Magnetometer Serial
  // Initialize HMC5883L
  while (!compass.begin())
  {
    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);
  
}
// Magnetometer
void isMagnetometer(){

  // Vector Norm
  Vector norm = compass.readNormalize();
  // Vector X, Y, Z
  // X Normalize
  X = norm.XAxis;
  // Y Normalize
  Y = norm.YAxis;
  // Z Normalize
  Z = norm.ZAxis;

}

getMicroOLED.ino

// SparkFun Micro OLED
// Setup Micro OLED
void isSetupMicroOLED() {

  // Initialize the OLED
  oled.begin();
  // Clear the display's internal memory
  oled.clear(ALL);
  // Display what's in the buffer (splashscreen)
  oled.display();

  // Delay 1000 ms
  delay(1000);

  // Clear the buffer.
  oled.clear(PAGE);
  
}
// Micro OLED
void isMicroOLED() {

  // Text Display Magnetometer
  // Clear the display
  oled.clear(PAGE);
  // Set cursor to top-left
  oled.setCursor(0, 0);
  // Set font to type 0
  oled.setFontType(0);
  // Magnetometer
  oled.print("Magneto");
  oled.setCursor(0, 12);
  // X Normalize
  oled.print("X: ");
  oled.print(X);
  oled.setCursor(0, 25);
  // Y Normalize
  oled.print("Y: ");
  oled.print(Y);
  oled.setCursor(0, 39);
  // Z Normalize
  oled.print("Z: ");
  oled.print(Z);
  oled.display();

}

setup.ino

// Setup
void setup() {

  // Give display time to power on
  delay(100);
  
  // Set up I2C bus
  Wire.begin();

  // Setup Triple Axis Magnetometer
  isSetupMagnetometer();

  // Setup Micro OLED
  isSetupMicroOLED();
  
}

——

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

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Wireless (Radio Frequency, Bluetooth, WiFi, Etc…)
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Machine Learning
  • RTOS
  • 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