Project #29 - DFRobot - AltIMU-10 - Mk19

Project #29 - DFRobot - AltIMU-10 - Mk19

 

https://www.donluc.com/?p=4007

 

https://youtu.be/WRAJ297YqXA

 

#DonLucElectronics #DonLuc #DFRobot #AltIMU10 #9DOF #GPS #FireBeetle2ESP32E #EEPROM #RTC #SD #Display #Pololu #ESP32 #IoT #Arduino #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

 

 

 

 

Pololu AltIMU-10 v5 Gyro, Accelerometer, Compass, and Altimeter

 

The Pololu AltIMU-10 v5 is a compact board that combines ST’s LSM6DS33 3-axis gyroscope and 3-axis accelerometer, LIS3MDL 3-axis magnetometer, and LPS25H digital barometer to form an inertial measurement unit (IMU) and altimeter. These sensors are great ICs, but their small packages make them difficult for the typical student or hobbyist to use. They also operate at voltages below 3.6 Volt, which can make interfacing difficult for microcontrollers operating at 5 Volt. The AltIMU-10 v5 addresses these issues by incorporating additional electronics, including a voltage regulator and a level-shifting circuit, while keeping the overall size as compact as possible. The board ships fully populated with its SMD components, including the LSM6DS33, LIS3MDL, and LPS25H.

 

Attitude and Heading Reference System (AHRS)

 

An attitude and heading reference system (AHRS) uses an inertial measurement unit (IMU) consisting of microelectromechanical system (MEMS) inertial sensors to measure the angular rate, acceleration, and Earth's magnetic field. These measurements can then be used to derive an estimate of the object's attitude. An AHRS typically includes a 3-axis gyroscope, a 3-axis accelerometer, and a 3-axis magnetometer to determine an estimate of a system's orientation. Each of these sensors contribute different measurements to the combined system and each exhibit unique limitations.

 

DL2406Mk06

 

1 x DFRobot FireBeetle 2 ESP32-E
1 x Adafruit SHARP Memory Display
1 x Adafruit MicroSD card breakout board+
1 x MicroSD 16 GB
1 x Pololu AltIMU-10 v5
1 x GPS Receiver - GP-20U7
2 x Switch
1 x 1K Ohm
1 x 1 x Lithium Ion Battery - 1000mAh
1 x Green LED
1 x USB 3.1 Cable A to C

 

DFRobot FireBeetle 2 ESP32-E

 

LED - 2
DSCK - 4
DMOSI - 16
DSS - 17
SCK - 22
MOSI - 23
MISO - 19
CS - 13
GPR - 26
GPT - 25
SCL - 21
SDA - 22
LED - 14
SWI - 3
XAC - A0
YAC - A1
ZAC - A2
VIN - +3.3V
GND - GND

 

DL2406Mk06p.ino

CODE
/****** Don Luc Electronics © ******
Software Version Information
Project #29 - DFRobot - AltIMU-10 - Mk19
29-19
DL2406Mk06p.ino
DL2406Mk06
1 x DFRobot FireBeetle 2 ESP32-E
1 x Adafruit SHARP Memory Display
1 x Adafruit MicroSD card breakout board+
1 x MicroSD 16 GB
1 x Pololu AltIMU-10 v5
1 x GPS Receiver - GP-20U7
2 x Switch
1 x 1K Ohm
1 x 1 x Lithium Ion Battery - 1000mAh
1 x Green LED
1 x USB 3.1 Cable A to C
*/

// Include the Library Code
// EEPROM Library to Read and Write EEPROM
// with Unique ID for Unit
#include "EEPROM.h"
// Wire
#include <Wire.h>
// SD Card
#include "FS.h"
#include "SD.h"
#include "SPI.h"
// SHARP Memory Display
#include <Adafruit_SharpMem.h>
#include <Adafruit_GFX.h>
// GPS Receiver
#include <TinyGPS++.h>
// ESP32 Hardware Serial
#include <HardwareSerial.h>
// Includes and variables for IMU integration
// STMicroelectronics LSM6DS33 Gyroscope and Accelerometer
#include <LSM6.h>
// STMicroelectronics LIS3MDL Magnetometer
#include <LIS3MDL.h>
// STMicroelectronics LPS25H digital Barometer
#include <LPS.h>

