jsimmonds2

jsimmonds2

Using popular Pressure, Temperature sensor LPS25H and Circuits.I2C
Seems I either don’t understand the Circuits.I2C API or don’t understand the I2C sensor device :expressionless:

My code has to do single-byte register transfers rather than reading 3 sequentially addressed registers to get the latest Pressure value : e.g. for device at bus address 0x5d and the LSByte of the Pressure value in Register 0x28 this is what I see :

Read each byte value seperately

iex(fb2@fb2-e53f.local)24> Circuits.I2C.write_read ph_ref, 0x5d, <<0x28>>, 1
{:ok, <<241>>}
iex(fb2@fb2-e53f.local)25> Circuits.I2C.write_read ph_ref, 0x5d, <<0x29>>, 1
{:ok, <<190>>}
iex(fb2@fb2-e53f.local)26> Circuits.I2C.write_read ph_ref, 0x5d, <<0x2a>>, 1
{:ok, "?"}


Try reading the 3 registers in one go

iex(fb2@fb2-e53f.local)28> Circuits.I2C.write_read ph_ref, 0x5d, <<0x28>>, 3
{:ok, <<241, 241, 241>>}
iex(fb2@fb2-e53f.local)29>

Thanks !

Showing Posts 1 to 2

fhunleth

fhunleth

Co-author of Nerves

Normally what you’re doing would work since I2C devices usually auto-increment the destination register on multi-byte reads. It looks like the LPS25H does something special, though. Take a look at section 5.2.1 of the datasheet. It looks like if you set the high bit of the register that you’re interested in, it will auto-increment, so try this:

iex> Circuits.I2C.write_read ph_ref, 0x5d, <<0xa8>>, 3
jsimmonds2

jsimmonds2 OP

@fhunleth, thanks for being my helpful eyes once again . . works as desired now.

      {:ok, <<pressure::size(24)-little>>} = I2C.write_read state.lps25hb_ref, state.lps25hb_i2c_addr, <<0xa8>>, 3
— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews