This commit is contained in:
Lady Ada 2020-02-22 19:20:28 -05:00
commit a0e0052da3
10 changed files with 581 additions and 0 deletions

46
.github/ISSUE_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,46 @@
Thank you for opening an issue on an Adafruit Arduino library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
- **Do not use GitHub issues for troubleshooting projects and issues.** Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
- **If following a tutorial or guide be sure you didn't miss a step.** Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
- **For Arduino projects check these very common issues to ensure they don't apply**:
- For uploading sketches or communicating with the board make sure you're using
a **USB data cable** and **not** a **USB charge-only cable**. It is sometimes
very hard to tell the difference between a data and charge cable! Try using the
cable with other devices or swapping to another cable to confirm it is not
the problem.
- **Be sure you are supplying adequate power to the board.** Check the specs of
your board and plug in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
- **Double check all soldering joints and connections.** Flakey connections
cause many mysterious problems. See the [guide to excellent soldering](https://learn.adafruit.com/adafruit-guide-excellent-soldering/tools) for examples of good solder joints.
- **Ensure you are using an official Arduino or Adafruit board.** We can't
guarantee a clone board will have the same functionality and work as expected
with this code and don't support them.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
- Arduino board: **INSERT ARDUINO BOARD NAME/TYPE HERE**
- Arduino IDE version (found in Arduino -> About Arduino menu): **INSERT ARDUINO
VERSION HERE**
- List the steps to reproduce the problem below (if possible attach a sketch or
copy the sketch code in too): **LIST REPRO STEPS BELOW**

26
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View file

@ -0,0 +1,26 @@
Thank you for creating a pull request to contribute to Adafruit's GitHub code!
Before you open the request please review the following guidelines and tips to
help it be more easily integrated:
- **Describe the scope of your change--i.e. what the change does and what parts
of the code were modified.** This will help us understand any risks of integrating
the code.
- **Describe any known limitations with your change.** For example if the change
doesn't apply to a supported platform of the library please mention it.
- **Please run any tests or examples that can exercise your modified code.** We
strive to not break users of the code and running tests/examples helps with this
process.
Thank you again for contributing! We will try to test and integrate the change
as soon as we can, but be aware we have many GitHub repositories to manage and
can't immediately respond to every request. There is no need to bump or check in
on a pull request (it will clutter the discussion of the request).
Also don't be worried if the request is closed or not integrated--sometimes the
priorities of Adafruit's GitHub code (education, ease of use) might not match the
priorities of the pull request. Don't fret, the open source community thrives on
forks and GitHub makes it easy to keep your changes in a forked repo.
After reviewing the guidelines above you can delete this text from the pull request.

32
.github/workflows/githubci.yml vendored Normal file
View file

@ -0,0 +1,32 @@
name: Arduino Library CI
on: [pull_request, push, repository_dispatch]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: adafruit/ci-arduino
path: ci
- name: pre-install
run: bash ci/actions_install.sh
- name: test platforms
run: python3 ci/build_platform.py main_platforms
- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .
- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit NAU7802 Library"
run: bash ci/doxy_gen_and_deploy.sh

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
# osx
.DS_Store
# doxygen
Doxyfile*
doxygen_sqlite3.db
html
*.tmp

196
Adafruit_NAU7802.cpp Normal file
View file

@ -0,0 +1,196 @@
/**************************************************************************/
/*!
@file Adafruit_NAU7802.cpp
@mainpage Adafruit NAU7802 I2C 24-bit ADC driver
@section intro Introduction
This is a library for the Adafruit NAU7802 I2C ADC breakout board
----> http://www.adafruit.com/products/4538
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section author Author
Limor Fied (Adafruit Industries)
@section license License
BSD (see license.txt)
*/
/**************************************************************************/
#include "Adafruit_NAU7802.h"
/**************************************************************************/
/*!
@brief Instantiates a new NAU7802 class
*/
/**************************************************************************/
Adafruit_NAU7802::Adafruit_NAU7802() {
}
/**************************************************************************/
/*!
@brief Sets up the I2C connection and tests that the sensor was found.
@param theWire Pointer to an I2C device we'll use to communicate
default is Wire
@return true if sensor was found, otherwise false.
*/
/**************************************************************************/
bool Adafruit_NAU7802::begin(TwoWire *theWire) {
i2c_dev = new Adafruit_I2CDevice(NAU7802_I2CADDR_DEFAULT, theWire);
/* Try to instantiate the I2C device. */
if (!i2c_dev->begin()) {
return false;
}
/* Check for NAU7802 revision register (0x1F), low nibble should be 0xF. */
Adafruit_I2CRegister rev_reg = Adafruit_I2CRegister(i2c_dev, NAU7802_REVISION_ID);
if ((rev_reg.read() & 0xF) != 0xF) {
return false;
}
// define the main power control register
_pu_ctrl_reg = new Adafruit_I2CRegister(i2c_dev, NAU7802_PU_CTRL);
if (! reset()) return false;
if (! setLDO(NAU7802_3V0)) return false;
if (! setGain(NAU7802_GAIN_128)) return false;
if (! setRate(NAU7802_RATE_10SPS)) return false;
if (! enable(true)) return false;
return true;
}
bool Adafruit_NAU7802::enable(bool flag) {
Adafruit_I2CRegisterBits pu_analog =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 2); // # bits, bit_shift
Adafruit_I2CRegisterBits pu_digital =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 1); // # bits, bit_shift
Adafruit_I2CRegisterBits pu_ready =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 3); // # bits, bit_shift
Adafruit_I2CRegisterBits pu_start =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 4); // # bits, bit_shift
if (! flag) {
// shut down;
if (! pu_analog.write(0)) return false;
if (! pu_digital.write(0)) return false;
return true;
}
// turn on!
if (! pu_digital.write(1)) return false;
if (! pu_analog.write(1)) return false;
// RDY: Analog part wakeup stable plus Data Ready after exiting power-down mode 600ms
delay(600);
if (! pu_start.write(1)) return false;
return pu_ready.read();
}
bool Adafruit_NAU7802::available(void) {
Adafruit_I2CRegisterBits conv_ready =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 5); // # bits, bit_shift
return conv_ready.read();
}
int32_t Adafruit_NAU7802::read(void) {
Adafruit_I2CRegister adc0 = Adafruit_I2CRegister(i2c_dev, NAU7802_ADCO_B2, 3, MSBFIRST);
uint32_t val = adc0.read();
// extend sign bit
if (val & 0x80000) { val |= 0xFF000000; }
return val;
}
bool Adafruit_NAU7802::reset(void) {
Adafruit_I2CRegisterBits reg_reset =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 0); // # bits, bit_shift
Adafruit_I2CRegisterBits pu_digital =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 1); // # bits, bit_shift
Adafruit_I2CRegisterBits pu_ready =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 3); // # bits, bit_shift
// Set the RR bit to 1 in R0x00, to guarantee a reset of all register values.
if (!reg_reset.write(1)) return false;
delay(10);
// Set the RR bit to 0 and PUD bit 1, in R0x00, to enter normal operation
if (!reg_reset.write(0)) return false;
if (!pu_digital.write(1)) return false;
// After about 200 microseconds, the PWRUP bit will be Logic=1 indicating the device is ready for the remaining programming setup.
delay(1);
return pu_ready.read();
}
bool Adafruit_NAU7802::setLDO(NAU7802_LDOVoltage voltage) {
Adafruit_I2CRegisterBits reg_avdds =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 7); // # bits, bit_shift
Adafruit_I2CRegister ctrl1_reg = Adafruit_I2CRegister(i2c_dev, NAU7802_CTRL1);
Adafruit_I2CRegisterBits vldo =
Adafruit_I2CRegisterBits(&ctrl1_reg, 3, 3); // # bits, bit_shift
if (voltage == NAU7802_EXTERNAL) {
// special case!
return reg_avdds.write(0);
}
// internal LDO
if (! reg_avdds.write(1)) return false;
return vldo.write(voltage);
}
NAU7802_LDOVoltage Adafruit_NAU7802::getLDO(void) {
Adafruit_I2CRegisterBits reg_avdds =
Adafruit_I2CRegisterBits(_pu_ctrl_reg, 1, 7); // # bits, bit_shift
Adafruit_I2CRegister ctrl1_reg = Adafruit_I2CRegister(i2c_dev, NAU7802_CTRL1);
Adafruit_I2CRegisterBits vldo =
Adafruit_I2CRegisterBits(&ctrl1_reg, 3, 3); // # bits, bit_shift
if (! reg_avdds.read()) {
return NAU7802_EXTERNAL;
}
// internal LDO
return (NAU7802_LDOVoltage)vldo.read();
}
bool Adafruit_NAU7802::setGain(NAU7802_Gain gain) {
Adafruit_I2CRegister ctrl1_reg = Adafruit_I2CRegister(i2c_dev, NAU7802_CTRL1);
Adafruit_I2CRegisterBits gain_select =
Adafruit_I2CRegisterBits(&ctrl1_reg, 3, 0); // # bits, bit_shift
return gain_select.write(gain);
}
NAU7802_Gain Adafruit_NAU7802::getGain(void) {
Adafruit_I2CRegister ctrl1_reg = Adafruit_I2CRegister(i2c_dev, NAU7802_CTRL1);
Adafruit_I2CRegisterBits gain_select =
Adafruit_I2CRegisterBits(&ctrl1_reg, 3, 0); // # bits, bit_shift
return gain_select.read();
}
bool Adafruit_NAU7802::setRate(NAU7802_SampleRate rate) {
Adafruit_I2CRegister ctrl2_reg = Adafruit_I2CRegister(i2c_dev, NAU7802_CTRL2);
Adafruit_I2CRegisterBits rate_select =
Adafruit_I2CRegisterBits(&ctrl2_reg, 3, 4); // # bits, bit_shift
return rate_select.write(rate);
}
NAU7802_SampleRate Adafruit_NAU7802::getRate(void) {
Adafruit_I2CRegister ctrl2_reg = Adafruit_I2CRegister(i2c_dev, NAU7802_CTRL2);
Adafruit_I2CRegisterBits rate_select =
Adafruit_I2CRegisterBits(&ctrl2_reg, 3, 4); // # bits, bit_shift
return (NAU7802_SampleRate)rate_select.read();
}

