You are on page 1of 11

“Practical IoT with

Raspberry Pi”
Module 4-2:Serial Protocols
“Practical IoT with Raspberry Pi”

Raspberry ports

• UART
• I2C
• SPI

Module 4-2: Serial Protocols Speaker: Jorge Artieda


“Practical IoT with Raspberry Pi”

I2C

SPI

Module 4-2: Serial Protocols Speaker: Jorge Artieda


“Practical IoT with Raspberry Pi”

I2C

https://www.amazon.es/gp/product/B013G6FZVS
Module 4-2: Serial Protocols Speaker: Jorge Artieda
“Practical IoT with Raspberry Pi”

Enable I2C

Module 4-2: Serial Protocols Speaker: Jorge Artieda


“Practical IoT with Raspberry Pi”

Detect devices I2C


sudo i2cdetect -y 1

Install services
git clone https://github.com/adafruit/Adafruit_Python_BMP.git
cd Adafruit_Python_BMP
sudo python3 setup.py install

Module 4-2: Serial Protocols Speaker: Jorge Artieda


“Practical IoT with Raspberry Pi”

Python code

import Adafruit_BMP.BMP085 as BMP085

sensor = BMP085.BMP085()

print 'Temp={0:0.2f} *C'.format(sensor.read_temperature())


print 'Pressure={0:0.2f} Pa'.format(sensor.read_pressure())
print 'Altitude={0:0.2f} m'.format(sensor.read_altitude())
print 'Sealevel Pres.={0:0.2f} Pa'.format(sensor.read_sealevel_pressure())

Module 4-2: Serial Protocols Speaker: Jorge Artieda


“Practical IoT with Raspberry Pi”

DHT11

Module 4-2: Serial Protocols Speaker: Jorge Artieda


“Practical IoT with Raspberry Pi”

Install library

sudo apt-get install git build-essential python-dev


git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo python3 setup.py install

Module 4-2: Serial Protocols Speaker: Jorge Artieda


“Practical IoT with Raspberry Pi”

Python code

#!/usr/bin/python
import Adafruit_DHT
sensor = Adafruit_DHT.DHT11
pin = 23
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature,
humidity))
else:
print('Failed to get reading. Try again!')

Module 4-2: Serial Protocols Speaker: Jorge Artieda


“Practical IoT with Raspberry Pi”

Conclusion

• SPI, I2C, etc


• Pressure sensor
• Humidity sensor

Module 4-2: Serial Protocols Speaker: Jorge Artieda

You might also like