Gadget, Strike and Dip

Strike & Dip Part I

This post was originally published on September 14, 2017 at https://sparklechicken.net/channel/jakessbc

 

Strike and dip measurements are a fundamental part of field geology, and typically done by hand with a transit compass.  There are apps out there for mobile devices that will automagically determine the strike and dip of an outcropping, but since the magnetometer is so close to the rest of the electronics, the strike measurement tends to be pretty jacked up.  I figured that if I were able to separate the sensors from the controller, it might give better readings.  I still need to figure out how accurate the device is, and plan on updating it with an barometer/thermometer for altitude and a GPS sensor, but for now, it is a functioning prototype.  Oh, and I need a better display, too.

This build requires:

  • Arduino Uno
  • ST7735 1.4″ TFT
  • 9-DOF IMU L3GD20 + LSM303

The code is pretty much a mash up of the example code from Adafruit for both the IMU and the TFT.


#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_9DOF.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#define TFT_CS     10
#define TFT_RST    9  // you can also connect this to the Arduino reset
                      // in which case, set this #define pin to 0!
#define TFT_DC     8
#define TFT_SCLK 13   // set these to be whatever pins you like!
#define TFT_MOSI 11   // set these to be whatever pins you like!

/* Assign a unique ID to the sensors */
Adafruit_9DOF                dof   = Adafruit_9DOF();
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified   mag   = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS,  TFT_DC, TFT_RST);

/* Update this with the correct SLP for accurate altitude measurements */
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
float p = 3.1415926;
/**************************************************************************/
/*!
    @brief  Initialises all the sensors used by this example
*/
/**************************************************************************/
void initSensors()
{
  if(!accel.begin())
  {
    /* There was a problem detecting the LSM303 ... check your connections */
    Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
    while(1);
  }
  if(!mag.begin())
  {
    /* There was a problem detecting the LSM303 ... check your connections */
    Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
    while(1);
  }
}

/**************************************************************************/
/*!

*/
/**************************************************************************/
void setup(void)
{
  Serial.begin(115200);
  Serial.println(F("Adafruit 9 DOF Pitch/Roll/Heading Example")); Serial.println("");
  tft.initR(INITR_BLACKTAB);
  /* Initialise the sensors */
  initSensors();
  uint16_t time = millis();
  tft.fillScreen(ST7735_BLACK);
  time = millis() - time;
}

/**************************************************************************/
/*!
    @brief  Constantly check the roll/pitch/heading/altitude/temperature
*/
/**************************************************************************/
void loop(void)
{
  sensors_event_t accel_event;
  sensors_event_t mag_event;
  sensors_vec_t   orientation;

  /* Calculate pitch and roll from the raw accelerometer data */
  accel.getEvent(&accel_event);
  if (dof.accelGetOrientation(&accel_event, &orientation))
  {
    /* 'orientation' should have valid .roll and .pitch fields */
    tft.fillScreen(ST7735_BLACK);
    tft.setCursor(0, 30);
    tft.setTextColor(ST7735_YELLOW);
    tft.setTextSize(2);
    tft.println("Roll: ");
    tft.println(orientation.roll);
    tft.println("; ");
    tft.println("Pitch: ");
    tft.println(orientation.pitch);
    tft.println("; ");
    delay(1000);
  }
  
  /* Calculate the heading using the magnetometer */
  mag.getEvent(&mag_event);
  if (dof.magGetOrientation(SENSOR_AXIS_Z, &mag_event, &orientation))
  {
    /* 'orientation' should have valid .heading data now */
    tft.fillScreen(ST7735_BLACK);
    tft.setCursor(0, 30);
    tft.setTextColor(ST7735_YELLOW);
    tft.setTextSize(2);
    tft.println("Heading: ");
    tft.println(orientation.heading);
    tft.println("; ");
    delay(1000);
  }

  tft.println("");
  delay(1000);
}

void testdrawtext(char *text, uint16_t color) {
  tft.setCursor(0, 0);
  tft.setTextColor(color);
  tft.setTextWrap(true);
  tft.print(text);
}