Home / Learn Verilog / Project 11: I2C Temperature Sensor Reader
Project 11: I2C Temperature Sensor Reader
Read a TMP102-style sensor and show degrees.
Theory in plain words
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.
| Level | Time | Works in simulation only? |
|---|---|---|
| Intermediate | 5 hours | Simulation 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.
| Item | What it is (in simple words) | Why you need it | Approx. 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 wires | A 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 |
| Multimeter | Measures 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
| Signal | Direction | Goes to | Note |
|---|---|---|---|
| scl | inout | sensor SCL | open-drain with 4.7k pull-up |
| sda | inout | sensor SDA | open-drain with 4.7k pull-up |
| VCC/GND | - | 3.3 V / GND | common ground |
Step 1: simulate the design
In a real design the master drives SCL and releases SDA (open-drain) so the sensor can pull it low.
Step by step
- Simulate the bus sequence and read the waveform.
- Fix SCL at 100 kHz (divide the clock by 270 for 27 MHz).
- Model SDA as open-drain: assign sda = drive_low ? 1'b0 : 1'bz.
- Check the 7-bit address in the sensor datasheet (TMP102 = 0x48).
- Show degrees on the 7-segment display.
If it does not work
| Symptom | Likely cause | Fix |
|---|---|---|
| Board not detected | Charge-only cable or no driver | Use a data cable, install the vendor driver |
| Nothing happens | Wrong pin constraints | Recheck every pin against the board manual |
| No ACK | Wrong address or no pull-ups | Add 4.7 k pull-ups; check ADD0 pin |
| Reads 0xFF | SDA stuck high | Check wiring; scope the START condition |
Quick quiz
1. Why pull-ups on I2C?
Open-drain bus.