Raspberry Pi Pico weather display (MicroPython)
Your first MicroPython project: temperature and humidity on an OLED.
Shop by category
Shop all componentsThe ADXL345 feels gravity on three axes, and a little trigonometry turns that into pitch and roll angles. The OLED draws a bubble that slides as you tilt the board, with the angles in degrees on top. Handy for levelling a shelf, a 3D printer bed or a camera.
Tick anything you already have and the total updates.
Three-axis accelerometer that feels gravity and bumps, so it can measure tilt angles and detect knocks, drops and vibration.
Follow the colours: red is power, dark grey is ground, blue is a signal.
main.py# Pico spirit level with an ADXL345 and a moving bubble on the OLED (MicroPython)
from machine import Pin, I2C
import ssd1306, time
i2c = I2C(0, sda=Pin(4), scl=Pin(5), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
import math, struct
ADXL = 0x53
i2c.writeto_mem(ADXL, 0x2D, b"\x08") # measurement mode
def tilt():
x, y, z = struct.unpack("<hhh", i2c.readfrom_mem(ADXL, 0x32, 6))
roll = math.degrees(math.atan2(y, z))
pitch = math.degrees(math.atan2(-x, math.sqrt(y * y + z * z)))
return pitch, roll
while True:
pitch, roll = tilt()
bx = int(64 + max(-50, min(50, roll * 5)))
by = int(38 + max(-22, min(22, pitch * 5)))
oled.fill(0)
oled.rect(14, 12, 100, 52, 1)
oled.hline(54, 38, 20, 1)
oled.vline(64, 28, 20, 1)
oled.fill_rect(bx - 3, by - 3, 7, 7, 1)
oled.text("%+.1f %+.1f" % (pitch, roll), 20, 0)
oled.show()
time.sleep_ms(80)
Check SDA and SCL. An I²C scanner should show 0x53 (0x1D if the ALT pin is high).
Keep the board still while it starts, and check pitch and roll are not swapped for your mounting.
Check SDA/SCL and try address 0x3D. Run an I²C scanner to confirm.
5 parts: ADXL345 Digital Acceleration Sensor Module – I2C/SPI, 3.3V/5V, 0.96" OLED Display 128x64 (I2C), Raspberry Pi Pico, Solderless Breadboard (830 points) and Dupont Jumper Wires (40 pcs). Tools: Digital Multimeter and Wire Stripper and Cutter. On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 45 minutes. The build on this page has 5 steps.
No. This page has the complete, tested code (main.py). Install this library first: ssd1306 (micropython-lib).
About ₹819 for the parts at the prices on this page, plus tools if you do not have them. Quantity price breaks lower the cost when you build several.
Accelerometers, tilt angles and shock detection; Drawing text on an I²C display.
Ideas that reuse this build: Pico ultrasonic distance OLED and Bike lean angle meter. They are listed under Take it further on this page.
Your first MicroPython project: temperature and humidity on an OLED.
A web page with ON and OFF buttons that switches a relay over Wi-Fi.
A warm ring light that fades up at dusk and down at dawn.
Turn a Pi and a touchscreen into a home command centre with a clock and to-do list.
Learning project. Check every circuit and the datasheet of each part before you power it up.