// Earth's magnetic field varies by location. Add or subtract
// a declination to get a more accurate heading. Calculate
// your's here: http://www.ngdc.noaa.gov/geomag-web/#declination
// Declination (degrees) in Mexicali
#define DECLINATION 10.31

// 9DoF IMU
// STMicroelectronics LSM6DS33 Gyroscope and Accelerometer
LSM6 imu;
// Accelerometer and Gyroscopes
// Accelerometer
int imuAX;
int imuAY;
int imuAZ;
//String FullStringB = "";
// Gyroscopes 
int imuGX;
int imuGY;
int imuGZ;
// STMicroelectronics LIS3MDL magnetometer
LIS3MDL mag;
// Magnetometer
int magX;
int magY;
int magZ;
// STMicroelectronics LPS25H digital barometer
LPS ps;
// Digital Barometer
float pressure;
float altitude;
float temperature;
// Attitude Calculate Pitch, Roll, and Headind
float r;
float p;
float h;

// ESP32 HardwareSerial
HardwareSerial tGPS(2);

// GPS Receiver
#define gpsRXPIN 26
// This one is unused and doesnt have a conection
#define gpsTXPIN 25
// The TinyGPS++ object
TinyGPSPlus gps;
// Latitude
float TargetLat;
// Longitude
float TargetLon;
// GPS Date, Time, Speed, Altitude
// GPS Date
String TargetDat;
// GPS Time
String TargetTim;
// GPS Speeds M/S
String TargetSMS;
// GPS Speeds Km/h
String TargetSKH;
// GPS Altitude Meters
String TargetALT;
// GPS Status
String GPSSt = "";

// MicroSD Card
const int chipSelect = 13;
String zzzzzz = "";

// SHARP Memory Display
#define SHARP_SCK  4
#define SHARP_MOSI 16
#define SHARP_SS   17
// Set the size of the display here, e.g. 144x168!
Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
// The currently-available SHARP Memory Display (144x168 pixels)
// requires > 4K of microcontroller RAM; it WILL NOT WORK on Arduino Uno
// or other <4K "classic" devices.
#define BLACK 0
#define WHITE 1

// LED Green
int iLEDGreen = 2;

// Define LED
int iLED = 14;

// Switch
int iSwitch = 3;
// Variable for reading the Switch status
int iSwitchState = 0;

// EEPROM Unique ID Information
#define EEPROM_SIZE 64
String uid = "";

// Software Version Information
String sver = "29-19";

void loop() {

  // Accelerometer and Gyroscopes
  isIMU();

  // Magnetometer
  isMag();

  // Barometer
  isBarometer();

  // Attitude Calculate Pitch, Roll, and Heading
  isAttitude(imuAX, imuAY, imuAZ, -imuGY, -imuGX, imuGZ);

  // isGPS
  isGPS();

  // Read the state of the Switch value
  iSwitchState = digitalRead(iSwitch);
  
  // The Switch is HIGH:
  if (iSwitchState == HIGH) {

    // Attitude Calculate Pitch, Roll, and Heading and Barometer
    isDisplayAttitude();
  
  } else {

    // Display GPS
    isDisplayGPS();
    
  }  

  // MicroSD Card
  isSD();

  // iLED HIGH
  digitalWrite(iLED, HIGH );

  // Delay 5 Second
  delay(5000);

}

getAccelGyro.ino

CODE
// Accelerometer and Gyroscopes
// Setup IMU
void isSetupIMU() {

  // Setup IMU
  imu.init();
  // Default
  imu.enableDefault();
  
}
// Accelerometer and Gyroscopes
void isIMU() {

  // Accelerometer and Gyroscopes
  imu.read();
  // Accelerometer x, y, z
  imuAX = imu.a.x;
  imuAY = imu.a.y;
  imuAZ = imu.a.z;
  // Gyroscopes x, y, z
  imuGX = imu.g.x;
  imuGY = imu.g.y;
  imuGZ = imu.g.z;

}

getAttitude.ino

