Home

Awesome

License: MIT

Bolder Flight Systems Logo     Arduino Logo

Ams5812

This library communicates with AMS-5812 pressure transducers and is compatible with Arduino and CMake build systems.

Description

The Analog Microelectronics AMS-5812 pressure transducers are fully signal conditioned, amplified, and temperature compensated over a temperature range of -25 to +85 C. These sensors generate data with high precision, high stability and low drift. Digital measurements are sampled with a 14 bit resolution. The AMS-5812 sensors are available in a wide variety of pressure ranges and in configurations suited for barometric, differential, and bidirectional differential measurement.

Usage

This library communicates with the AMS-5812 sensors using an I2C interface. The default I2C address for the AMS-5812 is 0x78; however, a USB starter kit may be purchased to enable programming additional addresses. Pressure and temperature data can be provided at rates of up to 2 kHz.

Installation

Arduino

Simply clone or download and extract the zipped library into your Arduino/libraries folder. The library is added as:

#include "ams5812.h"

An example Arduino executable is located in: examples/arduino/ams5812_example/ams5812_example.ino. Teensy 3.x, 4.x, and LC devices are used for testing under Arduino and this library should be compatible with other Arduino devices.

CMake

CMake is used to build this library, which is exported as a library target called ams5812. The header is added as:

#include "ams5812.h"

The library can be also be compiled stand-alone using the CMake idiom of creating a build directory and then, from within that directory issuing:

cmake .. -DMCU=MK66FX1M0
make

This will build the library and an example executable called ams5812_example. The example executable source file is located at examples/cmake/ams5812_example.cc. Notice that the cmake command includes a define specifying the microcontroller the code is being compiled for. This is required to correctly configure the code, CPU frequency, and compile/linker options. The available MCUs are:

These are known to work with the same packages used in Teensy products. Also switching packages is known to work well, as long as it's only a package change.

Each target also has a _hex, for creating the hex file to upload to the microcontroller, and an _upload for using the Teensy CLI Uploader to flash the Teensy. Please note that the CMake build tooling is expected to be run under Linux or WSL, instructions for setting up your build environment can be found in our build-tools repo.

Namespace

This library is within the namespace bfs.

Ams5812

Ams5812() Default constructor, requires calling the Config method to setup the I2C bus, I2C address, and transducer type.

Ams5812(i2c_t3 *bus, const uint8_t addr, const Transducer type) Creates an Ams5812 object. A pointer to the I2C bus object is passed along with the I2C address of the sensor and the AMS-5812 transducer type. The enumerated transducer types are:

Sensor NameEnumerated TypePressure TypePressure Range
AMS 5812-0000-DAMS5812_0000_Ddifferential / relative0...517 Pa
AMS 5812-0001-DAMS5812_0001_Ddifferential / relative0...1034 Pa
AMS 5812-0000-D-BAMS5812_0000_D_Bbidirectional differential-517...+517 Pa
AMS 5812-0001-D-BAMS5812_0001_D_Bbidirectional differential-1034...+1034 Pa
AMS 5812-0003-DAMS5812_0003_Ddifferential / relative0...2068 Pa
AMS 5812-0008-DAMS5812_0008_Ddifferential / relative0...5516 Pa
AMS 5812-0015-DAMS5812_0015_Ddifferential / relative0...10342 Pa
AMS 5812-0003-D-BAMS5812_0003_D_Bbidirectional differential-2068...+2068 Pa
AMS 5812-0008-D-BAMS5812_0008_D_Bbidirectional differential-5516...+5516 Pa
AMS 5812-0015-D-BAMS5812_0015_D_Bbidirectional differential-10342...+10342 Pa
AMS 5812-0030-DAMS5812_0030_Ddifferential / relative0...20684 Pa
AMS 5812-0050-DAMS5812_0050_Ddifferential / relative0...34474 Pa
AMS 5812-0150-DAMS5812_0150_Ddifferential / relative0...103421 Pa
AMS 5812-0300-DAMS5812_0300_Ddifferential / relative0...206843 Pa
AMS 5812-0600-DAMS5812_0600_Ddifferential / relative0...413685 Pa
AMS 5812-1000-DAMS5812_1000_Ddifferential / relative0...689476 Pa
AMS 5812-0030-D-BAMS5812_0030_D_Bbidirectional differential-20684...+20684 Pa
AMS 5812-0050-D-BAMS5812_0050_D_Bbidirectional differential-34474...+34474 Pa
AMS 5812-0150-D-BAMS5812_0150_D_Bbidirectional differential-103421...+103421 Pa
AMS 5812-0150-BAMS5812_0150_Bbarometric75842...120658 Pa
AMS 5812-0150-AAMS5812_0150_Aabsolute0...103421 Pa
AMS 5812-0300-AAMS5812_0300_Aabsolute0...206843 Pa

For example, the following code declares an AMS5812 object called ams with an AMS5812-0008-D sensor located on I2C bus 0 with an I2C address of 0x10:

bfs::Ams5812 ams(&Wire, 0x10, bfs::Ams5812::AMS5812_0008_D);

void Config(TwoWire *bus, const uint8_t addr, const Transducer type) This is required when using the default constructor and sets up the I2C bus, I2C address, and transducer type.

bool Begin() Initializes communication with the sensor and configures the sensor driver for the specified transducer. True is returned if communication is able to be established with the sensor and configuration completes successfully, otherwise, false is returned. The communication bus is not initialized within this library and must be initialized seperately; this enhances compatibility with other sensors that may on the same bus.

Wire.begin();
Wire.setClock(400000);
bool status = ams.Begin();
if (!status) {
  // ERROR
}

bool Read() Reads data from the AMS-5812 and stores the data in the Ams5812 object. Returns true if data is successfully read, otherwise, returns false.

/* Read the sensor data */
if (ams.Read()) {
}

float pres_pa() Returns the pressure data from the Ams5812 object in units of Pa.

float pressure = ams.pres_pa();

float die_temp_c Returns the die temperature of the sensor from the Ams5812 object in units of degrees C.

float temperature = ams.die_temp_c();

Example List

Wiring and Pullups

Please refer to the Analog Microelectronics AMS 5812 datasheet and your microcontroller's pinout diagram.

The silver dot on the AMS 5812 marks the location of Pin 1. The AMS 5812 pinout is:

4.7 kOhm resistors should be used as pullups on SDA and SCL, these resistors should pullup with a 5V source.