GY-63_MS5611/libraries/A1301/README.md

208 lines
6.2 KiB
Markdown
Raw Normal View History

2022-12-02 04:37:37 -05:00
[![Arduino CI](https://github.com/RobTillaart/A1301/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
[![Arduino-lint](https://github.com/RobTillaart/A1301/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/A1301/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/A1301/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/A1301/actions/workflows/jsoncheck.yml)
2023-09-20 13:16:07 -04:00
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/A1301.svg)](https://github.com/RobTillaart/A1301/issues)
2022-12-02 04:37:37 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/A1301/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/A1301.svg?maxAge=3600)](https://github.com/RobTillaart/A1301/releases)
2023-09-20 13:16:07 -04:00
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/A1301.svg)](https://registry.platformio.org/libraries/robtillaart/A1301)
2022-12-02 04:37:37 -05:00
# A1301
Arduino library for A1301 and A1302 magnetometer.
## Description
2023-04-25 04:25:42 -04:00
The A1301 and A1302 are continuous-time, Ratio-metric, linear Hall-effect sensors.
They are optimized to accurately provide a voltage output that is proportional to
an applied magnetic field.
These devices have a quiescent output voltage that is 50% of the supply voltage.
This voltage level is a.k.a. the midPoint.
Two output sensitivity options are provided: 2.5 mV/G typical for the A1301,
and 1.3 mV/G typical for the A1302. (from datasheet)
2022-12-02 04:37:37 -05:00
2022-12-02 06:52:49 -05:00
The following 5 classes are supported:
2022-12-02 04:37:37 -05:00
| sensor | sensitivity | support |
|:---------|:---------------:|:---------:|
| A1301 | 2.5 mV/Gauss | Y |
| A1302 | 1.3 mV/Gauss | Y |
2022-12-02 06:52:49 -05:00
| A1324 | 5.000 mV/Gauss | Y |
| A1325 | 3.125 mV/Gauss | Y |
| A1326 | 2.500 mV/Gauss | Y |
2022-12-02 04:37:37 -05:00
Other, more or less, compatible sensors are welcome.
2022-12-02 06:52:49 -05:00
(see future below.)
2022-12-02 04:37:37 -05:00
The library is experimental and need more testing.
Feedback, issues and improvements are welcome,
Please open an issue on GitHub.
## Connection
```
// always check datasheet.
2022-12-02 06:52:49 -05:00
//
2022-12-02 04:37:37 -05:00
// PIN A1301
// ===============
// 1 GND
// 2 DATA
// 3 VDD +5V
```
## Interface
2023-04-25 04:25:42 -04:00
```cpp
#include "A1301.h"
```
2022-12-02 04:37:37 -05:00
#### Constructor
- **HALL(uint8_t pin)** base class constructor.
pin is the analogPin to read from.
- **A1301(uint8_t pin)** constructor.
- **A1302(uint8_t pin)** constructor.
2022-12-02 06:52:49 -05:00
- **A1324(uint8_t pin)** constructor.
- **A1325(uint8_t pin)** constructor.
- **A1326(uint8_t pin)** constructor.
2022-12-02 04:37:37 -05:00
#### Configuration
- **void begin(float voltage, uint16_t steps)**
Sets the parameters voltage and number of steps of the internal ADC.
Note this allows to update the voltage runtime.
2023-09-20 13:16:07 -04:00
Steps must be larger than zero.
2022-12-02 04:37:37 -05:00
- **void setMidPoint(float midPoint)** the value of midPoint depends on the internal ADC.
It is the value where there is no (zero) magnetic field.
Note it does not need to be a whole value.
This allows quite precise tuning.
- **float getMidPoint()** returns the current midPoint.
- **void setSensitivity(float sensitivity)** overrule default sensitivity.
Use with care.
2023-09-20 13:16:07 -04:00
- **float getSensitivity()** return the set / current sensitivity.
2022-12-02 04:37:37 -05:00
#### Read
- **float raw(uint8_t times = 1)** raw analog measurement.
- **float read(uint8_t times = 1)** raw measurement converted to Gauss.
Can be positive (North) or negative (South).
2022-12-02 06:52:49 -05:00
Returns Gauss.
2022-12-02 04:37:37 -05:00
- **float readExt(float raw)** to be used with external ADC.
2022-12-02 06:52:49 -05:00
Note: **raw** is an ADC measurement, not a voltage.
2022-12-02 04:37:37 -05:00
Can be positive (North) or negative (South).
2022-12-02 06:52:49 -05:00
Returns Gauss.
2023-04-25 04:25:42 -04:00
Can also be used for testing, e.g. replay of a series of data.
2022-12-02 04:37:37 -05:00
#### Analyse
2023-09-20 13:16:07 -04:00
- **bool isNull()** last read is zero.
- **bool isNorth()** last read is above than zero.
- **bool isSouth()** last read is below zero.
- **bool isRising()** trend (last 2 reads) is upward.
- **bool isFalling()** trend (last 2 reads) is downward.
2022-12-02 04:37:37 -05:00
- **float lastGauss()** returns last measurement in Gauss.
- **float prevGauss()** returns previous measurement in Gauss.
2023-09-20 13:16:07 -04:00
- **float deltaGauss()** returns last - previous measurement.
Experimental.
- **float determineNoise(uint8_t times = 2)** estimates noise level
around measurements. **times** will be forced to be at least 2.
Does not affect lastGauss or prevGauss values.
- **float angle()** returns atan2(prevGauss, lastGauss).
Indicator of change.
Returns angle in radians. For degrees multiply by 180/PI.
2022-12-02 06:52:49 -05:00
2023-04-25 04:25:42 -04:00
#### Saturation.
2022-12-02 06:52:49 -05:00
2023-04-25 04:25:42 -04:00
Experimental saturation level.
- **void setMaxGauss(float maxGauss)** set the saturation level.
If maxGauss < 0 the absolute value is set.
- **float getMaxGauss()** returns the set saturation level.
- **bool isSaturated()** true when ADC (lastRead) seems to max out.
2023-09-20 13:16:07 -04:00
- **float saturationLevel()** returns value between 0..100%, or beyond!
2022-12-02 06:52:49 -05:00
#### Tesla
2022-12-02 04:37:37 -05:00
- **float Tesla(float Gauss)** convenience convertor.
- **float mTesla(float Gauss)** convenience convertor.
- **float uTesla(float Gauss)** convenience convertor.
## Operation
The examples show the basic working of the functions.
2022-12-02 06:52:49 -05:00
(to elaborate more examples)
2022-12-02 04:37:37 -05:00
## Future
#### Must
2023-04-25 04:25:42 -04:00
2022-12-02 04:37:37 -05:00
- improve documentation
2023-04-25 04:25:42 -04:00
- buy hardware A1301 / A1302 / etc...
2022-12-02 04:37:37 -05:00
- test with hardware (again)
2023-04-25 04:25:42 -04:00
2022-12-02 04:37:37 -05:00
#### Should
2023-04-25 04:25:42 -04:00
2022-12-02 04:37:37 -05:00
- unit tests
2023-04-25 04:25:42 -04:00
- test **isSaturated()** + **saturationLevel()**
2022-12-02 06:52:49 -05:00
- limits might be sensor dependant.
2023-09-20 13:16:07 -04:00
- investigate **atan2(prevGauss, lastGauss)**
- angle indicates relative delta compared to magnitude and direction.
- 45 & 315 degrees is no change.
2023-04-25 04:25:42 -04:00
2022-12-02 04:37:37 -05:00
#### Could
2023-04-25 04:25:42 -04:00
- **float findZero()** how exactly => ACS712 **autoMidPoint()**
- add examples.
- performance read()
2022-12-02 04:37:37 -05:00
- Possible compatible
- HoneyWell - SS39ET/SS49E/SS59ET
- HoneyWell - SS490 Series
2023-04-25 04:25:42 -04:00
- temperature correction functions?
- see datasheet.
#### Ideas
(thinking out loud section)
- isEast() and isWest() meaning?
- influence of angle of the field-lines?
- defaults for parameters of some functions?
2022-12-02 04:37:37 -05:00
#### Won't
2023-04-25 04:25:42 -04:00
- printable interface
- does not add much.
2023-09-20 13:16:07 -04:00
- can the strength of the signal be converted to distance?
- for a given magnet maybe
- repeatability + noise is a problem.
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,