https://github.com/pilotak/mcp3x21
Arduino library for MCP3021 I2C ADC
https://github.com/pilotak/mcp3x21
mcp3021 mcp3221
Last synced: about 1 year ago
JSON representation
Arduino library for MCP3021 I2C ADC
- Host: GitHub
- URL: https://github.com/pilotak/mcp3x21
- Owner: pilotak
- License: mit
- Created: 2018-09-23T16:55:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-09-29T07:06:13.000Z (over 4 years ago)
- Last Synced: 2025-03-28T03:41:21.021Z (about 1 year ago)
- Topics: mcp3021, mcp3221
- Language: C++
- Homepage:
- Size: 21.5 KB
- Stars: 3
- Watchers: 1
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Arduino library for MCP3021 & MCP3221 I2C ADC
[](https://github.com/pilotak/MCP3X21/actions)
[](https://arduino.cc)
## Example
```cpp
#include
#include "MCP3X21.h"
const uint8_t address = 0x4D;
const uint16_t ref_voltage = 3300; // in mV
MCP3021 mcp3021(address);
void setup() {
Serial.begin(115200);
#if defined(ESP8266)
Wire.begin(SDA, SCL);
mcp3021.init(&Wire);
#else
mcp3021.init();
#endif
}
void loop() {
uint16_t result = mcp3021.read();
Serial.print(F("ADC: "));
Serial.print(result);
Serial.print(F(", mV: "));
Serial.println(mcp3021.toVoltage(result, ref_voltage));
delay(1000);
}
```