We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Post 60
Weather App 07 - Quick update
Published on: 2025-08-14
Tags:
elixir, Blog, Side Project, Libraries, Weather App, Poncho
For some reason I was under the impression that you needed to have a command bit for the UV sensor, that was not the case. I will keep posting all the steps it took to get this app running and will also keep working on the other sensors. But quickly here is the updated version of the relevant code.
alias Circuits.I2C
alias LTR390_UV.Config
import Bitwise
@enable_register 0x00
@gain_register 0x05
@control_register 0x04
@als_data_register [0x0D, 0x0E, 0x0F]
@uvs_data_register [0x10, 0x11, 0x12]
def discover(possible_addresses \\ [0x53]) do
I2C.discover_one!(possible_addresses)
end
def open(bus_name) do
{:ok, i2c} = I2C.open(bus_name)
i2c
end
def write_config(config, i2c, sensor) do
enable_byte = Config.to_enable_byte(config)
control_byte = Config.to_control_byte(config)
gain_byte = Config.to_gain_byte(config)
# Write ENABLE register (1 byte) with command bit set
I2C.write(i2c, sensor, <<@enable_register, enable_byte>>)
# Write CONTROL register (1 byte) with command bit set
I2C.write(i2c, sensor, <<@control_register, control_byte>>)
# Write the GAIN register
I2C.write(i2c, sensor, <<@gain_register, gain_byte>>)
end