Skip to content

Instantly share code, notes, and snippets.

@ringvold
Created September 3, 2022 23:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ringvold/fe343f12d54bb6286231be47577d6d7b to your computer and use it in GitHub Desktop.
Save ringvold/fe343f12d54bb6286231be47577d6d7b to your computer and use it in GitHub Desktop.

BMP280

Mix.install([
  {:kino, "~> 0.6.1"},
  {:kino_vega_lite, "~> 0.1.1"}
])

alias VegaLite, as: Vl

Section

Circuits.I2C.detect_devices()
{:ok, bmp} = BMP280.start_link(bus_name: "i2c-1", bus_address: 0x77)
BMP280.measure(bmp)
widget =
  Vl.new(width: 400, height: 400)
  |> Vl.mark(:line)
  |> Vl.encode_field(:x, "x", type: :quantitative)
  |> Vl.encode_field(:y, "y", type: :quantitative)
  |> Kino.VegaLite.new()
  |> Kino.render()

Kino.VegaLite.periodically(widget, 200, 0, fn i ->
  {:ok, measurement} = BMP280.measure(bmp)
  point = %{x: i, y: measurement.temperature_c}
  Kino.VegaLite.push(widget, point, window: 500)
  {:cont, i + 1}
end)
widget =
  VegaLite.new(width: 400, height: 400)
  |> VegaLite.mark(:line)
  |> VegaLite.encode_field(:x, "X", type: :quantitative)
  |> VegaLite.encode_field(:y, "Y", type: :quantitative)
  |> Kino.VegaLite.new()
  |> Kino.render()

Kino.VegaLite.periodically(widget, 200, 0, fn i ->
  {:ok, measurement} = BMP280.measure(bmp)
  point = %{x: i, y: measurement.temperature_c}
  Kino.VegaLite.push(widget, point, window: 100)
  {:cont, i + 1}
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment