How to Use MCP3425 ADC 16-Bit Mode with Raspberry Pi (Python)
Raspberry Pi cannot acquire analog values. However, Arduino is equipped with ADC as standard, but the performance is on the odder of “10-Bit(0 – 1023). The MCP3425 used in this article is 16-Bit and can also perform I2C connection. Furthermore, It’s possible to measure not only positive values but also negative values.
1 Configuration of MCP3425
The Configuration of the MCP3425 is as follows.
- Diagram
- For Raspberry Pi

Diagram
Wiring diagram of MCP3425 and Raspberry Pi.

Battery Voltage Measurement Example
Check the I2C connection with the command.
$ sudo i2cdetect -y 1
2 Use MCP3425 with 16-Bit Mode
Control MCP3425 using Python. The following program acquires the analog values and display the voltage values.
$ vi mcp3425.py #!/usr/bin/env python # -*- coding: utf-8 -*- import smbus import time
bus = smbus.SMBus(1) bus.write_i2c_block_data(0x68, 0b10001000, [0x00]) time.sleep(1)
data = bus.read_i2c_block_data(0x68, 0x00, 2) raw = data[0] << 8 | data[1]
if raw > 32767: raw -= 65535 vol = 2.048 / 32767 print str(raw*vol) + " [V]"
3 Explanation
Bit | Value | Explanation |
Bit 7 | 1 | Initiate a new conversion. |
0 | No effect. | |
Bit 6 | 0 | Do not use. Select value 0. |
Bit 5 | 0 | Do not use. Select value 0. |
Bit 4 | 1 | Continuous conversion mode. |
0 | One-Shot conversion mode. | |
Bit 3-2 | 00 | 12 Bits. 240 SPS. |
01 | 14 Bits. 60 SPS. | |
10 | 16 Bits. 15 SPS. | |
Bit 1-0 | 00 | PGA Gain x1. |
01 | PGA Gain x2. | |
10 | PGA Gain x4. | |
11 | PGA Gain x8. |
3.1 Write Setting
Refer to the above table and set the parameters. The following is the Write Setting. It’s arranged from Bit 7 to Bit 0.
bus.write_i2c_block_data(0x68, 0b10001000, [0x00])
Radix Reference
Radix | Prefix | Example |
Binary Number | 0b | 0b110 |
Octal Number | 0o | 0o310 |
Decimal Number | 0d | 0d209 |
Hexadecimal Number | 0x | 0x1F2 |
3.2 Read Setting
Receive data from MCP3425. Read using “bus.read_i2c_block_data”.
data = bus.read_i2c_block_data(0x68, 0x00, 2)
It’s necessary to properly format the read data.
raw = data[0] << 8 | data[1]
Let’s see what is contained in data[0] and data[1].
The displayed value is Decimal Number. Conversion work is done in Binary Number.

Conversion Work

Shift
About Shift :
raw = data[0] << 8 | data[1]
最近のコメント