91
Adafruit_NAU7802.h Normal file
View file

@ -0,0 +1,91 @@
/**************************************************************************/
/**
@file Adafruit_NAU7802.h
Author: Limor Fried (Adafruit Industries)
License: BSD (see license.txt)
This is a library for the Adafruit NAU7802 I2C ADC breakout board
----> http://www.adafruit.com/products/4538
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
/** Default NAU7802 I2C address. */
#define NAU7802_I2CADDR_DEFAULT 0x2A ///< I2C address
#define NAU7802_PU_CTRL 0x00
#define NAU7802_CTRL1 0x01
#define NAU7802_CTRL2 0x02
#define NAU7802_ADCO_B2 0x12
#define NAU7802_ADC1_B2 0x12
#define NAU7802_REVISION_ID 0x1F
/*! The possible LDO voltages */
typedef enum _ldovoltages {
NAU7802_4V5,
NAU7802_4V2,
NAU7802_3V9,
NAU7802_3V6,
NAU7802_3V3,
NAU7802_3V0,
NAU7802_2V7,
NAU7802_2V4,
NAU7802_EXTERNAL,
} NAU7802_LDOVoltage;
/*! The possible gains */
typedef enum _gains {
NAU7802_GAIN_1,
NAU7802_GAIN_2,
NAU7802_GAIN_4,
NAU7802_GAIN_8,
NAU7802_GAIN_16,
NAU7802_GAIN_32,
NAU7802_GAIN_64,
NAU7802_GAIN_128,
} NAU7802_Gain;
/*! The possible sample rates */
typedef enum _sample_rates {
NAU7802_RATE_10SPS = 0,
NAU7802_RATE_20SPS = 1,
NAU7802_RATE_40SPS = 2,
NAU7802_RATE_80SPS = 3,
NAU7802_RATE_320SPS = 7,
} NAU7802_SampleRate;
/**************************************************************************/
/*!
@brief NAU7802 driver.
*/
/**************************************************************************/
class Adafruit_NAU7802 {
public:
Adafruit_NAU7802();
bool begin(TwoWire *theWire = &Wire);
bool reset(void);
bool enable(bool flag);
bool available(void);
int32_t read(void);
bool setLDO(NAU7802_LDOVoltage voltage);
NAU7802_LDOVoltage getLDO(void);
bool setGain(NAU7802_Gain gain);
NAU7802_Gain getGain(void);
bool setRate(NAU7802_SampleRate gain);
NAU7802_SampleRate getRate(void);
private:
Adafruit_I2CRegister *_pu_ctrl_reg = NULL;
Adafruit_I2CDevice *i2c_dev = NULL;
};

