File tree Expand file tree Collapse file tree
lib/steami_screen/examples Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ """
2+ Displays a compass with a rotating needle based on the LIS2MDL magnetometer.
3+ """
4+
5+ from time import sleep_ms
6+
7+ import ssd1327
8+ from lis2mdl import LIS2MDL
9+ from machine import I2C , SPI , Pin
10+ from steami_screen import Screen , SSD1327Display
11+
12+ # --- Screen setup ---
13+ spi = SPI (1 )
14+ dc = Pin ("DATA_COMMAND_DISPLAY" )
15+ res = Pin ("RST_DISPLAY" )
16+ cs = Pin ("CS_DISPLAY" )
17+
18+ raw_display = ssd1327 .WS_OLED_128X128_SPI (spi , dc , res , cs )
19+ display = SSD1327Display (raw_display )
20+ screen = Screen (display )
21+
22+ # --- Sensor setup ---
23+ i2c = I2C (1 )
24+ sensor = LIS2MDL (i2c )
25+
26+ print ("Calibrate the magnetometer by moving it flat." )
27+ sensor .calibrate_minmax_2d ()
28+ print ("Calibration complete." )
29+
30+ heading = 0
31+
32+ # --- Main loop ---
33+ while True :
34+ angle = sensor .heading_flat_only ()
35+
36+ screen .clear ()
37+ screen .compass (angle )
38+ screen .show ()
39+
40+ print ("Cap:" , angle , "°" )
41+
42+ sleep_ms (50 )
You can’t perform that action at this time.
0 commit comments