Introduction: Raspberry Pi CPS120 Pressure Sensor Java Tutorial
CPS120 is a high quality and low cost capacitive absolute pressure sensor with fully compensated output. It consumes very less power and comprises of an ultra small Micro-Electro-Mechanical Sensor(MEMS) for pressure measurement. A sigma-delta based ADC is also embodied in it to accomplish the requirement of compensated output. Here is the demonstration with a java code using Raspberry Pi.
Step 1: What You Need..!!
Step 2: Connections:
Take an I2C shield for raspberry pi and gently push it over the gpio pins of raspberry pi.
Then connect the one end of I2C cable to CPS120 sensor and the other end to the I2C shield.
Also connect the Ethernet cable to the pi or you can use a WiFi module.
Connections are shown in the picture above.
Step 3: Code:
The java code for CPS120 can be downloaded from our github repository- Dcube Store
Here is the link for the same :
We have used pi4j library for java code, the steps to install pi4j on raspberry pi is described here:
You can also copy the code from here, it is given as follows:
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// This code is designed to work with the CPS120_I2CS I2C Mini Module.
public class CPS120
public static void main(String args) throws Exception
// Create I2CBus
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1);
// Get I2C device, CPS120 I2C address is 0x28(40)
I2CDevice device = bus.getDevice(0x28);
// Send start command
// Read 2 bytes of data, msb first
byte data = new byte;
device.read(data, 0, 2);
// Convert data to kPa
double pressure = (((data & 0x3F) * 256 + data) * (90 / 16384.00)) + 30;
// Output data to screen
System.out.printf("Pressure is : %.2f kPa %n",pressure);
Step 4: Applications:
CPS120 has a variety of applications. It can be employed in portable and stationary barometers, altimeters etc. Pressure is an important parameter to determine the weather conditions and considering that this sensor can be installed at weather stations too. It can be incorporated in air contol systems as well as vacuum systems.