CODE
// Attitude Calculate Pitch, Roll, and Heading
void isAttitude(float ax, float ay, float az, float mx, float my, float mz) {

  // Attitude Calculate Pitch, Roll, and Heading
  float roll = atan2(ay, az);
  float pitch = atan2(-ax, sqrt(ay * ay + az * az));

  float heading;
  if (my == 0)
    heading = (mx < 0) ? PI : 0;
  else
    heading = atan2(mx, my);

  heading -= DECLINATION * PI / 180;

  if (heading > PI) heading -= (2 * PI);
  else if (heading < -PI) heading += (2 * PI);

  // Convert everything from radians to degrees:
  heading *= 180.0 / PI;
  pitch *= 180.0 / PI;
  roll  *= 180.0 / PI;

  h = heading;
  p = pitch;
  r = roll;
  
}

getBarometer.ino

CODE
// STMicroelectronics LPS25H digital barometer
// Setup Barometer
void isSetupBarometer(){

  // Setup Barometer
  ps.init();
  // Default
  ps.enableDefault();
  
}
// Barometer
void isBarometer(){

  // Barometer
  pressure = ps.readPressureMillibars();
  // Altitude Meters
  altitude = ps.pressureToAltitudeMeters(pressure);
  // Temperature Celsius
  temperature = ps.readTemperatureC();

}

getDisplay.ino

CODE
// SHARP Memory Display
// SHARP Memory Display - UID
void isDisplayUID() {

    // Text Display 
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(3);
    display.setTextColor(BLACK);
    // Don Luc Electronics
    display.setCursor(0,10);
    display.println( "Don Luc" );
    display.setTextSize(2);
    display.setCursor(0,40);
    display.println( "Electronics" );
    // Version
    //display.setTextSize(3);
    display.setCursor(0,70);
    display.println( "Version" );
    //display.setTextSize(2);
    display.setCursor(0,95);   
    display.println( sver );
    // EEPROM
    display.setCursor(0,120);
    display.println( "EEPROM" );
    display.setCursor(0,140);   
    display.println( uid );
    // Refresh
    display.refresh();
    delay( 100 );
    
}
// Attitude Calculate Pitch, Roll, and Heading
void isDisplayAttitude() {

    // Text Display
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Pitch
    display.setCursor(0,5);
    display.print( "Pi: " );
    display.println( p );
    // Roll
    display.setCursor(0,25);
    display.print( "Ro: " );
    display.println( r );
    // Heading
    display.setCursor(0,45);
    display.print( "He: " );
    display.println( h );
    // Temperature Celsius
    display.setCursor(0,65);
    display.print( "Te: " );
    display.println( temperature );
    // Barometer
    display.setCursor(0,85);
    display.print( "Ba: " );
    display.println( pressure );
    // Altitude Meters
    display.setCursor(0,105);
    display.print( "Al: " );
    display.println( altitude );
    // Refresh
    display.refresh();
    delay( 100 );

}
// Display GPS
void isDisplayGPS() {

    // Text Display Date
    // Clear Display
    display.clearDisplay();
    display.setRotation(4);
    display.setTextSize(2);
    display.setTextColor(BLACK);
    // Latitude
    display.setCursor(0,5);
    display.print( "Lat: " );
    display.println( TargetLat );
    // Longitude
    display.setCursor(0,30);
    display.print( "Lon: " );
    display.println( TargetLon );
    // GPS Date
    display.setCursor(0,55);
    display.println( TargetDat );
    // GPS Time
    display.setCursor(0,80);
    display.println( TargetTim );
    // GPS Speed M/S
    display.setCursor(0,105);
    display.print( TargetSMS );
    display.println( " M/S" );
    // GPS Altitude Meters
    display.setCursor(0,130);
    display.print( TargetALT );
    display.println( " M" );
    // Refresh
    display.refresh();
    delay( 100 );

}

getEEPROM.ino

CODE
// EEPROM
// isUID EEPROM Unique ID
void isUID() {
  
  // Is Unit ID
  uid = "";
  for (int x = 0; x < 7; x++)
  {
    uid = uid + char(EEPROM.read(x));
  }
  
}

getGPS.ino

