Tutorial: Reading a TMP102 Temperature Sensor with Binho Nova and Python
This tutorial walks through a complete I2C sensor read workflow using the Binho Nova and Python. We will connect to a TI TMP102 digital temperature sensor, scan the I2C bus to find it, read the temperature register, convert the raw data to degrees Celsius, and build a simple temperature logging script.
The TMP102 is a common I2C temperature sensor used in industrial monitoring, server thermal management, and battery pack temperature sensing. Its I2C interface and straightforward register map make it a good starting point for learning Binho Nova’s I2C capabilities.
What You Need
- Binho Nova multi-protocol USB adapter
- TMP102 breakout board (available from Adafruit, SparkFun, or equivalent suppliers)
- 4 jumper wires
- USB cable (included with Nova)
- Python 3.7+ installed on your computer
- Binho Python package (
pip install binho)
Wiring
The TMP102 uses a standard I2C connection plus power and ground. Connect the Nova to the TMP102 breakout as follows:
| Nova Pin | TMP102 Pin | Function |
|---|---|---|
| IO0 (SCL) | SCL | I2C clock |
| IO1 (SDA) | SDA | I2C data |
| 3V3 | VCC | Power (3.3 V) |
| GND | GND | Ground |
The Nova provides a 3.3 V output on its power pin that can supply the TMP102 (which draws under 10 uA in continuous conversion mode). The I2C bus has internal pull-up resistors on most TMP102 breakout boards. If using a bare TMP102 chip, add 4.7 kOhm pull-up resistors on SDA and SCL to 3.3 V.
The TMP102’s I2C address depends on the ADD0 pin configuration:
- ADD0 to GND: address 0x48
- ADD0 to VCC: address 0x49
- ADD0 to SDA: address 0x4A
- ADD0 to SCL: address 0x4B
Most breakout boards default to 0x48 (ADD0 tied to GND).
Step 1: Install the Binho Python Package
pip install binho
This installs the Binho host adapter library, which provides Python classes for interacting with the Nova’s I2C, SPI, UART, and GPIO interfaces.
Step 2: Scan the I2C Bus
Before reading temperature data, confirm that the TMP102 is present and responding at the expected address. The following script scans all valid I2C addresses:
from binho import binhoHostAdapter
## Connect to Nova (auto-detects the first connected device)
binho = binhoHostAdapter.binhoHostAdapter()
binho.setOperationMode(0, 'I2C')
binho.setI2CFrequency(0, 400000) # 400 kHz (Fast Mode)
print("Scanning I2C bus...")
for addr in range(0x08, 0x78):
try:
result = binho.readFromAddress(0, addr, 1)
if result is not None:
print(f" Device found at 0x{addr:02X}")
except:
pass
print("Scan complete.")
If wiring is correct, you should see:
Device found at 0x48
Step 3: Read the Temperature Register
The TMP102’s temperature register is at address 0x00. It contains a 12-bit (or 13-bit in extended mode) two’s complement value representing the temperature. The default resolution is 0.0625 degrees Celsius per LSB.
## Read 2 bytes from the temperature register (register 0x00)
## First, write the register pointer
binho.writeToAddress(0, 0x48, [0x00])
## Then read 2 bytes
temp_bytes = binho.readFromAddress(0, 0x48, 2)
## Convert to temperature
raw = (temp_bytes[0] << 4) | (temp_bytes[1] >> 4)
## Handle negative temperatures (two's complement, 12-bit)
if raw > 2047:
raw -= 4096
temperature_c = raw * 0.0625
print(f"Temperature: {temperature_c:.2f} C")
At room temperature (approximately 25 degrees Celsius), you should see a value between 20 and 30 degrees. If you see 0.00 or an implausible value, check the wiring and verify the device address with the bus scan.
Step 4: Read the Configuration Register
The TMP102’s configuration register (0x01) controls conversion rate, alert functionality, and extended mode. Reading it confirms the sensor is in its default state:
## Read configuration register
binho.writeToAddress(0, 0x48, [0x01])
config = binho.readFromAddress(0, 0x48, 2)
print(f"Config register: 0x{config[0]:02X}{config[1]:02X}")
The default value is typically 0x60A0, indicating 4 Hz conversion rate, comparator mode, and 12-bit resolution.
Step 5: Build a Temperature Logger
Combining the above into a continuous temperature logging script:
from binho import binhoHostAdapter
import time
import csv
from datetime import datetime
binho = binhoHostAdapter.binhoHostAdapter()
binho.setOperationMode(0, 'I2C')
binho.setI2CFrequency(0, 400000)
TMP102_ADDR = 0x48
def read_temperature():
binho.writeToAddress(0, TMP102_ADDR, [0x00])
data = binho.readFromAddress(0, TMP102_ADDR, 2)
raw = (data[0] << 4) | (data[1] >> 4)
if raw > 2047:
raw -= 4096
return raw * 0.0625
## Log to CSV
with open('temperature_log.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(['timestamp', 'temperature_c'])
print("Logging temperature. Press Ctrl+C to stop.")
try:
while True:
temp = read_temperature()
now = datetime.now().isoformat()
writer.writerow([now, f"{temp:.2f}"])
print(f"{now}: {temp:.2f} C")
time.sleep(1.0)
except KeyboardInterrupt:
print("Logging stopped.")
binho.close()
This script reads the temperature every second and writes timestamped readings to a CSV file, useful for thermal characterization during board bring-up, environmental testing, or validating enclosure thermal design.
Next Steps
With basic I2C communication working, you can extend this approach to any I2C device: IMUs, pressure sensors, EEPROMs, PMICs, display controllers, and more. The Binho Nova’s support for I2C speeds up to 3.4 MHz covers the full range of I2C devices, from legacy 100 kHz standard mode sensors to high-speed 3.4 MHz high-bandwidth peripherals.
For teams in Bengaluru, Hyderabad, Chennai, and Pune working on multi-sensor IoT boards, the same Nova and Python approach scales to reading multiple I2C sensors in a single script, building a complete board-level diagnostic tool that exercises all I2C devices on the bus.
Why Buy from GSAS
GSAS Micro Systems is the authorized Binho engineering partner in India. We provide the Nova, Supernova, and Pulsar with INR invoicing and hands-on technical support. Our applications engineers in Bengaluru, Hyderabad, Chennai, Pune, Mumbai, and Delhi NCR help teams get started with Binho tools and develop scripted workflows for sensor validation, board bring-up, and production test. Contact us for evaluation units or a demo.
Also appears in:
Interested in Binho tools?
Talk to our application engineers for personalized tool recommendations.
More from Binho
View all →