Rich_Morin
Connecting to BerryGPS-IMUv3
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?
Most Liked
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(30in base 10) for the magnetometer and accelerometer0x6A(106in base 10) for the gyroscope0x77(119in base 10) for the pressure sensor
Or, on version 3 (which seems to be yours):
0x6A(106in base 10) for the gyroscope and accelerometer0x1C(28in base 10) for the magnetometer0x77(119in 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
0x1Cfor the next steps - Set a few of registers to enable the magnetometer:
- register
CTRL_REG5_XMto0b11110000 - register
CTRL_REG6_XMto0b01100000 - register
CTRL_REG7_XMto0b00000000
- register
- Read a block of data (6 bytes it seems) starting from
OUT_X_L_Mas 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.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








