初始化提交
This commit is contained in:
178
arduino-cli/libraries/Adafruit_MLX90614/Adafruit_MLX90614.cpp
Normal file
178
arduino-cli/libraries/Adafruit_MLX90614/Adafruit_MLX90614.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/***************************************************
|
||||
This is a library for the MLX90614 Temp Sensor
|
||||
|
||||
Designed specifically to work with the MLX90614 sensors in the
|
||||
adafruit shop
|
||||
----> https://www.adafruit.com/products/1748
|
||||
----> https://www.adafruit.com/products/1749
|
||||
|
||||
These sensors use I2C to communicate, 2 pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include "Adafruit_MLX90614.h"
|
||||
/**
|
||||
* @brief Construct a new Adafruit_MLX90614::Adafruit_MLX90614 object
|
||||
*
|
||||
* @param i2caddr The I2C address to use. Defaults to 0x5A
|
||||
*/
|
||||
Adafruit_MLX90614::Adafruit_MLX90614(uint8_t i2caddr) { _addr = i2caddr; }
|
||||
/**
|
||||
* @brief Begin the I2C connection
|
||||
*
|
||||
* @return bool Always returns true
|
||||
*/
|
||||
bool Adafruit_MLX90614::begin(void) {
|
||||
Wire.begin();
|
||||
|
||||
/*
|
||||
for (uint8_t i=0; i<0x20; i++) {
|
||||
Serial.print(i); Serial.print(" = ");
|
||||
Serial.println(read16(i), HEX);
|
||||
}
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read the raw value from the emissivity register
|
||||
*
|
||||
* @return uint16_t The unscaled emissivity value
|
||||
*/
|
||||
uint16_t Adafruit_MLX90614::readEmissivityReg(void) {
|
||||
return read16(MLX90614_EMISS);
|
||||
}
|
||||
/**
|
||||
* @brief Write the raw unscaled emissivity value to the emissivity register
|
||||
*
|
||||
* @param ereg The unscaled emissivity value
|
||||
*/
|
||||
void Adafruit_MLX90614::writeEmissivityReg(uint16_t ereg) {
|
||||
write16(MLX90614_EMISS, 0); // erase
|
||||
delay(10);
|
||||
write16(MLX90614_EMISS, ereg);
|
||||
delay(10);
|
||||
}
|
||||
/**
|
||||
* @brief Read the emissivity value from the sensor's register and scale
|
||||
*
|
||||
* @return double The emissivity value, ranging from 0.1 - 1.0
|
||||
*/
|
||||
double Adafruit_MLX90614::readEmissivity(void) {
|
||||
uint16_t ereg = read16(MLX90614_EMISS);
|
||||
return ((double)ereg) / 65535.0;
|
||||
}
|
||||
/**
|
||||
* @brief Set the emissivity value
|
||||
*
|
||||
* @param emissivity The emissivity value to use, between 0.1 and 1.0
|
||||
*/
|
||||
void Adafruit_MLX90614::writeEmissivity(double emissivity) {
|
||||
uint16_t ereg = (uint16_t)(0xffff * emissivity);
|
||||
|
||||
writeEmissivityReg(ereg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current temperature of an object in degrees Farenheit
|
||||
*
|
||||
* @return double The temperature in degrees Farenheit
|
||||
*/
|
||||
double Adafruit_MLX90614::readObjectTempF(void) {
|
||||
return (readTemp(MLX90614_TOBJ1) * 9 / 5) + 32;
|
||||
}
|
||||
/**
|
||||
* @brief Get the current ambient temperature in degrees Farenheit
|
||||
*
|
||||
* @return double The temperature in degrees Farenheit
|
||||
*/
|
||||
double Adafruit_MLX90614::readAmbientTempF(void) {
|
||||
return (readTemp(MLX90614_TA) * 9 / 5) + 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current temperature of an object in degrees Celcius
|
||||
*
|
||||
* @return double The temperature in degrees Celcius
|
||||
*/
|
||||
double Adafruit_MLX90614::readObjectTempC(void) {
|
||||
return readTemp(MLX90614_TOBJ1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the current ambient temperature in degrees Celcius
|
||||
*
|
||||
* @return double The temperature in degrees Celcius
|
||||
*/
|
||||
double Adafruit_MLX90614::readAmbientTempC(void) {
|
||||
return readTemp(MLX90614_TA);
|
||||
}
|
||||
|
||||
float Adafruit_MLX90614::readTemp(uint8_t reg) {
|
||||
float temp;
|
||||
|
||||
temp = read16(reg);
|
||||
temp *= .02;
|
||||
temp -= 273.15;
|
||||
return temp;
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
uint16_t Adafruit_MLX90614::read16(uint8_t a) {
|
||||
uint16_t ret;
|
||||
Wire.begin();
|
||||
Wire.beginTransmission(_addr); // start transmission to device
|
||||
Wire.write(a); // sends register address to read from
|
||||
Wire.endTransmission(false); // end transmission
|
||||
|
||||
Wire.requestFrom(_addr, (size_t)3); // send data n-bytes read
|
||||
ret = Wire.read(); // receive DATA
|
||||
ret |= Wire.read() << 8; // receive DATA
|
||||
|
||||
uint8_t pec = Wire.read();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
byte Adafruit_MLX90614::crc8(byte *addr, byte len)
|
||||
// The PEC calculation includes all bits except the START, REPEATED START, STOP,
|
||||
// ACK, and NACK bits. The PEC is a CRC-8 with polynomial X8+X2+X1+1.
|
||||
{
|
||||
byte crc = 0;
|
||||
while (len--) {
|
||||
byte inbyte = *addr++;
|
||||
for (byte i = 8; i; i--) {
|
||||
byte carry = (crc ^ inbyte) & 0x80;
|
||||
crc <<= 1;
|
||||
if (carry)
|
||||
crc ^= 0x7;
|
||||
inbyte <<= 1;
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
void Adafruit_MLX90614::write16(uint8_t a, uint16_t v) {
|
||||
uint8_t pec;
|
||||
uint8_t pecbuf[4];
|
||||
|
||||
pecbuf[0] = _addr << 1;
|
||||
pecbuf[1] = a;
|
||||
pecbuf[2] = v & 0xff;
|
||||
pecbuf[3] = v >> 8;
|
||||
pec = crc8(pecbuf, sizeof pecbuf);
|
||||
|
||||
Wire.beginTransmission(_addr); // start transmission to device
|
||||
Wire.write(a); // sends register address to write
|
||||
Wire.write(v & 0xff); // lo
|
||||
Wire.write(v >> 8); // hi
|
||||
Wire.write(pec); // pec
|
||||
Wire.endTransmission(true); // end transmission
|
||||
}
|
||||
71
arduino-cli/libraries/Adafruit_MLX90614/Adafruit_MLX90614.h
Normal file
71
arduino-cli/libraries/Adafruit_MLX90614/Adafruit_MLX90614.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/***************************************************
|
||||
This is a library for the MLX90614 Temp Sensor
|
||||
|
||||
Designed specifically to work with the MLX90614 sensors in the
|
||||
adafruit shop
|
||||
----> https://www.adafruit.com/products/1748
|
||||
----> https://www.adafruit.com/products/1749
|
||||
|
||||
These sensors use I2C to communicate, 2 pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruied in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#if (ARDUINO >= 100)
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include "Wire.h"
|
||||
|
||||
#define MLX90614_I2CADDR 0x5A
|
||||
|
||||
// RAM
|
||||
#define MLX90614_RAWIR1 0x04
|
||||
#define MLX90614_RAWIR2 0x05
|
||||
#define MLX90614_TA 0x06
|
||||
#define MLX90614_TOBJ1 0x07
|
||||
#define MLX90614_TOBJ2 0x08
|
||||
// EEPROM
|
||||
#define MLX90614_TOMAX 0x20
|
||||
#define MLX90614_TOMIN 0x21
|
||||
#define MLX90614_PWMCTRL 0x22
|
||||
#define MLX90614_TARANGE 0x23
|
||||
#define MLX90614_EMISS 0x24
|
||||
#define MLX90614_CONFIG 0x25
|
||||
#define MLX90614_ADDR 0x2E
|
||||
#define MLX90614_ID1 0x3C
|
||||
#define MLX90614_ID2 0x3D
|
||||
#define MLX90614_ID3 0x3E
|
||||
#define MLX90614_ID4 0x3F
|
||||
|
||||
/**
|
||||
* @brief Class to read from and control a MLX90614 Temp Sensor
|
||||
*
|
||||
*/
|
||||
class Adafruit_MLX90614 {
|
||||
public:
|
||||
Adafruit_MLX90614(uint8_t addr = MLX90614_I2CADDR);
|
||||
bool begin();
|
||||
|
||||
double readObjectTempC(void);
|
||||
double readAmbientTempC(void);
|
||||
double readObjectTempF(void);
|
||||
double readAmbientTempF(void);
|
||||
uint16_t readEmissivityReg(void);
|
||||
void writeEmissivityReg(uint16_t ereg);
|
||||
double readEmissivity(void);
|
||||
void writeEmissivity(double emissivity);
|
||||
|
||||
private:
|
||||
float readTemp(uint8_t reg);
|
||||
|
||||
uint16_t read16(uint8_t addr);
|
||||
void write16(uint8_t addr, uint16_t data);
|
||||
byte crc8(byte *addr, byte len);
|
||||
uint8_t _addr;
|
||||
};
|
||||
51
arduino-cli/libraries/Adafruit_MLX90614/README.md
Normal file
51
arduino-cli/libraries/Adafruit_MLX90614/README.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Adafruit-MLX90614-Library [](https://github.com/adafruit/Adafruit-MLX90614-Library/actions)[](http://adafruit.github.io/Adafruit-MLX90614-Library/html/index.html)
|
||||
|
||||
This is a library for the MLX90614 temperature sensor
|
||||
|
||||
<a href="https://www.adafruit.com/products/1747"><img src="https://cdn-shop.adafruit.com/970x728/1747-00.jpg" width="500px"></a>
|
||||
|
||||
Designed and tested to work with the MLX90614 sensors in the adafruit shop
|
||||
* https://www.adafruit.com/products/1747 3V version
|
||||
* https://www.adafruit.com/products/1748 5V version
|
||||
|
||||
Check out the links above for our tutorials and wiring diagrams
|
||||
|
||||
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
|
||||
|
||||
# Installation
|
||||
To install, use the Arduino Library Manager and search for "Adafruit-MLX90614-Library" and install the library.
|
||||
|
||||
# Contributing
|
||||
|
||||
Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit-MLX90614-Library/blob/master/CODE_OF_CONDUCT.md>)
|
||||
before contributing to help this project stay welcoming.
|
||||
|
||||
## Documentation and doxygen
|
||||
Documentation is produced by doxygen. Contributions should include documentation for any new code added.
|
||||
|
||||
Some examples of how to use doxygen can be found in these guide pages:
|
||||
|
||||
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen
|
||||
|
||||
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips
|
||||
|
||||
## Formatting and clang-format
|
||||
This library uses [`clang-format`](https://releases.llvm.org/download.html) to standardize the formatting of `.cpp` and `.h` files.
|
||||
Contributions should be formatted using `clang-format`:
|
||||
|
||||
The `-i` flag will make the changes to the file.
|
||||
```bash
|
||||
clang-format -i *.cpp *.h
|
||||
```
|
||||
If you prefer to make the changes yourself, running `clang-format` without the `-i` flag will print out a formatted version of the file. You can save this to a file and diff it against the original to see the changes.
|
||||
|
||||
Note that the formatting output by `clang-format` is what the automated formatting checker will expect. Any diffs from this formatting will result in a failed build until they are addressed. Using the `-i` flag is highly recommended.
|
||||
|
||||
### clang-format resources
|
||||
* [Binary builds and source available on the LLVM downloads page](https://releases.llvm.org/download.html)
|
||||
* [Documentation and IDE integration](https://clang.llvm.org/docs/ClangFormat.html)
|
||||
|
||||
## About this Driver
|
||||
Written by Limor Fried for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above must be included in any redistribution
|
||||
127
arduino-cli/libraries/Adafruit_MLX90614/code-of-conduct.md
Normal file
127
arduino-cli/libraries/Adafruit_MLX90614/code-of-conduct.md
Normal file
@@ -0,0 +1,127 @@
|
||||
# Adafruit Community Code of Conduct
|
||||
|
||||
## Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and leaders pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level or type of
|
||||
experience, education, socio-economic status, nationality, personal appearance,
|
||||
race, religion, or sexual identity and orientation.
|
||||
|
||||
## Our Standards
|
||||
|
||||
We are committed to providing a friendly, safe and welcoming environment for
|
||||
all.
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Be kind and courteous to others
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Collaborating with other community members
|
||||
* 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 sexual attention or advances
|
||||
* The use of inappropriate images, including in a community member's avatar
|
||||
* The use of inappropriate language, including in a community member's nickname
|
||||
* Any spamming, flaming, baiting or other attention-stealing behavior
|
||||
* Excessive or unwelcome helping; answering outside the scope of the question
|
||||
asked
|
||||
* 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
|
||||
|
||||
The goal of the standards and moderation guidelines outlined here is to build
|
||||
and maintain a respectful community. We ask that you don’t just aim to be
|
||||
"technically unimpeachable", but rather try to be your best self.
|
||||
|
||||
We value many things beyond technical expertise, including collaboration and
|
||||
supporting others within our community. Providing a positive experience for
|
||||
other community members can have a much more significant impact than simply
|
||||
providing the correct answer.
|
||||
|
||||
## Our Responsibilities
|
||||
|
||||
Project leaders 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 leaders have the right and responsibility to remove, edit, or
|
||||
reject messages, comments, commits, code, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any community member for other behaviors that they deem
|
||||
inappropriate, threatening, offensive, or harmful.
|
||||
|
||||
## Moderation
|
||||
|
||||
Instances of behaviors that violate the Adafruit Community Code of Conduct
|
||||
may be reported by any member of the community. Community members are
|
||||
encouraged to report these situations, including situations they witness
|
||||
involving other community members.
|
||||
|
||||
You may report in the following ways:
|
||||
|
||||
In any situation, you may send an email to <support@adafruit.com>.
|
||||
|
||||
On the Adafruit Discord, you may send an open message from any channel
|
||||
to all Community Helpers by tagging @community helpers. You may also send an
|
||||
open message from any channel, or a direct message to @kattni#1507,
|
||||
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
|
||||
@Andon#8175.
|
||||
|
||||
Email and direct message reports will be kept confidential.
|
||||
|
||||
In situations on Discord where the issue is particularly egregious, possibly
|
||||
illegal, requires immediate action, or violates the Discord terms of service,
|
||||
you should also report the message directly to Discord.
|
||||
|
||||
These are the steps for upholding our community’s standards of conduct.
|
||||
|
||||
1. Any member of the community may report any situation that violates the
|
||||
Adafruit Community Code of Conduct. All reports will be reviewed and
|
||||
investigated.
|
||||
2. If the behavior is an egregious violation, the community member who
|
||||
committed the violation may be banned immediately, without warning.
|
||||
3. Otherwise, moderators will first respond to such behavior with a warning.
|
||||
4. Moderators follow a soft "three strikes" policy - the community member may
|
||||
be given another chance, if they are receptive to the warning and change their
|
||||
behavior.
|
||||
5. If the community member is unreceptive or unreasonable when warned by a
|
||||
moderator, or the warning goes unheeded, they may be banned for a first or
|
||||
second offense. Repeated offenses will result in the community member being
|
||||
banned.
|
||||
|
||||
## Scope
|
||||
|
||||
This Code of Conduct and the enforcement policies listed above apply to all
|
||||
Adafruit Community venues. This includes but is not limited to any community
|
||||
spaces (both public and private), the entire Adafruit Discord server, and
|
||||
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
|
||||
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
|
||||
interaction at a conference.
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. As a community
|
||||
member, you are representing our community, and are expected to behave
|
||||
accordingly.
|
||||
|
||||
## 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>,
|
||||
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
|
||||
|
||||
For other projects adopting the Adafruit Community Code of
|
||||
Conduct, please contact the maintainers of those projects for enforcement.
|
||||
If you wish to use this code of conduct for your own project, consider
|
||||
explicitly mentioning your moderation policy or making a copy with your
|
||||
own moderation policy so as to avoid confusion.
|
||||
@@ -0,0 +1,40 @@
|
||||
/***************************************************
|
||||
This is a library example for the MLX90614 Temp Sensor
|
||||
|
||||
Designed specifically to work with the MLX90614 sensors in the
|
||||
adafruit shop
|
||||
----> https://www.adafruit.com/products/1747 3V version
|
||||
----> https://www.adafruit.com/products/1748 5V version
|
||||
|
||||
These sensors use I2C to communicate, 2 pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
****************************************************/
|
||||
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_MLX90614.h>
|
||||
|
||||
Adafruit_MLX90614 mlx = Adafruit_MLX90614();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
Serial.println("Adafruit MLX90614 test");
|
||||
|
||||
mlx.begin();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC());
|
||||
Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
|
||||
Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF());
|
||||
Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");
|
||||
|
||||
Serial.println();
|
||||
delay(500);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
name=Adafruit MLX90614 Library
|
||||
version=1.1.1
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for the MLX90614 sensors in the Adafruit shop
|
||||
paragraph=Arduino library for the MLX90614 sensors in the Adafruit shop
|
||||
category=Sensors
|
||||
url=https://github.com/adafruit/Adafruit-MLX90614-Library
|
||||
architectures=*
|
||||
26
arduino-cli/libraries/Adafruit_MLX90614/license.txt
Normal file
26
arduino-cli/libraries/Adafruit_MLX90614/license.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2020 Limor Fried for Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Reference in New Issue
Block a user