A Go API to control an MLX90614 temperature sensor using a Raspberry Pi. Uses periph.io to handle I2C communication with the sensor.
func main() {
// Create a new connection to the sensor. An empty bus ("") uses the first
// available I2C bus. A 0 address uses the default address of this sensor
// (0x5A). You can also use mlx90614.Addr as the address.
sensor, err := mlx90614.New("", 0)
if err != nil {
log.Fatal(err)
}
// Don't forget to close the sensor after using it.
defer sensor.Close()
// This function returns a type mlx90614.Temperature that can output the
// value in t.Celsius(), t.Kelvin(), and t.Fahrenheit().
tA, err := sensor.TAmbient()
if err != nil {
log.Fatal(err)
}
tO, err := sensor.TObject1()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Ambient temperature: %.2f C", tA.Celsius())
fmt.Printf("Object temperature: %.2f C", tO.Celsius())
}