Publishing temperature sensor data

Now we're going to implement simple code that can be used to read TMP102 temperature sensor data through the Raspberry Pi I2C bus 1. Listing 4-2 presents the Java class TemperatureSensor.java, which can be used to read the sensor data from TMP102 with the pi4j library. Add a new Java class file to your project by right-clicking on the IoTDashboard node, and from the context menu, click New|Java Class. Type Temperature Sensor in the Class Name text box and click the Finish button. An empty class file will be added to your project. Type all the lines listed under listing 4-2.

Listing 4-2: TemperatureSensor.java

    package com.packt.B05688.chapter4;import com.pi4j.io.i2c.I2CBus;import com.pi4j.io.i2c.I2CDevice; ...

Get Raspberry Pi 3 Projects for Java Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.