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..!!

1. Raspberry Pi

2. CPS120

LINK : https://www.controleverything.com/content/Barometer?sku=CPS120_I2CS

3. I²C Cable

LINK : https://www.controleverything.com/content/I2C-Cables?sku=I2CAFF3

4. I²C Shield for Raspberry Pi

LINK : https://www.controleverything.com/content/I2C-Master?sku=TOUTPI2

5. Ethernet Cable

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- ControlEverythingCommunity

Here is the link for the same :

https://github.com/ControlEverythingCommunity/CPS1...

The datasheet of CPS120 can be found here:

http://consensic.com/images/CPS120_Data%20Sheet_Pr...

We have used pi4j library for java code, the steps to install pi4j on raspberry pi is described here:

http://pi4j.com/install.html

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.

// CPS120

// This code is designed to work with the CPS120_I2CS I2C Mini Module available from ControlEverything.com.

// https://www.controleverything.com/content/Baromet...

import com.pi4j.io.i2c.I2CBus;

import com.pi4j.io.i2c.I2CDevice;

import com.pi4j.io.i2c.I2CFactory;

import java.io.IOException;

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

device.write(0x28, (byte)0x80);

Thread.sleep(800);

// Read 2 bytes of data, msb first

byte[] data = new byte[2];

device.read(data, 0, 2);

// Convert data to kPa

double pressure = (((data[0] & 0x3F) * 256 + data[1]) * (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.

Comments