Raspberry Pi SI7050 Temperature Sensor Java Tutorial
by Dcube Tech Ventures in Circuits > Electronics
36 Views, 0 Favorites, 0 Comments
Raspberry Pi SI7050 Temperature Sensor Java Tutorial
SI7050 is a digital temperature sensor which works on I2C communication protocol and offers high accuracy over the entire operating voltage and temperature range. This high accuracy of the sensor is attributed by the novel signal processing and analog design. These sensors are embedded with an on-chip memory which stores the callibration data which facilitates its usage over a wide range. Here is its demonstration with Raspberry Pi using java code.
What You Need..!!
Connections:
Take a 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 SI7050 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.
Code:
The java code for SI7050 can be downloaded from our GitHub repository-DCUBE Store Community.
The code can be found here.
https://github.com/DcubeTechVentures/SI7050/blob/master/Java/SI7050.java
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.
// SI7050
// This code is designed to work with the SI7050_I2CS I2C Mini Module
import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;
import java.io.IOException;
public class SI7050
{
public static void main(String args[]) throws Exception
{
// Create I2C bus I2CBus
Bus = I2CFactory.getInstance(I2CBus.BUS_1);
// Get I2C device, SI7050 I2C address is 0x40(64)
I2CDevice device = Bus.getDevice(0x40);
// Send temperature measurement command, NO HOLD MASTER
device.write((byte)0xF3);
Thread.sleep(500);
// Read 2 bytes of temperature data
// temp msb, temp lsb
byte[] data = new byte[2];
device.read(data, 0, 2);
// Convert the data
double cTemp = (((((data[0] & 0xFF) * 256) + (data[1] & 0xFF)) * 175.72) / 65536.0) - 46.85;
double fTemp = cTemp * 1.8 + 32;
// Output data to screen
System.out.printf("Temperature in Celsius : %.2f C %n", cTemp);
System.out.printf("Temperature in Fahrenheit : %.2f F %n", fTemp);
}
}
Applications:
SI7050 can be incorporated in various systems including computer equipments, portable consumer devices and medical equipments. This sensor can be employed in cold storage chains, asset tracking as well as various industrial control systems. It plays a pivotal role in battery protection too.