This is a simplified version Masatoshi Nishiguchi's bmp280.livemd
notebook that's
included in Nerves Livebook. Check out that notebook if you'd like to try this out yourself.
Mix.install([
:bmp280,
{:kino, "~> 0.6.2"},
{:vega_lite, "~> 0.1.6"}
])
alias VegaLite, as: Vl
Circuits.I2C.detect_devices()
{:ok, bmp} = BMP280.start_link(bus_name: "i2c-1", bus_address: 0x77)
BMP280.measure(bmp)
widget =
Vl.new(width: 700, height: 400, title: "BME280 Temperature")
|> Vl.mark(:line)
|> Vl.encode_field(:x, "x", title: "Sample #", type: :quantitative)
|> Vl.encode_field(:y, "y", title: "Celsius", type: :quantitative)
|> Vl.encode_field(:color, "key", type: :nominal, title: nil)
|> Kino.VegaLite.new()
|> tap(&Kino.render/1)
Kino.VegaLite.periodically(widget, 100, 0, fn i ->
{:ok, measurement} = BMP280.measure(bmp)
points = [
%{key: "Temperature", x: i, y: measurement.temperature_c},
%{key: "Dew Point", x: i, y: measurement.dew_point_c}
]
Kino.VegaLite.push_many(widget, points, window: 100)
{:cont, i + 1}
end)