2022-12-02 04:37:37 -05:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: A1301.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2024-04-19 13:37:04 -04:00
|
|
|
// VERSION: 0.2.3
|
2022-12-02 04:37:37 -05:00
|
|
|
// DATE: 2010-07-22
|
|
|
|
// PURPOSE: Arduino library for A1301 A1302 magnetometer.
|
2023-04-25 04:25:42 -04:00
|
|
|
// URL: https://github.com/RobTillaart/A1301
|
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
|
|
|
|
// always check datasheet.
|
|
|
|
// PIN A1301
|
|
|
|
// ===============
|
|
|
|
// 1 GND
|
|
|
|
// 2 DATA
|
|
|
|
// 3 VDD +5V
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
2024-04-19 13:37:04 -04:00
|
|
|
#define A1301_LIB_VERSION (F("0.2.3"))
|
2022-12-02 04:37:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
class HALL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HALL(uint8_t pin);
|
|
|
|
|
|
|
|
// ADC parameters
|
|
|
|
void begin(float voltage, uint16_t steps);
|
|
|
|
|
2023-04-25 04:25:42 -04:00
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
// midpoint depends on ADC.
|
|
|
|
void setMidPoint(float midPoint);
|
2024-01-01 11:20:13 -05:00
|
|
|
float autoMidPoint(uint8_t times = 100);
|
2022-12-02 04:37:37 -05:00
|
|
|
float getMidPoint();
|
2022-12-02 06:52:49 -05:00
|
|
|
// to override default sensitivity
|
2022-12-02 04:37:37 -05:00
|
|
|
void setSensitivity(float sensitivity);
|
|
|
|
float getSensitivity();
|
|
|
|
|
2023-04-25 04:25:42 -04:00
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
// READ
|
|
|
|
// times > 1 ==> more stable read / averaging.
|
|
|
|
// uses internal ADC
|
2023-01-03 14:01:29 -05:00
|
|
|
float raw(uint8_t times = 1); // returns raw ADC
|
|
|
|
float read(uint8_t times = 1); // returns Gauss
|
2023-09-20 13:16:07 -04:00
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
// for external ADC
|
|
|
|
float readExt(float raw);
|
|
|
|
|
2023-04-25 04:25:42 -04:00
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
// ANALYSE
|
2023-04-25 04:25:42 -04:00
|
|
|
bool isNull();
|
2022-12-02 06:52:49 -05:00
|
|
|
bool isNorth();
|
|
|
|
bool isSouth();
|
2023-09-20 13:16:07 -04:00
|
|
|
bool isRising();
|
|
|
|
bool isFalling();
|
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
float lastGauss();
|
|
|
|
float prevGauss();
|
2023-09-20 13:16:07 -04:00
|
|
|
float deltaGauss();
|
|
|
|
float angle(); // == atan2(prevGauss, lastGauss);
|
|
|
|
float determineNoise(uint8_t times = 2); // in Gauss
|
|
|
|
|
2022-12-02 06:52:49 -05:00
|
|
|
|
2023-04-25 04:25:42 -04:00
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
// CONVERTERs
|
|
|
|
float Tesla(float Gauss);
|
|
|
|
float mTesla(float Gauss);
|
|
|
|
float uTesla(float Gauss);
|
|
|
|
|
2023-04-25 04:25:42 -04:00
|
|
|
|
|
|
|
// SATURATION LEVEL = EXPERIMENTAL
|
2022-12-02 06:52:49 -05:00
|
|
|
// manual override default maxGauss
|
2023-04-25 04:25:42 -04:00
|
|
|
void setMaxGauss(float maxGauss);
|
2022-12-02 06:52:49 -05:00
|
|
|
float getMaxGauss();
|
|
|
|
bool isSaturated();
|
2023-04-25 04:25:42 -04:00
|
|
|
float saturationLevel();
|
2022-12-02 06:52:49 -05:00
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
|
|
|
|
protected:
|
2023-04-25 04:25:42 -04:00
|
|
|
uint8_t _pin;
|
|
|
|
float _midPoint;
|
|
|
|
float _prevGauss;
|
|
|
|
float _lastGauss;
|
2023-09-20 13:16:07 -04:00
|
|
|
float _GaussmV; // == 1.0 / mVGauss
|
2023-04-25 04:25:42 -04:00
|
|
|
float _mVStep;
|
|
|
|
uint16_t _maxADC;
|
2023-09-20 13:16:07 -04:00
|
|
|
|
2022-12-02 06:52:49 -05:00
|
|
|
// Experimental
|
2023-04-25 04:25:42 -04:00
|
|
|
float _maxGauss;
|
2022-12-02 04:37:37 -05:00
|
|
|
};
|
|
|
|
|
2023-04-25 04:25:42 -04:00
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
////////////////////////////////////////////////////
|
|
|
|
//
|
2024-04-19 13:37:04 -04:00
|
|
|
// DERIVED CLASSES
|
2022-12-02 04:37:37 -05:00
|
|
|
//
|
|
|
|
class A1301 : public HALL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
A1301(uint8_t pin);
|
|
|
|
};
|
|
|
|
|
|
|
|
class A1302 : public HALL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
A1302(uint8_t pin);
|
|
|
|
};
|
|
|
|
|
2022-12-02 06:52:49 -05:00
|
|
|
class A1324 : public HALL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
A1324(uint8_t pin);
|
|
|
|
};
|
|
|
|
|
|
|
|
class A1325 : public HALL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
A1325(uint8_t pin);
|
|
|
|
};
|
|
|
|
|
|
|
|
class A1326 : public HALL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
A1326(uint8_t pin);
|
|
|
|
};
|
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|