This module contains the driver for Microchip MCP3426/3427/3428 multichannel analog to digital converters with I2C interface (datasheet).
from microchip.mcp3428 import MCP3428 ... mcp = mcp3428.MCP3428(I2C0, addr = 0x6A) mcp.set(ch = 1, pga = 1) value1 = mcp.get_raw_data() mcp.set(ch = 2, pga = 2) value2 = mcp.get_raw_data()
MCP3428(i2cdrv, addr = 0x68, clk = 400000)¶
Creates an instance of the MCP3428 class. This class allows the control of all MCP3426, MCP3427, and MCP3428 devices.
- i2cdrv – I2C Bus used ‘(I2C0, ...)’
- addr – Slave address, default 0x68
- clk – Clock speed, default 400 kHz
set(cmode=0, rdy=0, ch=0, sps=2, pga=1)¶
Sets the device’s configuration register.
cmode : sets the Conversion mode. Available values are:
0: One-Shot Conversion Mode. The device performs a single conversion and enters a low power standby mode until it receives another command.
1: Continuous Conversion Mode. The device performs data conversion continuously.
rdy : when in Continuous Conversion mode, the value of this parameter has no effect. When in One-Shot Conversion mode, setting this parameter to
1initiates a new conversion.
ch : channel selection.
ch selected channel 0 Channel 1 1 Channel 2 2 Channel 3 (MCP3248 only, treated as 0 by MCP3246/MCP3247) 3 Channel 4 (MCP3248 only, treated as 1 by MCP3246/MCP3247)
sps : Sample rate / resolution selection.
sps Samples per second ADC resolution (bits) 0 240 12 1 60 14 2 15 16
pga : PGA Gain selection. Available values are 1, 2, 4, and 8. Passing an invalid value results in unity gain.