Adafruit MCP3421 Arduino Library
Adafruit_MCP3421.h
1 #ifndef ADAFRUIT_MCP3421_H
2 #define ADAFRUIT_MCP3421_H
3 
4 #include "Arduino.h"
5 #include <Adafruit_I2CDevice.h>
6 
11 typedef enum {
12  GAIN_1X = 0b00,
13  GAIN_2X = 0b01,
14  GAIN_4X = 0b10,
15  GAIN_8X = 0b11
16 } mcp3421_gain;
17 
22 typedef enum {
23  RESOLUTION_12_BIT = 0b00,
24  RESOLUTION_14_BIT = 0b01,
25  RESOLUTION_16_BIT = 0b10,
26  RESOLUTION_18_BIT = 0b11
27 } mcp3421_resolution;
28 
33 typedef enum {
34  MODE_CONTINUOUS = 0b1,
35  MODE_ONE_SHOT = 0b0
36 } mcp3421_mode;
37 
42 typedef struct {
43  uint8_t gain : 2;
44  uint8_t resolution : 2;
45  uint8_t mode : 1;
46  uint8_t unused : 2;
47  uint8_t ready : 1;
49 
55 public:
57  boolean begin(uint8_t i2c_addr = 0x68, TwoWire *wire = &Wire);
58 
59  void setGain(mcp3421_gain gain);
60  mcp3421_gain getGain();
61 
62  void setResolution(mcp3421_resolution res);
63  mcp3421_resolution getResolution();
64 
65  void setMode(mcp3421_mode mode);
66  mcp3421_mode getMode();
67 
68  bool isReady();
70  int32_t readADC();
71 
72 private:
73  Adafruit_I2CDevice *i2c_dev;
74  mcp3421_config_t config;
75  uint8_t adc_data[3];
77  bool readData();
78 };
79 
80 #endif // ADAFRUIT_MCP3421_H
boolean begin(uint8_t i2c_addr=0x68, TwoWire *wire=&Wire)
Initialize the MCP3421 sensor.
Definition: Adafruit_MCP3421.cpp:16
void setGain(mcp3421_gain gain)
Set the gain of the MCP3421.
Definition: Adafruit_MCP3421.cpp:26
bool startOneShotConversion()
Start a one-shot conversion on the MCP3421.
Definition: Adafruit_MCP3421.cpp:132
uint8_t mode
Definition: Adafruit_MCP3421.h:45
Adafruit_MCP3421()
Construct a new Adafruit_MCP3421::Adafruit_MCP3421 object. Initialize the I2C device and configuratio...
Definition: Adafruit_MCP3421.cpp:7
mcp3421_resolution getResolution()
Get the current resolution setting of the MCP3421.
Definition: Adafruit_MCP3421.cpp:58
uint8_t ready
Definition: Adafruit_MCP3421.h:47
uint8_t resolution
Definition: Adafruit_MCP3421.h:44
bool isReady()
Check if the MCP3421 has completed a conversion, can be used in continuous or one-shot mode...
Definition: Adafruit_MCP3421.cpp:90
uint8_t unused
Definition: Adafruit_MCP3421.h:46
void setMode(mcp3421_mode mode)
Set the operational mode of the MCP3421.
Definition: Adafruit_MCP3421.cpp:68
Struct representing the configuration register of the MCP3421.
Definition: Adafruit_MCP3421.h:42
mcp3421_gain getGain()
Get the current gain setting of the MCP3421.
Definition: Adafruit_MCP3421.cpp:37
mcp3421_mode getMode()
Get the current operational mode of the MCP3421.
Definition: Adafruit_MCP3421.cpp:79
int32_t readADC()
Read the ADC value from MCP3421.
Definition: Adafruit_MCP3421.cpp:143
void setResolution(mcp3421_resolution res)
Set the resolution of the MCP3421.
Definition: Adafruit_MCP3421.cpp:47
Class representing the Adafruit MCP3421 ADC breakout.
Definition: Adafruit_MCP3421.h:54
uint8_t gain
Definition: Adafruit_MCP3421.h:43