Duration 11:2

Intro to Raspberry Pi Pico and RP2040 - MicroPython Part 2: I2C Sensor | Digi-Key Electronics

21 754 watched
0
371
Published 19 Apr 2021

Previously, we saw how to run a simple MicroPython program on the Raspberry Pi Pico using Thonny. We printed “Hello, World!” to the console and blinked an LED. In this tutorial, we will use the I2C module to read from a Bosch BME280 temperature, pressure, and humidity sensor. I2C is a popular communication protocol used by various chipmakers and is commonly supported by many sensors. It uses 2 lines--data and clock--and supports multiple devices on a single bus. The RP2040 has 2 I2C buses (not counting the PIO, which we will cover next). We will connect the BME280 sensor to bus 0 and use a simple program to scan the bus. This scan program looks for any devices connected to the bus and returns their addresses. The BME280 sensor can have 2 addresses: 0x76 and 0x77. If the SDO line on the breakout board is connected to 3.3V (default), the address will be 0x77. If it is connected to GND, the address will be 0x76. Next, we install the bme280.py module from this GitHub repository (https://github.com/SebastianRoll/mpy_bme280_esp8266) using the Thonny package manager. We construct a simple looping program that reads from the sensor and prints the temperature to the console once every 0.5 seconds. We recommend referring to the following documentation when working with MicroPython on the Raspberry Pi Pico: - Raspberry Pi Pico Datasheet: https://datasheets.raspberrypi.org/pico/pico-datasheet.pdf - Raspberry Pi Pico Python SDK: https://datasheets.raspberrypi.org/pico/raspberry-pi-pico-python-sdk.pdf - MicroPython API: https://docs.micropython.org/en/latest/library/ Product Links: https://www.digikey.com/en/products/detail/raspberry-pi/SC0915/13684020 https://www.digikey.com/en/products/detail/adafruit-industries-llc/2652/5604372 Related Videos: Intro to MicroPython - /watch/gI7XnSCNnv3NX Intro to Raspberry Pi Pico and RP2040 - MicroPython Part 1 - /watch/UQ5HCaQ9kCJ9H Intro to Raspberry Pi Pico and RP2040 - MicroPython Part 2 - /watch/Ek6zAszdK4bdz Intro to Raspberry Pi Pico and RP2040 - MicroPython Part 3 - /watch/wFCi9vpQMrPQi Related Project Links: Written tutorial - https://www.digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-micropython-part-2-i2c-sensor-and-module/b43e7958153f41fc9e7403df4d626ba5 Related Articles: Introduction to MicroPython - https://www.digikey.com/en/maker/blogs/2018/introduction-to-micropython Raspberry Pi Pico and RP2040 - MicroPython Part 1 - https://www.digikey.com/en/maker/projects/raspberry-pi-pico-and-rp2040-micropython-part-1-blink/58b3c31ac93649849b58824caa00529c Learn more: Maker.io - https://www.digikey.com/en/maker Digi-Key’s Blog – TheCircuit https://www.digikey.com/en/blog Connect with Digi-Key on Facebook https://www.facebook.com/digikey.electronics/ And follow us on Twitter https://twitter.com/digikey

Category

Show more

Comments - 14