Home / Learn Verilog / Project 11: I2C Temperature Sensor Reader

Project 11: I2C Temperature Sensor Reader

Read a TMP102-style sensor and show degrees.

The short versionRead a TMP102-style sensor and show degrees.

Theory in plain words

I2C startsclsda
I2C start

In plain terms

Build an I2C master that writes a register pointer, reads two bytes from a sensor and converts them to degrees.

Why we use it

Projects turn knowledge into skill: you design, simulate, debug and finally see real hardware react.

Under the hood

Simulate in the browser, then build for your board following the steps.

Real-world use

  • Portfolio
  • Interviews
  • Learning by doing

What you will build

Build an I2C master that writes a register pointer, reads two bytes from a sensor and converts them to degrees.

LevelTimeWorks in simulation only?
Intermediate5 hoursSimulation first; sensor optional

What you need (equipment and tools)

Read this table once and you will know exactly what to buy or prepare. You can do the simulation part with only a computer and the free tools.

ItemWhat it is (in simple words)Why you need itApprox. cost
Computer (Windows, Linux or macOS)Your normal laptop or desktop. You write Verilog here and run the free tools.Simulator, synthesis and programmer all run on it.you have it
Free software: Icarus Verilog + GTKWave (simulation), Yosys + nextpnr or the vendor IDE (build), openFPGALoader (program)The programs that compile and simulate your design.Everything in this course can be simulated with only these free tools.free
FPGA development board (e.g. Tang Nano 9K, Basys 3, iCEBreaker, Arty A7)A small circuit board with an FPGA chip, an oscillator (clock), LEDs, buttons and a USB port. The FPGA is the "blank hardware" that your Verilog turns into a real circuit.This is where your design actually runs. Without it you can only simulate.about $15 (Tang Nano 9K) to $150 (Arty A7)
I2C sensor module (e.g. BME280, TMP102 or MPU6050)A small board with a sensor and an I2C interface (two wires: SDA data, SCL clock).Real data to read with your I2C master.$3-$6
4.7 kohm pull-up resistors (2 pieces)Resistors that pull a line up to 3.3 V when nobody drives it low.I2C lines are open-drain: they need pull-ups to be 1. Many modules already include them.$0.5
Breadboard + jumper wiresA plastic board with holes connected in rows; wires plug in without soldering.Connect the FPGA pins to buttons, LEDs and modules quickly and safely.$5
MultimeterMeasures voltage, resistance and continuity.Check that a pin is 3.3 V, that wires connect, and that power is correct.$10
7-segment display module (4 digits)Four digits made of seven LED bars each. One shared set of segment lines, one select line per digit.Shows numbers such as a clock or counter.$2

Connections

SignalDirectionGoes toNote
sclinoutsensor SCLopen-drain with 4.7k pull-up
sdainoutsensor SDAopen-drain with 4.7k pull-up
VCC/GND-3.3 V / GNDcommon ground

Step 1: simulate the design

Open-drain bus, write address then readVerilog: edit and run

In a real design the master drives SCL and releases SDA (open-drain) so the sensor can pull it low.

Step by step

  1. Simulate the bus sequence and read the waveform.
  2. Fix SCL at 100 kHz (divide the clock by 270 for 27 MHz).
  3. Model SDA as open-drain: assign sda = drive_low ? 1'b0 : 1'bz.
  4. Check the 7-bit address in the sensor datasheet (TMP102 = 0x48).
  5. Show degrees on the 7-segment display.

If it does not work

SymptomLikely causeFix
Board not detectedCharge-only cable or no driverUse a data cable, install the vendor driver
Nothing happensWrong pin constraintsRecheck every pin against the board manual
No ACKWrong address or no pull-upsAdd 4.7 k pull-ups; check ADD0 pin
Reads 0xFFSDA stuck highCheck wiring; scope the START condition
Tip:Keep your first board test tiny: if the LED blinks, the toolchain, cable and clock are fine. Then add your project piece by piece.

Quick quiz

1. Why pull-ups on I2C?