Rich_Morin

Rich_Morin

I have a pair of BerryGPS-IMUv3 (10 DOF + GPS) HATs which I want to use with a pair of Raspberry Pi 3B+ and 4B computers, using Raspbian and Stormux (an Arch Linux ARM variant) respectively.

I’m able to talk to the device on the RasPi 3B+, using circuits_i2c, but I’m unable to get useful data from it. Here are some IEx interactions, in which I try to read the compass:

iex(1)> alias Circuits.I2C
Circuits.I2C
iex(2)> {:ok, ref} = I2C.open("i2c-1")
{:ok, #Reference<0.517024855.4042391563.14505>}
iex(3)> I2C.bus_names
["i2c-1"]
iex(4)> I2C.detect_devices  
  Devices on I2C bus "i2c-1":
   * 28
   * 106
   * 119
  3 devices detected on 1 I2C buses

iex(5)> I2C.write(ref, 0x1c, <<0xf0, 0x60, 0x00>>)
iex(6)> I2C.read(ref, 0x1c, 6)
{:ok, <<0, 0, 0, 0, 0, 0>>}
iex(7)> I2C.read(ref, 0x08, 6)
{:error, :i2c_nak}
iex(8)> I2C.read(ref, 0x28, 6)                    
{:error, :i2c_nak}

Because I find the documentation a bit confusing, I’m not sure what address(es) I need to use. More generally, it’s quite possible that I’m sending the wrong commands. Help?

Showing Posts 1 to 2

entone

entone

Nerves won’t help you in the near term, but i would highly recommend checking it out for reproducible builds.

I haven’t used those devices before, so unfortunately can’t be any help there. But it is most likely an issue with your commands. Also be sure you try both hats, maybe one of them is foobard.

lucaong

lucaong

Here you are reading from the device with address 0x08, which is not among the addresses returned by I2C.detect_devices. Same for the other read, where you use 0x28 (which is address 40 in base 10).

The documentation on the page you linked reports that the I2C addresses should be:

  • 0x1E (30 in base 10) for the magnetometer and accelerometer
  • 0x6A (106 in base 10) for the gyroscope
  • 0x77 (119 in base 10) for the pressure sensor

Or, on version 3 (which seems to be yours):

  • 0x6A (106 in base 10) for the gyroscope and accelerometer
  • 0x1C (28 in base 10) for the magnetometer
  • 0x77 (119 in base 10) for the pressure sensor

The specifics of the protocol to read the magnetometer data over I2C is explained here, while for the accelerometer/gyro data explained here (and the C code seems to refer to this source code).

You’ll have to translate the C code in the guide to Elixir, but with some patience it looks feasible, as the guide explains it step by step. The actual addresses and registers can be found in one of these two header files, depending on the specific chip in use on your board: LSM9DS0.h and LSM9DS1.h. It looks like your board mounts the LSM9DS1.

At a glance, in order to read the compass (magnetometer) you’ll have to:

  • Open the I2C bus and use address 0x1C for the next steps
  • Set a few of registers to enable the magnetometer:
    • register CTRL_REG5_XM to 0b11110000
    • register CTRL_REG6_XM to 0b01100000
    • register CTRL_REG7_XM to 0b00000000
  • Read a block of data (6 bytes it seems) starting from OUT_X_L_M as shown in the guide
  • Decode the data

Once you get the basic working, if you get stuck on something I am sure people here will be able to help.

Note: I made a few edits to this reply, as I was finding out more and more about it.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
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
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
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
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews