How to get I2C sensor readings

enable I2C interface

in raspi-config -> interfacing options -> I2C -> enable

connect wires

Connect SDA, SCL, V+ and GND.

../../../../_images/RasPi2_3_pin.png

use i2cdetect tool to find the device

You may need to install i2c-tools packet For lm75 sensor, after executing

sudo i2cdetect -y 1

you will see something like

../../../../_images/I2C_address_get.png

It means at address 0x48, there is a device which is lm75.

read the temperature

install smbus packet

sudo apt-get install python-smbus

coding

import smbus
import time

bus = smbus.SMBus(1)

while True:
    temp = bus.read_byte_data(0x48, 0x00)
    print(temp)
    # print("temp read is {temp}", temp)
    time.sleep(1)

result

../../../../_images/I2C_LM75_rst.png