CODE
// GPS Receiver
// Setup GPS
void isSetupGPS() {

  // Setup GPS
  tGPS.begin(  9600 , SERIAL_8N1 , gpsRXPIN , gpsTXPIN );
  
}
// isGPS
void isGPS(){

  // Receives NEMA data from GPS receiver
  // This sketch displays information every time a new sentence is correctly encoded
  while ( tGPS.available() > 0)
    
    if (gps.encode( tGPS.read() ))
    {
     
       // GPS Vector Pointer Target
       displayInfo();
       // GPS Date, Time, Speed, Altitude
       displayDTS();
       
    }
  
  if (millis() > 5000 && gps.charsProcessed() < 10)
  {
   
     while(true);
    
  }

}
// GPS Vector Pointer Target
void displayInfo(){

  // Location
  if (gps.location.isValid())
  {
    
     // Latitude
     TargetLat = gps.location.lat();
     // Longitude
     TargetLon = gps.location.lng();
     // GPS Status 2
     GPSSt = "Yes";
    
  }
  else
  {

     // GPS Status 0
     GPSSt = "No";
    
  }

}
// GPS Date, Time, Speed, Altitude
void displayDTS(){

  // Date
  TargetDat = ""; 
  if (gps.date.isValid())
  {
    
     // Date
     // Year
     TargetDat += String(gps.date.year(), DEC);
     TargetDat += "/";
     // Month
     TargetDat += String(gps.date.month(), DEC);
     TargetDat += "/";
     // Day
     TargetDat += String(gps.date.day(), DEC);
    
  }

  // Time
  TargetTim = "";
  if (gps.time.isValid())
  {
    
     // Time
     // Hour
     TargetTim += String(gps.time.hour(), DEC);
     TargetTim += ":";
     // Minute
     TargetTim += String(gps.time.minute(), DEC);
     TargetTim += ":";
     // Secound
     TargetTim += String(gps.time.second(), DEC);
    
  }

  // Speed
  TargetSMS = "";
  TargetSKH = "";
  if (gps.speed.isValid())
  {
    
     // Speed
     // M/S
     int x = gps.speed.mps();
     TargetSMS = String( x, DEC);
     // Km/h
     int y = gps.speed.kmph();
     TargetSKH = String( y, DEC);

  }

  // Altitude
  TargetALT = "";
  if (gps.altitude.isValid())
  {
    
     // Altitude
     // Meters
     int z = gps.altitude.meters();
     TargetALT = String( z, DEC);

  }
  
}

getMagnetometer.ino

CODE
// Magnetometer
// Setup Magnetometer
void isSetupMag() {

  // Setup Magnetometer
  mag.init();
  // Default
  mag.enableDefault();
  
}
// Magnetometer
void isMag() {

  // Magnetometer
  mag.read();
  // Magnetometer x, y, z
  magX = mag.m.x;
  magY = mag.m.y;
  magZ = mag.m.z;

}

getSD.ino

