feat: 全量同步 254 个常用的 Arduino 扩展库文件
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
build:
|
||||
tags:
|
||||
- nas
|
||||
script:
|
||||
- wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh
|
||||
- chmod +x seeed-arduino-ci.sh
|
||||
- bash $PWD/seeed-arduino-ci.sh test
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
language: generic
|
||||
dist: bionic
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- ~/arduino_ide
|
||||
- ~/.arduino15/packages/
|
||||
|
||||
before_install:
|
||||
- wget -c https://files.seeedstudio.com/arduino/seeed-arduino-ci.sh
|
||||
|
||||
script:
|
||||
- chmod +x seeed-arduino-ci.sh
|
||||
- cat $PWD/seeed-arduino-ci.sh
|
||||
- bash $PWD/seeed-arduino-ci.sh test
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: change
|
||||
@@ -0,0 +1,76 @@
|
||||
# Contributor Covenant Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, sex characteristics, gender identity and expression,
|
||||
level of experience, education, socio-economic status, nationality, personal
|
||||
appearance, race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
## Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at zuobaozhu@gmail.com. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
## Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
||||
|
||||
[homepage]: https://www.contributor-covenant.org
|
||||
|
||||
For answers to common questions about this code of conduct, see
|
||||
https://www.contributor-covenant.org/faq
|
||||
@@ -0,0 +1,3 @@
|
||||
## Contributing guidelines
|
||||
|
||||
All guidelines for contributing to the Seeed_Arduino_LIS3DHTR repository can be found at [`How to contribute guideline`](https://github.com/Seeed-Studio/Seeed_Arduino_LIS3DHTR/wiki/How_to_contribute).
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Seeed Studio
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -0,0 +1,181 @@
|
||||
# Seeed_Arduino_LIS3DHTR [](https://travis-ci.com/Seeed-Studio/Seeed_Arduino_LIS3DHTR)
|
||||
## Introduction
|
||||
An Arduino library for 3-Axis Digital Accelerometer ±2g to 16g (LIS3DHTR).Acceleration data can be obtained using IIC interface and SPI interface.
|
||||
## How to install Arduino Library
|
||||
please refer [here](https://wiki.seeedstudio.com/How_to_install_Arduino_Library/).
|
||||
|
||||
## Usage
|
||||
|
||||
```C++
|
||||
// This example use I2C.
|
||||
#include "LIS3DHTR.h"
|
||||
#include <Wire.h>
|
||||
LIS3DHTR<TwoWire> LIS; //IIC
|
||||
#define WIRE Wire
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
{
|
||||
};
|
||||
LIS.begin(WIRE, LIS3DHTR_ADDRESS_UPDATED); //IIC init
|
||||
delay(100);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
if (!LIS)
|
||||
{
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1)
|
||||
;
|
||||
return;
|
||||
}
|
||||
//3 axis
|
||||
Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print(" ");
|
||||
Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print(" ");
|
||||
Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
- **begin(*comm\<TwoWire\>, address\<uint8_t\>=0x18*) : void**
|
||||
```C++
|
||||
// Init device by IIC
|
||||
LIS3DHTR<TwoWire> LIS; //IIC
|
||||
LIS.begin(Wire, 0x19)
|
||||
```
|
||||
|
||||
- **begin(*comm\<SPIClass\>, sspin\<uint8_t\>=SS*) : void**
|
||||
```C++
|
||||
// Init device by SPI
|
||||
LIS3DHTR<SPIClass> LIS; //SPI
|
||||
LIS.begin(SPI, 10); //SPI SS/CS
|
||||
```
|
||||
|
||||
- **setPoweMode(*mode\<power_type_t\>*) : void**
|
||||
```C++
|
||||
// Set power mode
|
||||
LIS.setPoweMode(POWER_MODE_NORMAL); // Normal mode
|
||||
LIS.setPoweMode(POWER_MODE_LOW); // Low power mode
|
||||
```
|
||||
|
||||
- **setFullScaleRange(*range\<scale_type_t\>*) : void**
|
||||
```C++
|
||||
// Set Full scale
|
||||
LIS.setFullScaleRange(LIS3DHTR_RANGE_2G); // 2G
|
||||
LIS.setFullScaleRange(LIS3DHTR_RANGE_4G); // 4G
|
||||
LIS.setFullScaleRange(LIS3DHTR_RANGE_8G); // 8G
|
||||
LIS.setFullScaleRange(LIS3DHTR_RANGE_16G); // 16G
|
||||
```
|
||||
|
||||
- **setOutputDataRate(*odr\<odr_type_t\>*) : void**
|
||||
```C++
|
||||
// Set output data rate
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_POWERDOWN); // Power down
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ); // 1HZ
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ); // 10HZ
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ); // 25HZ
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ); // 50HZ
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ); // 100HZ
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ); // 200HZ
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_400HZ); // 400HZ
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KH); // 1.6kHZ
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ); // 5KHZ
|
||||
```
|
||||
|
||||
- **available(*void*) : bool**
|
||||
```C++
|
||||
// if new data
|
||||
if(LIS.available){
|
||||
float x = LIS.getAccelerationX();
|
||||
}
|
||||
```
|
||||
|
||||
- **getAcceleration(*x\<float \*\>, y\<float \*\>, z\<float \*\>*) : void**
|
||||
```C++
|
||||
// get acceleration
|
||||
float x, y, z;
|
||||
LIS.getAcceleration(&x, &y, &z);
|
||||
```
|
||||
|
||||
- **getAccelerationX(*void*) : float**
|
||||
```C++
|
||||
// get acceleration x
|
||||
float x = LIS.getAccelerationX();
|
||||
```
|
||||
|
||||
- **getAccelerationY(*void*) : float**
|
||||
```C++
|
||||
// get acceleration y
|
||||
float y = LIS.getAccelerationY();
|
||||
```
|
||||
|
||||
- **getAccelerationY(*void*) : float**
|
||||
```C++
|
||||
// get acceleration z
|
||||
float Z = LIS.getAccelerationZ();
|
||||
```
|
||||
|
||||
- **getTemperature(*void*) : int16_t**
|
||||
```C++
|
||||
// get temperature, you need to execute LIS.openTemp() before get temperature
|
||||
int16_t temp = LIS.getTemperature();
|
||||
```
|
||||
|
||||
- **openTemp(*void*) : void**
|
||||
```C++
|
||||
// open temperature enable
|
||||
LIS.openTemp();
|
||||
```
|
||||
|
||||
- **closeTemp(*void*) : void**
|
||||
```C++
|
||||
// close temperature enable
|
||||
LIS.closeTemp();
|
||||
```
|
||||
|
||||
- **readbitADC1(*void*) : uint16_t**
|
||||
```C++
|
||||
// read ADC1
|
||||
uint16_t adc1 = LIS.readbitADC1();
|
||||
```
|
||||
|
||||
- **readbitADC2(*void*) : uint16_t**
|
||||
```C++
|
||||
// read ADC2
|
||||
uint16_t adc2 = LIS.readbitADC2();
|
||||
```
|
||||
|
||||
- **readbitADC3(*void*) : uint16_t**
|
||||
```C++
|
||||
// read ADC3
|
||||
uint16_t adc3 = LIS.readbitADC3();
|
||||
```
|
||||
|
||||
- **reset(*void*) : void**
|
||||
```C++
|
||||
// reset device
|
||||
LIS.reset();
|
||||
```
|
||||
|
||||
|
||||
----
|
||||
## License
|
||||
This software is written by seeed studio<br>
|
||||
and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.<br>
|
||||
|
||||
Contributing to this software is warmly welcomed. You can do this basically by<br>
|
||||
[forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above<br>
|
||||
for operating guide). Adding change log and your contact into file header is encouraged.<br>
|
||||
Thanks for your contribution.
|
||||
|
||||
Seeed Studio is an open hardware facilitation company based in Shenzhen, China. <br>
|
||||
Benefiting from local manufacture power and convenient global logistic system, <br>
|
||||
we integrate resources to serve new era of innovation. Seeed also works with <br>
|
||||
global distributors and partners to push open hardware movement.<br>
|
||||
@@ -0,0 +1,54 @@
|
||||
// This example use I2C.
|
||||
#include "LIS3DHTR.h"
|
||||
#include <Wire.h>
|
||||
LIS3DHTR<TwoWire> LIS; //IIC
|
||||
#define WIRE Wire
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
{
|
||||
};
|
||||
LIS.begin(WIRE); //IIC init dafault :0x18
|
||||
//LIS.begin(WIRE, 0x19); //IIC init
|
||||
LIS.openTemp(); //If ADC3 is used, the temperature detection needs to be turned off.
|
||||
// LIS.closeTemp();//default
|
||||
delay(100);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
||||
LIS.setHighSolution(true); //High solution enable
|
||||
}
|
||||
void loop()
|
||||
{
|
||||
if (!LIS)
|
||||
{
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1)
|
||||
;
|
||||
return;
|
||||
}
|
||||
//3 axis
|
||||
// Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print(" ");
|
||||
// Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print(" ");
|
||||
// Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
|
||||
//ADC
|
||||
// Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
|
||||
// Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
|
||||
// Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
|
||||
|
||||
//temperature
|
||||
Serial.print("temp:");
|
||||
Serial.println(LIS.getTemperature());
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// This example USES the ADC function.
|
||||
#include "LIS3DHTR.h"
|
||||
#include <Wire.h>
|
||||
LIS3DHTR<TwoWire> LIS; //IIC
|
||||
#define WIRE Wire
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial) {};
|
||||
LIS.begin(WIRE); //IIC init dafault :0x18
|
||||
//LIS.begin(WIRE, 0x19); //IIC init
|
||||
delay(100);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
||||
LIS.setHighSolution(true); //High solution enable
|
||||
}
|
||||
void loop() {
|
||||
if (!LIS) {
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
//ADC
|
||||
Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
|
||||
Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
|
||||
Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// This example shows the 3 axis acceleration.
|
||||
#include "LIS3DHTR.h"
|
||||
#include <Wire.h>
|
||||
LIS3DHTR<TwoWire> LIS; //IIC
|
||||
#define WIRE Wire
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial) {};
|
||||
LIS.begin(WIRE); //IIC init dafault :0x18
|
||||
//LIS.begin(WIRE, 0x19); //IIC init
|
||||
delay(100);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
||||
LIS.setHighSolution(true); //High solution enable
|
||||
}
|
||||
void loop() {
|
||||
if (!LIS) {
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
//3 axis
|
||||
Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print(" ");
|
||||
Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print(" ");
|
||||
Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
|
||||
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//This example show the temperature.
|
||||
// if you use the software I2C to drive the sensor, you can uncommnet the define SOFTWAREWIRE which in LIS3DHTR.h.
|
||||
|
||||
#include "LIS3DHTR.h"
|
||||
#ifdef SOFTWAREWIRE
|
||||
#include <SoftwareWire.h>
|
||||
SoftwareWire myWire(3, 2);
|
||||
LIS3DHTR<SoftwareWire> LIS;//IIC
|
||||
#define WIRE myWire
|
||||
#else
|
||||
#include <Wire.h>
|
||||
LIS3DHTR<TwoWire> LIS;//IIC
|
||||
#define WIRE Wire
|
||||
#endif
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial) {};
|
||||
LIS.begin(WIRE); //IIC init
|
||||
LIS.openTemp();////If ADC3 is used, the temperature detection needs to be turned off.
|
||||
// LIS.closeTemp();//default
|
||||
delay(100);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (!LIS) {
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
//temperature
|
||||
Serial.print("temp:"); Serial.println(LIS.getTemperature());
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// This example use SPI.
|
||||
|
||||
#include "LIS3DHTR.h"
|
||||
#include "SPI.h"
|
||||
LIS3DHTR<SPIClass> LIS; //SPI
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
LIS.begin(SPI,10); //SPI SS/CS
|
||||
LIS.openTemp();//If ADC3 is used, the temperature detection needs to be turned off.
|
||||
// LIS.closeTemp();//default
|
||||
delay(100);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
||||
}
|
||||
void loop() {
|
||||
if (!LIS) {
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
//3 Axis
|
||||
// Serial.print("x:");Serial.print(LIS.getAccelerationX());Serial.print(" ");
|
||||
// Serial.print("y:");Serial.print(LIS.getAccelerationY());Serial.print(" ");
|
||||
// Serial.print("z:");Serial.println(LIS.getAccelerationZ());
|
||||
//ADC
|
||||
// Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
|
||||
// Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
|
||||
// Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
|
||||
//temperature
|
||||
Serial.print("temp:"); Serial.println(LIS.getTemperature());
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// This example USES the ADC function.
|
||||
|
||||
#include "LIS3DHTR.h"
|
||||
LIS3DHTR<TwoWire> LIS; //SPI
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
LIS.begin(SPI, 10); //SPI SS/CS
|
||||
delay(100);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
||||
}
|
||||
void loop() {
|
||||
if (!LIS) {
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
//ADC
|
||||
Serial.print("adc1:"); Serial.println(LIS.readbitADC1());
|
||||
Serial.print("adc2:"); Serial.println(LIS.readbitADC2());
|
||||
Serial.print("adc3:"); Serial.println(LIS.readbitADC3());
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// This example shows the 3 axis acceleration.
|
||||
|
||||
#include "LIS3DHTR.h"
|
||||
LIS3DHTR<TwoWire> LIS; //SPI
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
LIS.begin(SPI, 10); //SPI SS/CS
|
||||
delay(100);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
||||
}
|
||||
void loop() {
|
||||
if (!LIS) {
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
//3 Axis
|
||||
Serial.print("x:"); Serial.print(LIS.getAccelerationX()); Serial.print(" ");
|
||||
Serial.print("y:"); Serial.print(LIS.getAccelerationY()); Serial.print(" ");
|
||||
Serial.print("z:"); Serial.println(LIS.getAccelerationZ());
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
//This example show the temperature.
|
||||
|
||||
#include "LIS3DHTR.h"
|
||||
#include "SPI.h"
|
||||
LIS3DHTR<SPIClass> LIS; //SPI
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
LIS.begin(SPI, 10); //SPI SS/CS
|
||||
LIS.openTemp();////If ADC3 is used, the temperature detection needs to be turned off.
|
||||
// LIS.closeTemp();//default
|
||||
delay(100);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_2G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_4G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_8G);
|
||||
// LIS.setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_10HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_25HZ);
|
||||
LIS.setOutputDataRate(LIS3DHTR_DATARATE_50HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_100HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_200HZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_1_6KHZ);
|
||||
// LIS.setOutputDataRate(LIS3DHTR_DATARATE_5KHZ);
|
||||
}
|
||||
void loop() {
|
||||
if (!LIS) {
|
||||
Serial.println("LIS3DHTR didn't connect.");
|
||||
while (1);
|
||||
return;
|
||||
}
|
||||
//temperature
|
||||
Serial.print("temp:"); Serial.println(LIS.getTemperature());
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
LIS3DHTR KEYWORD1
|
||||
|
||||
isConnection KEYWORD2
|
||||
begin KEYWORD2
|
||||
setPowerMode KEYWORD2
|
||||
setFullScaleRange KEYWORD2
|
||||
setOutputDataRate KEYWORD2
|
||||
setHighSolution KEYWORD2
|
||||
getAcceleration KEYWORD2
|
||||
getAccelerationX KEYWORD2
|
||||
getAccelerationY KEYWORD2
|
||||
getAccelerationZ KEYWORD2
|
||||
click KEYWORD2
|
||||
openTemp KEYWORD2
|
||||
closeTemp KEYWORD2
|
||||
readbitADC1 KEYWORD2
|
||||
readbitADC2 KEYWORD2
|
||||
readbitADC3 KEYWORD2
|
||||
getTemperature KEYWORD2
|
||||
getDeviceID KEYWORD2
|
||||
reset KEYWORD2
|
||||
@@ -0,0 +1,9 @@
|
||||
name=Grove-3-Axis-Digital-Accelerometer-2g-to-16g-LIS3DHTR
|
||||
version=1.2.3
|
||||
author=Seeed Studio
|
||||
maintainer=Seeed Studio <techsupport@seeed.cc>
|
||||
sentence=Library for Grove - 3-Axis Digital Accelerometer ±2g to 16g Power(LIS3DHTR).
|
||||
paragraph=An Arduino Library for Grove - 3-Axis Digital Accelerometer ±2g to 16g (LIS3DHTR) use to get acceleration data.
|
||||
category=Sensors
|
||||
url=https://github.com/Seeed-Studio/Seeed_Arduino_LIS3DHTR
|
||||
architectures=*
|
||||
@@ -0,0 +1,489 @@
|
||||
/*
|
||||
* A library for Grove - 3-Axis Digital Accelerometer ±2g to 16g Ultra-low Power(LIS3DHTR)
|
||||
*
|
||||
* Copyright (c) 2019 seeed technology co., ltd.
|
||||
* Author : Hongtai Liu (lht856@foxmail.com)
|
||||
* Create Time : July 2019
|
||||
* Change Log :
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software istm
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INcommInterface
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "LIS3DHTR.h"
|
||||
template <class T>
|
||||
|
||||
LIS3DHTR<T>::LIS3DHTR()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::begin(SPIClass &comm, uint8_t sspin)
|
||||
{
|
||||
chipSelectPin = sspin;
|
||||
_spi_com = &comm;
|
||||
_wire_com = NULL;
|
||||
pinMode(chipSelectPin, OUTPUT);
|
||||
digitalWrite(chipSelectPin, HIGH);
|
||||
// start the SPI library:
|
||||
_spi_com->begin();
|
||||
// Maximum SPI frequency is 10MHz, could divide by 2 here:
|
||||
_spi_com->setClockDivider(SPI_CLOCK_DIV4);
|
||||
// Data is read and written MSb first.
|
||||
_spi_com->setBitOrder(MSBFIRST);
|
||||
// Data is captured on rising edge of clock (CPHA = 0)
|
||||
// Base value of the clock is HIGH (CPOL = 1)
|
||||
// MODE3 for 328p operation
|
||||
_spi_com->setDataMode(SPI_MODE3);
|
||||
|
||||
delay(200);
|
||||
|
||||
uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
|
||||
LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
|
||||
uint8_t config1 = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL | // Normal Mode
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE | // Acceleration Z-Axis Enabled
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE | // Acceleration Y-Axis Enabled
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, config1);
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
|
||||
uint8_t config4 = LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED | // Continuous Update
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB | // Data LSB @ lower address
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE | // High Resolution Disable
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL | // Normal Mode
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE; // 4-Wire Interface
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4, config4);
|
||||
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
|
||||
setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
setOutputDataRate(LIS3DHTR_DATARATE_400HZ);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::begin(TwoWire &wire, uint8_t address)
|
||||
{
|
||||
_wire_com = &wire;
|
||||
_wire_com->begin();
|
||||
_spi_com = NULL;
|
||||
devAddr = address;
|
||||
|
||||
uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
|
||||
LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
|
||||
uint8_t config1 = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL | // Normal Mode
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE | // Acceleration Z-Axis Enabled
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE | // Acceleration Y-Axis Enabled
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, config1);
|
||||
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
|
||||
uint8_t config4 = LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED | // Continuous Update
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB | // Data LSB @ lower address
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE | // High Resolution Disable
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL | // Normal Mode
|
||||
LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE; // 4-Wire Interface
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4, config4);
|
||||
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
|
||||
setFullScaleRange(LIS3DHTR_RANGE_16G);
|
||||
setOutputDataRate(LIS3DHTR_DATARATE_400HZ);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool LIS3DHTR<T>::available()
|
||||
{
|
||||
uint8_t status = 0;
|
||||
status = readRegister(LIS3DHTR_REG_ACCEL_STATUS2);
|
||||
status &= LIS3DHTR_REG_ACCEL_STATUS2_UPDATE_MASK;
|
||||
return status;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::openTemp()
|
||||
{
|
||||
uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
|
||||
LIS3DHTR_REG_TEMP_TEMP_EN_ENABLED;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::closeTemp()
|
||||
{
|
||||
uint8_t config5 = LIS3DHTR_REG_TEMP_ADC_PD_ENABLED |
|
||||
LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_TEMP_CFG, config5);
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int16_t LIS3DHTR<T>::getTemperature(void)
|
||||
{
|
||||
int16_t result = ((int16_t)readRegisterInt16(0x0c)) / 256;
|
||||
result += 25;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool LIS3DHTR<T>::isConnection(void)
|
||||
{
|
||||
return (getDeviceID() == 0x33);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
uint8_t LIS3DHTR<T>::getDeviceID(void)
|
||||
{
|
||||
return readRegister(LIS3DHTR_REG_ACCEL_WHO_AM_I);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::setPowerMode(power_type_t mode)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
|
||||
data = readRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1);
|
||||
|
||||
data &= ~LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_MASK;
|
||||
data |= mode;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, data);
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::setFullScaleRange(scale_type_t range)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
|
||||
data = readRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4);
|
||||
|
||||
data &= ~LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_MASK;
|
||||
data |= range;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4, data);
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
|
||||
switch (range)
|
||||
{
|
||||
case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G:
|
||||
accRange = 1280;
|
||||
break;
|
||||
case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G:
|
||||
accRange = 3968;
|
||||
break;
|
||||
case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G:
|
||||
accRange = 7282;
|
||||
break;
|
||||
case LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G:
|
||||
accRange = 16000;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::setOutputDataRate(odr_type_t odr)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
|
||||
data = readRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1);
|
||||
|
||||
data &= ~LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_MASK;
|
||||
data |= odr;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG1, data);
|
||||
delay(LIS3DHTR_CONVERSIONDELAY);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::getAcceleration(float *x, float *y, float *z)
|
||||
{
|
||||
// Read the Accelerometer
|
||||
uint8_t xAccelLo, xAccelHi, yAccelLo, yAccelHi, zAccelLo, zAccelHi;
|
||||
|
||||
// Read the Data
|
||||
// Reading the Low X-Axis Acceleration Data Register
|
||||
xAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_X_L);
|
||||
// Reading the High X-Axis Acceleration Data Register
|
||||
xAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_X_H);
|
||||
// Conversion of the result
|
||||
// 16-bit signed result for X-Axis Acceleration Data of LIS3DHTR
|
||||
*x = (float)((int16_t)((xAccelHi << 8) | xAccelLo)) / accRange;
|
||||
|
||||
// Reading the Low Y-Axis Acceleration Data Register
|
||||
yAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_Y_L);
|
||||
// Reading the High Y-Axis Acceleration Data Register
|
||||
yAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_Y_H);
|
||||
// Conversion of the result
|
||||
// 16-bit signed result for Y-Axis Acceleration Data of LIS3DHTR
|
||||
*y = (float)((int16_t)((yAccelHi << 8) | yAccelLo)) / accRange;
|
||||
|
||||
// Reading the Low Z-Axis Acceleration Data Register
|
||||
zAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_Z_L);
|
||||
// Reading the High Z-Axis Acceleration Data Register
|
||||
zAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_Z_H);
|
||||
// Conversion of the result
|
||||
// 16-bit signed result for Z-Axis Acceleration Data of LIS3DHTR
|
||||
*z = (float)((int16_t)((zAccelHi << 8)) | zAccelLo) / accRange;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
float LIS3DHTR<T>::getAccelerationX(void)
|
||||
{
|
||||
// Read the Accelerometer
|
||||
uint8_t xAccelLo, xAccelHi;
|
||||
int16_t x;
|
||||
|
||||
// Read the Data
|
||||
// Reading the Low X-Axis Acceleration Data Register
|
||||
xAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_X_L);
|
||||
// Reading the High X-Axis Acceleration Data Register
|
||||
xAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_X_H);
|
||||
// Conversion of the result
|
||||
// 16-bit signed result for X-Axis Acceleration Data of LIS3DHTR
|
||||
x = (int16_t)((xAccelHi << 8) | xAccelLo);
|
||||
|
||||
return (float)x / accRange;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
float LIS3DHTR<T>::getAccelerationY(void)
|
||||
{
|
||||
// Read the Accelerometer
|
||||
uint8_t yAccelLo, yAccelHi;
|
||||
int16_t y;
|
||||
|
||||
// Reading the Low Y-Axis Acceleration Data Register
|
||||
yAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_Y_L);
|
||||
// Reading the High Y-Axis Acceleration Data Register
|
||||
yAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_Y_H);
|
||||
// Conversion of the result
|
||||
// 16-bit signed result for Y-Axis Acceleration Data of LIS3DHTR
|
||||
y = (int16_t)((yAccelHi << 8) | yAccelLo);
|
||||
|
||||
return (float)y / accRange;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
float LIS3DHTR<T>::getAccelerationZ(void)
|
||||
{
|
||||
// Read the Accelerometer
|
||||
uint8_t zAccelLo, zAccelHi;
|
||||
int16_t z;
|
||||
|
||||
// Reading the Low Z-Axis Acceleration Data Register
|
||||
zAccelLo = readRegister(LIS3DHTR_REG_ACCEL_OUT_Z_L);
|
||||
// Reading the High Z-Axis Acceleration Data Register
|
||||
zAccelHi = readRegister(LIS3DHTR_REG_ACCEL_OUT_Z_H);
|
||||
// Conversion of the result
|
||||
// 16-bit signed result for Z-Axis Acceleration Data of LIS3DHTR
|
||||
z = (int16_t)((zAccelHi << 8) | zAccelLo);
|
||||
|
||||
return (float)z / accRange;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::setHighSolution(bool enable)
|
||||
{
|
||||
uint8_t data = 0;
|
||||
data = readRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4);
|
||||
|
||||
data = enable? data | LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_ENABLE : data & ~LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_ENABLE;
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG4, data);
|
||||
return;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
uint16_t LIS3DHTR<T>::readbitADC1(void)
|
||||
{
|
||||
uint8_t adc1_l, adc1_h;
|
||||
int16_t intTemp;
|
||||
uint16_t uintTemp;
|
||||
adc1_l = readRegister(0x08);
|
||||
adc1_h = readRegister(0x09);
|
||||
|
||||
intTemp = (int16_t)(adc1_h << 8) | adc1_l;
|
||||
intTemp = 0 - intTemp;
|
||||
uintTemp = intTemp + 32768;
|
||||
return uintTemp >> 6;
|
||||
}
|
||||
template <class T>
|
||||
uint16_t LIS3DHTR<T>::readbitADC2(void)
|
||||
{
|
||||
uint8_t adc2_l, adc2_h;
|
||||
int16_t intTemp;
|
||||
uint16_t uintTemp;
|
||||
adc2_l = readRegister(0x0A);
|
||||
adc2_h = readRegister(0x0B);
|
||||
intTemp = (int16_t)(adc2_h << 8) | adc2_l;
|
||||
intTemp = 0 - intTemp;
|
||||
uintTemp = intTemp + 32768;
|
||||
return uintTemp >> 6;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
uint16_t LIS3DHTR<T>::readbitADC3(void)
|
||||
{
|
||||
uint8_t adc3_l, adc3_h;
|
||||
int16_t intTemp;
|
||||
uint16_t uintTemp;
|
||||
adc3_l = readRegister(0x0C);
|
||||
adc3_h = readRegister(0x0D);
|
||||
|
||||
intTemp = (int16_t)(adc3_h << 8) | adc3_l;
|
||||
intTemp = 0 - intTemp;
|
||||
uintTemp = intTemp + 32768;
|
||||
return uintTemp >> 6;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::writeRegister(uint8_t reg, uint8_t val)
|
||||
{
|
||||
if (_spi_com != NULL)
|
||||
{
|
||||
digitalWrite(chipSelectPin, LOW);
|
||||
_spi_com->transfer(reg);
|
||||
_spi_com->transfer(val);
|
||||
digitalWrite(chipSelectPin, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
_wire_com->beginTransmission(devAddr);
|
||||
_wire_com->write(reg);
|
||||
_wire_com->write(val);
|
||||
_wire_com->endTransmission();
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::readRegisterRegion(uint8_t *outputPointer, uint8_t reg, uint8_t length)
|
||||
{
|
||||
|
||||
//define pointer that will point to the external space
|
||||
uint8_t i = 0;
|
||||
uint8_t c = 0;
|
||||
uint8_t tempFFCounter = 0;
|
||||
|
||||
if (_spi_com != NULL)
|
||||
{
|
||||
digitalWrite(chipSelectPin, LOW);
|
||||
_spi_com->transfer(reg | 0x80 | 0x40); //Ored with "read request" bit and "auto increment" bit
|
||||
while (i < length) // slave may send less than requested
|
||||
{
|
||||
c = _spi_com->transfer(0x00); // receive a byte as character
|
||||
*outputPointer = c;
|
||||
outputPointer++;
|
||||
i++;
|
||||
}
|
||||
digitalWrite(chipSelectPin, HIGH);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
_wire_com->beginTransmission(devAddr);
|
||||
reg |= 0x80; //turn auto-increment bit on, bit 7 for I2C
|
||||
_wire_com->write(reg);
|
||||
_wire_com->endTransmission();
|
||||
_wire_com->requestFrom(devAddr, length);
|
||||
|
||||
while ((_wire_com->available()) && (i < length)) // slave may send less than requested
|
||||
{
|
||||
c = _wire_com->read(); // receive a byte as character
|
||||
*outputPointer = c;
|
||||
outputPointer++;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <class T>
|
||||
uint16_t LIS3DHTR<T>::readRegisterInt16(uint8_t reg)
|
||||
{
|
||||
|
||||
uint8_t myBuffer[2];
|
||||
readRegisterRegion(myBuffer, reg, 2);
|
||||
uint16_t output = myBuffer[0] | uint16_t(myBuffer[1] << 8);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
uint8_t LIS3DHTR<T>::readRegister(uint8_t reg)
|
||||
{
|
||||
uint8_t data;
|
||||
|
||||
readRegisterRegion(&data, reg, 1);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void LIS3DHTR<T>::click(uint8_t c, uint8_t click_thresh, uint8_t limit, uint8_t latency, uint8_t window)
|
||||
{
|
||||
if (!c)
|
||||
{
|
||||
uint8_t r = readRegister(LIS3DHTR_REG_ACCEL_CTRL_REG3);
|
||||
r &= ~(0x80); // turn off I1_CLICK
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG3, r);
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CLICK_CFG, 0);
|
||||
return;
|
||||
}
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG3, 0x80);
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CTRL_REG5, 0x08);
|
||||
|
||||
if (c == 1)
|
||||
{
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CLICK_CFG, 0x15);
|
||||
}
|
||||
if (c == 2)
|
||||
{
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CLICK_CFG, 0x2A);
|
||||
}
|
||||
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_CLICK_THS, click_thresh);
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_TIME_LIMIT, limit);
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_TIME_LATENCY, latency);
|
||||
writeRegister(LIS3DHTR_REG_ACCEL_TIME_WINDOW, window);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
LIS3DHTR<T>::operator bool() { return isConnection(); }
|
||||
|
||||
template class LIS3DHTR<SPIClass>;
|
||||
template class LIS3DHTR<TwoWire>;
|
||||
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Author: Hongtai Liu (lht856@foxmail.com)
|
||||
|
||||
Copyright (C) 2019 Seeed Technology Co.,Ltd.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
|
||||
|
||||
#ifndef SEEED_LIS3DHTR_H
|
||||
#define SEEED_LIS3DHTR_H
|
||||
|
||||
/**************************************************************************
|
||||
I2C ADDRESS/BITS
|
||||
**************************************************************************/
|
||||
#define LIS3DHTR_DEFAULT_ADDRESS (0x18) // 3C >> 1 = 7-bit default
|
||||
#define LIS3DHTR_ADDRESS_UPDATED (0x19) //
|
||||
|
||||
/**************************************************************************
|
||||
CONVERSION DELAY (in mS)
|
||||
**************************************************************************/
|
||||
#define LIS3DHTR_CONVERSIONDELAY (100)
|
||||
|
||||
/**************************************************************************
|
||||
ACCELEROMETER REGISTERS
|
||||
**************************************************************************/
|
||||
#define LIS3DHTR_REG_ACCEL_STATUS (0x07) // Status Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_ADC1_L (0x28) // 1-Axis Acceleration Data Low Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_ADC1_H (0x29) // 1-Axis Acceleration Data High Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_ADC2_L (0x2A) // 2-Axis Acceleration Data Low Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_ADC2_H (0x2B) // 2-Axis Acceleration Data High Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_ADC3_L (0x2C) // 3-Axis Acceleration Data Low Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_ADC3_H (0x2D) // 3-Axis Acceleration Data High Register
|
||||
#define LIS3DHTR_REG_ACCEL_WHO_AM_I (0x0F) // Device identification Register
|
||||
#define LIS3DHTR_REG_TEMP_CFG (0x1F) // Temperature Sensor Register
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1 (0x20) // Accelerometer Control Register 1
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG2 (0x21) // Accelerometer Control Register 2
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG3 (0x22) // Accelerometer Control Register 3
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4 (0x23) // Accelerometer Control Register 4
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG5 (0x24) // Accelerometer Control Register 5
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG6 (0x25) // Accelerometer Control Register 6
|
||||
#define LIS3DHTR_REG_ACCEL_REFERENCE (0x26) // Reference/Datacapture Register
|
||||
#define LIS3DHTR_REG_ACCEL_STATUS2 (0x27) // Status Register 2
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_X_L (0x28) // X-Axis Acceleration Data Low Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_X_H (0x29) // X-Axis Acceleration Data High Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_Y_L (0x2A) // Y-Axis Acceleration Data Low Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_Y_H (0x2B) // Y-Axis Acceleration Data High Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_Z_L (0x2C) // Z-Axis Acceleration Data Low Register
|
||||
#define LIS3DHTR_REG_ACCEL_OUT_Z_H (0x2D) // Z-Axis Acceleration Data High Register
|
||||
#define LIS3DHTR_REG_ACCEL_FIFO_CTRL (0x2E) // FIFO Control Register
|
||||
#define LIS3DHTR_REG_ACCEL_FIFO_SRC (0x2F) // FIFO Source Register
|
||||
#define LIS3DHTR_REG_ACCEL_INT1_CFG (0x30) // Interrupt Configuration Register
|
||||
#define LIS3DHTR_REG_ACCEL_INT1_SRC (0x31) // Interrupt Source Register
|
||||
#define LIS3DHTR_REG_ACCEL_INT1_THS (0x32) // Interrupt Threshold Register
|
||||
#define LIS3DHTR_REG_ACCEL_INT1_DURATION (0x33) // Interrupt Duration Register
|
||||
#define LIS3DHTR_REG_ACCEL_CLICK_CFG (0x38) // Interrupt Click Recognition Register
|
||||
#define LIS3DHTR_REG_ACCEL_CLICK_SRC (0x39) // Interrupt Click Source Register
|
||||
#define LIS3DHTR_REG_ACCEL_CLICK_THS (0x3A) // Interrupt Click Threshold Register
|
||||
#define LIS3DHTR_REG_ACCEL_TIME_LIMIT (0x3B) // Click Time Limit Register
|
||||
#define LIS3DHTR_REG_ACCEL_TIME_LATENCY (0x3C) // Click Time Latency Register
|
||||
#define LIS3DHTR_REG_ACCEL_TIME_WINDOW (0x3D) // Click Time Window Register
|
||||
|
||||
/**************************************************************************
|
||||
TEMPERATURE REGISTER DESCRIPTION
|
||||
**************************************************************************/
|
||||
#define LIS3DHTR_REG_TEMP_ADC_PD_MASK (0x80) // ADC Power Enable Status
|
||||
#define LIS3DHTR_REG_TEMP_ADC_PD_DISABLED (0x00) // ADC Disabled
|
||||
#define LIS3DHTR_REG_TEMP_ADC_PD_ENABLED (0x80) // ADC Enabled
|
||||
|
||||
#define LIS3DHTR_REG_TEMP_TEMP_EN_MASK (0x40) // Temperature Sensor (T) Enable Status
|
||||
#define LIS3DHTR_REG_TEMP_TEMP_EN_DISABLED (0x00) // Temperature Sensor (T) Disabled
|
||||
#define LIS3DHTR_REG_TEMP_TEMP_EN_ENABLED (0x40) // Temperature Sensor (T) Enabled
|
||||
|
||||
/**************************************************************************
|
||||
ACCELEROMETER CONTROL REGISTER 1 DESCRIPTION
|
||||
**************************************************************************/
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_MASK (0xF0) // Acceleration Data Rate Selection
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_PD (0x00) // Power-Down Mode
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1 (0x10) // Normal / Low Power Mode (1 Hz)
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_10 (0x20) // Normal / Low Power Mode (10 Hz)
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_25 (0x30) // Normal / Low Power Mode (25 Hz)
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_50 (0x40) // Normal / Low Power Mode (50 Hz)
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_100 (0x50) // Normal / Low Power Mode (100 Hz)
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_200 (0x60) // Normal / Low Power Mode (200 Hz)
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_400 (0x70) // Normal / Low Power Mode (400 Hz)
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1_6K (0x80) // Low Power Mode (1.6 KHz)
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_5K (0x90) // Normal (1.25 KHz) / Low Power Mode (5 KHz)
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_MASK (0x08) // Low Power Mode Enable
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL (0x00) // Normal Mode
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_LOW (0x08) // Low Power Mode
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_MASK (0x04) // Acceleration Z-Axis Enable
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_DISABLE (0x00) // Acceleration Z-Axis Disabled
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AZEN_ENABLE (0x04) // Acceleration Z-Axis Enabled
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_MASK (0x02) // Acceleration Y-Axis Enable
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_DISABLE (0x00) // Acceleration Y-Axis Disabled
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AYEN_ENABLE (0x02) // Acceleration Y-Axis Enabled
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_MASK (0x01) // Acceleration X-Axis Enable
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_DISABLE (0x00) // Acceleration X-Axis Disabled
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG1_AXEN_ENABLE (0x01) // Acceleration X-Axis Enabled
|
||||
|
||||
/**************************************************************************
|
||||
ACCELEROMETER CONTROL REGISTER 4 DESCRIPTION
|
||||
**************************************************************************/
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_MASK (0x80) // Block Data Update
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_CONTINUOUS (0x00) // Continuous Update
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BDU_NOTUPDATED (0x80) // Output Registers Not Updated until MSB and LSB Read
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_MASK (0x40) // Big/Little Endian Data Selection
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_LSB (0x00) // Data LSB @ lower address
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_BLE_MSB (0x40) // Data MSB @ lower address
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_MASK (0x30) // Full-Scale Selection
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G (0x00) // +/- 2G
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G (0x10) // +/- 4G
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G (0x20) // +/- 8G
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G (0x30) // +/- 16G
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_MASK (0x08) // High Resolution Output Mode
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_DISABLE (0x00) // High Resolution Disable
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_HS_ENABLE (0x08) // High Resolution Enable
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_MASK (0x06) // Self-Test Enable
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_NORMAL (0x00) // Normal Mode
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_0 (0x02) // Self-Test 0
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_ST_1 (0x04) // Self-Test 1
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_MASK (0x01) // SPI Serial Interface Mode Selection
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_4WIRE (0x00) // 4-Wire Interface
|
||||
#define LIS3DHTR_REG_ACCEL_CTRL_REG4_SIM_3WIRE (0x01) // 3-Wire Interface
|
||||
|
||||
#define LIS3DHTR_REG_ACCEL_STATUS2_UPDATE_MASK (0x08) // Has New Data Flag Mask
|
||||
|
||||
enum power_type_t // power mode
|
||||
{
|
||||
POWER_MODE_NORMAL = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_NORMAL,
|
||||
POWER_MODE_LOW = LIS3DHTR_REG_ACCEL_CTRL_REG1_LPEN_LOW
|
||||
};
|
||||
|
||||
enum scale_type_t // measurement rage
|
||||
{
|
||||
LIS3DHTR_RANGE_2G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_2G, //
|
||||
LIS3DHTR_RANGE_4G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_4G, //
|
||||
LIS3DHTR_RANGE_8G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_8G, //
|
||||
LIS3DHTR_RANGE_16G = LIS3DHTR_REG_ACCEL_CTRL_REG4_FS_16G, //
|
||||
};
|
||||
|
||||
enum odr_type_t // output data rate
|
||||
{
|
||||
LIS3DHTR_DATARATE_POWERDOWN = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_PD,
|
||||
LIS3DHTR_DATARATE_1HZ = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1,
|
||||
LIS3DHTR_DATARATE_10HZ = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_10,
|
||||
LIS3DHTR_DATARATE_25HZ = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_25,
|
||||
LIS3DHTR_DATARATE_50HZ = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_50,
|
||||
LIS3DHTR_DATARATE_100HZ = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_100,
|
||||
LIS3DHTR_DATARATE_200HZ = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_200,
|
||||
LIS3DHTR_DATARATE_400HZ = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_400,
|
||||
LIS3DHTR_DATARATE_1_6KH = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_1_6K,
|
||||
LIS3DHTR_DATARATE_5KHZ = LIS3DHTR_REG_ACCEL_CTRL_REG1_AODR_5K
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class LIS3DHTR
|
||||
{
|
||||
public:
|
||||
LIS3DHTR();
|
||||
|
||||
bool isConnection(void);
|
||||
|
||||
void begin(SPIClass &comm = SPI, uint8_t sspin = SS); //init
|
||||
void begin(TwoWire &comm = Wire, uint8_t address = LIS3DHTR_DEFAULT_ADDRESS); //init
|
||||
void begin(uint8_t address) { begin(Wire, address); };
|
||||
|
||||
|
||||
void setPowerMode(power_type_t mode);
|
||||
void setFullScaleRange(scale_type_t range);
|
||||
void setOutputDataRate(odr_type_t odr);
|
||||
void setHighSolution(bool enable);
|
||||
bool available();
|
||||
void getAcceleration(float *x, float *y, float *z);
|
||||
float getAccelerationX(void);
|
||||
float getAccelerationY(void);
|
||||
float getAccelerationZ(void);
|
||||
void click(uint8_t c, uint8_t click_thresh, uint8_t limit = 10, uint8_t latency = 20, uint8_t window = 255);
|
||||
|
||||
void openTemp();
|
||||
void closeTemp();
|
||||
|
||||
uint16_t readbitADC1(void);
|
||||
uint16_t readbitADC2(void);
|
||||
uint16_t readbitADC3(void);
|
||||
|
||||
int16_t getTemperature(void);
|
||||
|
||||
uint8_t getDeviceID(void);
|
||||
|
||||
void reset(void);
|
||||
operator bool();
|
||||
|
||||
private:
|
||||
void read(uint8_t reg, uint8_t *buf, uint16_t len);
|
||||
void readRegisterRegion(uint8_t *outputPointer, uint8_t offset, uint8_t length);
|
||||
void writeRegister(uint8_t reg, uint8_t val);
|
||||
uint8_t readRegister(uint8_t reg);
|
||||
uint16_t readRegisterInt16(uint8_t reg);
|
||||
uint8_t devAddr;
|
||||
int16_t accRange;
|
||||
uint8_t commInterface;
|
||||
uint8_t chipSelectPin;
|
||||
SPIClass *_spi_com;
|
||||
TwoWire *_wire_com;
|
||||
};
|
||||
|
||||
#endif /*SEEED_LIS3DHTR_H*/
|
||||
Reference in New Issue
Block a user