19
README.md Normal file
View file

@ -0,0 +1,19 @@
Adafruit_NAU7802 [![Build Status](https://travis-ci.com/adafruit/Adafruit_NAU7802.svg?branch=master)](https://travis-ci.com/adafruit/Adafruit_NAU7802)
================
<a href="https://www.adafruit.com/product/4226"><img src="assets/board.jpg?raw=true" width="500px"></a>
This is the Adafruit NAU7802 I2C 24-bit ADC sensor library
Tested and works great with the Adafruit NAU7802 Breakout Board
* http://www.adafruit.com/products/4538
This chip uses 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 for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution
To install, use the Arduino Library Manager and search for "Adafruit NAU7802" and install the library.

127
code-of-conduct.md Normal file
View 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 dont 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 communitys 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.

10
library.properties Normal file
View file

@ -0,0 +1,10 @@
name=Adafruit NAU7802 Library
version=0.0.1
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for the NAU7802 ADC converter in the Adafruit shop
paragraph=Arduino library for the NAU7802 ADC converter in the Adafruit shop
category=Sensors
url=https://github.com/adafruit/Adafruit_NAU7802
architectures=*
depends=Adafruit BusIO

26
license.txt Normal file
View file

@ -0,0 +1,26 @@
Software License Agreement (BSD License)
Copyright (c) 2012, 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.