This repository has been archived by the owner on Apr 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Koen-Leaphy/master
Add new Compass Sensor
- Loading branch information
Showing
3 changed files
with
72 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
name=Leaphy Extra Extension | ||
version=0.0.13 | ||
version=0.0.14 | ||
author=Leaphy Robotics | ||
maintainer=Leaphy Robotics <[email protected]> | ||
sentence=Provides Extra functionality to Leaphy robots | ||
paragraph= | ||
category=Device Control | ||
url=https://github.com/leaphy-robotics/leaphy-extensions-extra | ||
architectures=avr | ||
includes=Adafruit_NeoPixel.h,Adafruit_TCS34725.h,ledstrip.h,Leaphy_Extra.h,OLED_Display.h | ||
depends=Adafruit SSD1306,Adafruit GFX Library | ||
includes=Adafruit_NeoPixel.h,Adafruit_TCS34725.h,ledstrip.h,Leaphy_Extra.h,OLED_Display.h,LSM303AGR.h | ||
depends=Adafruit SSD1306,Adafruit GFX Library,Adafruit LSM303 Accel,Adafruit LIS2MDL,Adafruit BusIO Register,Adafruit I2CDevice,Adafruit SPIDevice,Adafruit Sensor,Wire |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "LSM303AGR.h" | ||
|
||
#define _ADDRESS_MAG 0x1E //!< Default address | ||
#include <Adafruit_BusIO_Register.h> | ||
#include <Adafruit_I2CDevice.h> | ||
#include <Adafruit_SPIDevice.h> | ||
#include <Adafruit_Sensor.h> | ||
#include <Wire.h> | ||
|
||
CompassSensor::CompassSensor() { | ||
CompassSensor::mag = Adafruit_LIS2MDL(); | ||
// initiate the event | ||
CompassSensor::mag.getEvent(&data); | ||
} | ||
|
||
bool CompassSensor::begin(uint8_t i2c_addr = _ADDRESS_MAG, TwoWire *wire = &Wire) { | ||
CompassSensor::mag.begin(i2c_addr = _ADDRESS_MAG, wire = &Wire); | ||
|
||
return true; | ||
} | ||
|
||
bool CompassSensor::begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI) { | ||
CompassSensor::mag.begin_SPI(cs_pin, theSPI); | ||
|
||
return true; | ||
} | ||
|
||
bool CompassSensor::begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin, int8_t mosi_pin) { | ||
CompassSensor::mag.begin_SPI(cs_pin, sck_pin, miso_pin, mosi_pin); | ||
|
||
return true; | ||
} | ||
|
||
lis2mdl_rate_t CompassSensor::getDataRate() { | ||
return CompassSensor::mag.getDataRate(); | ||
} | ||
|
||
void CompassSensor::setDataRate(lis2mdl_rate_t rate) { | ||
CompassSensor::mag.setDataRate(rate); | ||
} | ||
|
||
void CompassSensor::reset() { | ||
CompassSensor::mag.reset(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef LSM303AGR_H | ||
#define LSM303AGR_H | ||
#include <Wire.h> | ||
#include <Adafruit_Sensor.h> | ||
#include <Adafruit_LIS2MDL.h> | ||
|
||
class CompassSensor { | ||
private: | ||
Adafruit_LIS2MDL mag; | ||
|
||
|
||
public: | ||
sensors_event_t * data; | ||
CompassSensor(); | ||
bool begin(uint8_t i2c_addr = _ADDRESS_MAG, TwoWire *wire = &Wire); | ||
bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI); | ||
bool begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin, | ||
int8_t mosi_pin); | ||
|
||
lis2mdl_rate_t getDataRate(); | ||
void setDataRate(lis2mdl_rate_t rate); | ||
void reset(); | ||
}; | ||
|
||
#endif |