tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/lsm6ds3tr/main.go (about) 1 // Connects to an LSM6DS3TR I2C a 6 axis Inertial Measurement Unit (IMU) 2 package main 3 4 import ( 5 "machine" 6 "time" 7 8 "tinygo.org/x/drivers/lsm6ds3tr" 9 ) 10 11 func main() { 12 machine.I2C0.Configure(machine.I2CConfig{}) 13 14 accel := lsm6ds3tr.New(machine.I2C0) 15 err := accel.Configure(lsm6ds3tr.Configuration{}) 16 if err != nil { 17 for { 18 println("Failed to configure", err.Error()) 19 time.Sleep(time.Second) 20 } 21 } 22 23 for { 24 if !accel.Connected() { 25 println("LSM6DS3TR not connected") 26 time.Sleep(time.Second) 27 continue 28 } 29 x, y, z, _ := accel.ReadAcceleration() 30 println("Acceleration:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000) 31 x, y, z, _ = accel.ReadRotation() 32 println("Gyroscope:", float32(x)/1000000, float32(y)/1000000, float32(z)/1000000) 33 x, _ = accel.ReadTemperature() 34 println("Degrees C", float32(x)/1000, "\n\n") 35 time.Sleep(time.Millisecond * 1000) 36 } 37 }