Sunday, March 2, 2014

Compass and Line Sensor Programming- Matt Mannino

The orders came in finally and I was able to start working on programming the Pololu LSM303 Compass Sensor.  I used an example program from Pololu using their specific library for the LSM303.  I was getting stable values for the heading.  I also started on the line sensing programming using the QRD1114 light sensors.  The light sensor is for predetermined boundaries where the robot is going to operate in using tape.

QRD1114 Wiring for Arduino


Value Readings from QRD1114 Light Sensor

Heading Value Readings from LSM303 Compass Sensor



LSM303 Pinouts


     5V  ->  VIN
    GND  ->  GND
    SDA  ->  SDA
    SCL  ->  SCL








QRD1114 Test
int sensorPin = 0; //A0

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int val = analogRead(sensorPin);
  Serial.println(val);

  delay(100);


}


LSM303 Compass Heading

#include <Wire.h>
#include <LSM303.h>

LSM303 compass;

void setup()
{
  Serial.begin(9600);
  Wire.begin();
  compass.init();
  compass.enableDefault();

  compass.m_min = (LSM303::vector<int16_t>){-32767, -32767, -32767};
  compass.m_max = (LSM303::vector<int16_t>){+32767, +32767, +32767};
}

void loop()
{
  compass.read();

  float heading = compass.heading();

  Serial.println(heading);
  delay(100);

}

No comments:

Post a Comment