CODE
// MicroSD Card
// MicroSD Setup
void isSetupSD() {

    // MicroSD Card
    pinMode( chipSelect , OUTPUT );
    if(!SD.begin( chipSelect )){
        ;  
        return;
    }
    
    uint8_t cardType = SD.cardType();

    // CARD NONE
    if(cardType == CARD_NONE){
        ; 
        return;
    }

    // SD Card Type
    if(cardType == CARD_MMC){
        ; 
    } else if(cardType == CARD_SD){
        ; 
    } else if(cardType == CARD_SDHC){
        ; 
    } else {
        ; 
    } 

    // Size
    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
 
}
// MicroSD Card
void isSD() {

  zzzzzz = "";

  //DFR|EEPROM Unique ID|Version|
  //Accelerometer X|Accelerometer Y|Accelerometer Z|
  //Gyroscope X|Gyroscope Y|Gyroscope Z|
  //Magnetometer X|Magnetometer Y|Magnetometer Z|
  //Pitch|Roll|Heading|
  //Temperature C|Pressure Millibars|Altitude Meters|
  //GPS|Latitude|Longitude|GPS Date|GPS Time|GPS Speed M/S|GPS Altitude|*\r
  zzzzzz = "DFR|" + uid + "|" + sver + "|"
  + String(imuAX) + "|" + String(imuAY) + "|" + String(imuAZ) + "|"
  + String(imuGX) + "|" + String(imuGY) + "|" + String(imuGZ) + "|"
  + String(magX) + "|" + String(magY) + "|" + String(magZ) + "|"
  + String(p) + "|" + String(r) + "|" + String(h) + "|"
  + String(temperature) + "|" + String(pressure) + "|" + String(altitude) + "|"
  + String(GPSSt) + "|" + String(TargetLat) + "|" 
  + String(TargetLon) + "|" + String(TargetDat) + "|" + String(TargetTim) + "|" 
  + String(TargetSMS) + "|" + String(TargetALT)+ "|*\r";

  // msg + 1
  char msg[zzzzzz.length() + 1];

  zzzzzz.toCharArray(msg, zzzzzz.length() + 1);

  // Append File
  appendFile(SD, "/dfrdata.txt", msg );
  
}
// List Dir
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
    
    // List Dir
    dirname;
    
    File root = fs.open(dirname);
    
    if(!root){
        return;
    }
    
    if(!root.isDirectory()){
        return;
    }

    File file = root.openNextFile();
    
    while(file){
        if(file.isDirectory()){
            file.name();
            if(levels){
                listDir(fs, file.name(), levels -1);
            }
        } else {
            file.name();
            file.size();
        }
        file = root.openNextFile();
    }
    
}
// Write File
void writeFile(fs::FS &fs, const char * path, const char * message){
    
    // Write File
    path;
    
    File file = fs.open(path, FILE_WRITE);
    
    if(!file){
        return;
    }
    
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    
    file.close();
    
}
// Append File
void appendFile(fs::FS &fs, const char * path, const char * message){
    
    // Append File
    path;
    
    File file = fs.open(path, FILE_APPEND);
    
    if(!file){
        return;
    }
    
    if(file.print(message)){
        ;  
    } else {
        ;  
    }
    
    file.close();
    
}

setup.ino

CODE
// Setup
void setup()
{
  
  // Give display time to power on
  delay(100);

  // EEPROM Size
  EEPROM.begin(EEPROM_SIZE);
  
  // EEPROM Unique ID
  isUID();

  // Give display
  delay(100);

  // Set up I2C bus
  Wire.begin();

  // Give display
  delay(100);

  //MicroSD Card
  isSetupSD();

  // SHARP Display Start & Clear the Display
  display.begin();
  // Clear Display
  display.clearDisplay();

  // Delay
  delay( 100 );

  // GPS Receiver
  // Setup GPS
  isSetupGPS();

  // Delay
  delay( 100 );

  // Setup IMU
  isSetupIMU();

  // Setup Magnetometer
  isSetupMag();

  // Setup Barometer
  isSetupBarometer();

  // Delay
  delay( 100 );

  // Initialize digital pin iLED as an output
  pinMode(iLED, OUTPUT);

  // Outputting high, the LED turns on
  digitalWrite(iLED, HIGH);

  // Initialize the LED Green
  pinMode(iLEDGreen, OUTPUT);

  // iLEDGreen HIGH
  digitalWrite(iLEDGreen, HIGH );

  // Initialize the Switch
  pinMode(iSwitch, INPUT);

  // Don Luc Electronics
  // Version
  // EEPROM
  isDisplayUID();
  
  // Delay 5 Second
  delay( 5000 );

}

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

 

Teacher, Instructor, E-Mentor, R&D and Consulting

 

-Programming Language
-Microcontrollers (PIC, Arduino, Raspberry Pi, Arm, Silicon Labs, Espressif, Etc...)
-IoT
-Wireless (Radio Frequency, Bluetooth, WiFi, Etc...)
-Robotics
-Automation
-Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
-Unmanned Vehicles Terrestrial and Marine
-Machine Learning
-Artificial Intelligence (AI)
-RTOS
-Sensors, eHealth Sensors, Biosensor, and Biometric
-Research & Development (R & D)
-Consulting
-Etc...

 

Follow Us

 

Luc Paquin – Curriculum Vitae - 2024
https://www.donluc.com/luc/

 

Web: https://www.donluc.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/@thesass2063
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/
LinkedIn: https://www.linkedin.com/in/jlucpaquin/

 

Don Luc

icon DL2406Mk06.zip 1.25MB Download(1)
License
All Rights
Reserved
licensBg
0