tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/bmp180/main.go (about)

     1  package main
     2  
     3  import (
     4  	"time"
     5  
     6  	"machine"
     7  
     8  	"tinygo.org/x/drivers/bmp180"
     9  )
    10  
    11  func main() {
    12  	machine.I2C0.Configure(machine.I2CConfig{})
    13  	sensor := bmp180.New(machine.I2C0)
    14  	sensor.Configure()
    15  
    16  	connected := sensor.Connected()
    17  	if !connected {
    18  		println("BMP180 not detected")
    19  		return
    20  	}
    21  	println("BMP180 detected")
    22  
    23  	for {
    24  		temp, _ := sensor.ReadTemperature()
    25  		println("Temperature:", float32(temp)/1000, "°C")
    26  
    27  		pressure, _ := sensor.ReadPressure()
    28  		println("Pressure", float32(pressure)/100000, "hPa")
    29  
    30  		altitude, _ := sensor.ReadAltitude()
    31  		println("Altitude", altitude, "meters")
    32  
    33  		time.Sleep(2 * time.Second)
    34  	}
    35  }