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.


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

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import smbus
import time
bus = smbus.SMBus(1)
bus.write_i2c_block_data(0x68, 0b10001000, [0x00])

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.

Reference : MICROCHIP – MCP3425 16-Bit Analog-to-Digital Converter with I2C Interface and On-Board Reference – Page 14

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])

無題の図形描画 (2).png

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

About Shift :

raw = data[0] << 8 | data[1]


3.3  Measurement Result



[Armbian]: How to Connect Orange Pi Zero to WiFi

Raspberry Pi Zero has no WiFi function. However, Orange Pi Zero has WiFi function. You cannot use the WiFi function simply by installing Armbian on Orange Pi Zero.

Here, we describe a method for connecting Orange Pi Zero with Armbian installed to WiFi.

1. Setting “wpa_supplicant.conf”

Introduction it’s necessary to set basic information for connecting to WiFi. Please prepare your WiFi SSID and Password. Write the setting information using an arbitrary Editor. Please change the part of “[SSID]” and “[PASSWORD]”.

$ sudo sh -c "wpa_passphrase [SSID] [PASSWORD] >> /etc/wpa_supplicant/wpa_supplicant.conf"
$ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

2. Setting “interfaces”

After setting WiFi, proceed to the next. Edit “/etc/network/interfaces” using an arbitrary editor.

$ sudo vi /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
$ sudo reboot


Thank you.

Japanese Food : Cup Chocolate Chow Mein

Would you like Cup Chocolate Chow Mein? You can eat it in 3 minutes.

Cup Chocolate Chow Mein
The Other Side

Blue is chocolate sauce, red is sauce, purple is chocolate cubes.


Put Hot Water in the cup and leave it for 3 minutes. Then, draining hot water.

Mix Accessories

I ate this Cup Chocolate Chow Mein. This is a combination of sweet and salty. I will not recommend it.

Evaluation : 3.0/10.0

Easy Install Hamachi on Raspberry Pi (Automatic Startup)

For older versions, “lsb” and “lsb-core” were necessary. In this article, “lsb” and “lsb-core” is unnecessary and it is setup until automatic startup.

The version used in this article is

$ wget
$ sudo dpkg -i logmein-hamachi_2.1.0.174-1_armhf.deb

After installation please do the following to join Hamachi. The last “hamachi join” is unnecessary if you are using WEB approval, and you can participate by approving it on the WEB.

$ sudo hamachi login
$ sudo hamachi attach [Your Hamachi Email Address]
$ sudo hamachi set-nick [Whatever Nickname You Make]
$ sudo hamachi join [Network ID] [Password]

Finally reboot Raspberry Pi and check whether Hamachi will start automatically.

How to Acquire CPU Temperature and CPU Frequency Using PHP

This article is in English. Sometimes the sentences are wrong. Please be understanding of this beforehand.

How to Acquire the CPU Temperature Using PHP

The temperature displayed is celsius.

echo round((exec('cat /sys/class/thermal/thermal_zone0/temp')/1000),2);

How to Acquire the CPU Frequency Using PHP

The unit displayed is MHz. If there are 4 cores, cpu0 to cpu3.

echo round((exec('cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq')/1000),2);

Operation Example

Raspberry Pi is used for the server. By introducing “Insert PHP” in WordPress you can run PHP with widget.

Using “Insert PHP”.
Add Completed.

Change the frequency and check the operation.

Changed from 900MHz to 1000Mhz