PROJECT SAMPSON
  • Home
  • Digital Compass
    • Rev C Circuit - Portable
    • Rev C First Test
  • About Me
Digital Cave Compass αI Rev A
Components:
  • Arduino Micro (Link)
  • LSM303DLHC on Breakout Board (Link)
  • 16x2 LCD Character Display (Link)
  • Breadboard (Link)
  • Connecting Wires (Link)
  • USB to USB Micro Cable (Link) [*Note: USB cable must have data capability. Not just a charging cable.]
  • LSM303 Arduino Library (Link)
  • Arduino Sketch Environment (Link)

The first evaluation of the LSM303DLHC will be done with a simple circuit containing the sensor on a breakout board, an LCD display screen, and an Arduino Micro. I have based the initial circuit on the following schematic but have replaced the 8x2 LCD screen with a 16x2 LCD screen which I had on hand. This has kept my prototyping cost low for this first evaluation of the circuit.
Schematic Picture

Since I am using this build to perform a sanity check on using the LSM303DLHC for a cave compass, I am doing my first set of work on a breadboard I have on hand. Promising results on this initial build will lead me to hard wire the next iteration of the project on a thru-hole protoboard.
Picture

Compass Program:
For our initial program for this compass will will use the example serial output program provided in the package that the library comes in. The only change we will make for this portion of the test is to have the calculated heading output to our LCD screen.
#include <Wire.h>
#include <LSM303.h>
#include <LiquidCrystal.h>

LSM303 compass;
LiquidCrystal lcd(12, 11, 10, 9, 8, 6);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  compass.init();
  compass.enableDefault();
  
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("..Initializing..");
}

void loop() {
  compass.read();
  
  Serial.print("Ax: ");
  Serial.print((int)compass.a.x);
  Serial.print(" Ay: ");
  Serial.print((int)compass.a.y);
  Serial.print(" Az: ");
  Serial.print((int)compass.a.z);

  Serial.print("  ");  
  Serial.print("Mx: ");
  Serial.print((int)compass.m.x);
  Serial.print(" My: ");
  Serial.print((int)compass.m.y);
  Serial.print(" Mz: ");
  Serial.print((int)compass.m.z);
  
  // figuring out heading alters the M components so we do heading after
  int heading = compass.heading((LSM303::vector){0,-1,0});
  
  Serial.print(" Heading: ");
  Serial.println(heading);
  
  lcd.clear();
  lcd.print("Heading: ");
  lcd.print(heading);
  
  delay(100);
}
Click to see results from using this circuit
Powered by
✕