OpenMarine

Full Version: MPU 9250 9-Axis and bmp280
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello to everyone,
i have connected mpu9250 to the raspberry and everythings work greet. Sensor has been reconized and pypilot works correctly.
From the datasheet of this sensor i have:

Pin Description
VCC-> Supply Voltage (3 – 5VDC)
GND-> Ground
SCL/SCLK-> I2C Serial Clock / SPI Serial Clock
SDA/SDI-> I2C Serial Data / SPI Serial Data Input (MOSI)
EDA-> I2C Serial Data for External Sensor Connection
ECL-> I2C Serial Clock for External Sensor Connection
AD0/SDO-> I2C Slave Address LSB / SPI Serial Data Output (MISO)
INT-> Interrupt Digital Output (Totem Pole or Open-Drain)
NCS-> Chip Select (SPI Only)
FSYNC-> Frame Sync Digital Input (Ground if not used)

I'm trying to connect bmp280 to the eda and ecl but i don't have any value in signalk.
I try different channel for the bmp280 in the 12c software that correctly show 0x68 as address, but i don't have any value in signalk.

What i have to try?
I am not clear if your MPU9250 and BMP280 are separate devices or are they all in one board?

What I2C address does the IMU use?

"I try different channel for the BMP280.." Can you explain what you mean by that?
(2023-05-17, 04:30 PM)baltika_no_9 Wrote: [ -> ]I am not clear if your MPU9250 and BMP280 are separate devices or are they all in one board?

What I2C address does the IMU use?

"I try different channel for the BMP280.." Can you explain what you mean by that?

MPU9250 and bmp250 is 2 separate devices. I'm tryng to cennect bmp280 throw the external data/clock sensor connection of the mpu9250.
The IMU use 0x68 and i suppose is the same address also for the bmp280, and it's the only i2c address that is detected by i2c software.
in the i2c openplotter software i have tried different channel... only to try a solution, but it doesn't help.
in check system i have a warning: openplotter-i2c-read not running
Ah, I see. You are trying to use the capability of the MPU9250 to drive an external sensor. Now I understand.

I suspect very much that to enable that you will need to configure the MPU to act as the master to handle the I2C data from external sensor. for a start the BMP280 will have an address which is not 0x68 (usually 76 or 77). I have no experience of that but maybe the datasheet for the IMU can help. If it were me I would connect the two devices separately, both directly to the Pi's SDA/SCL.

Sorry I can't help at the moment.
(2023-05-17, 05:14 PM)baltika_no_9 Wrote: [ -> ]Ah, I see. You are trying to use the capability of the MPU9250 to drive an external sensor. Now I understand.

I suspect very much that to enable that you will need to configure the MPU to act as the master to handle the I2C data from external sensor. for a start the BMP280 will have an address which is not 0x68 (usually 76 or 77). I have no experience of that but maybe the datasheet for the IMU can help. If it were me I would connect the two devices separately, both directly to the Pi's SDA/SCL.

Sorry I can't help at the moment.

I made as you suggest, and everything works. 

If noone else can help me with the first idea i think i'll use your way.

Thank you
(2023-05-22, 10:06 AM)markusmiles Wrote: [ -> ]1) Double-check the connection of the BMP280 to the EDA and ECL pins. Ensure that all connections are secure. 2) Make sure that the BMP280 is powered with 3-5V DC. 3) If using the I2C Bus, make sure you have the correct I2C address set for the BMP280 in the 12C software. 4) If using the SPI Bus, make sure you have the correct chip select (NCS) pin connected to the BMP280.

ChatGPT is brilliant at stating the obvious sometimes isn't it?  Rolleyes 

Have you any personal experience of connecting these two devices? No, because you're a bot.

The core of the problem is that the I2C address of the external sensor is not presented to the PI. It requires manipulation of the internal registers so the simple and straightforward answer is to connect the two devices in parallel to the Pi's SDA/SCL pins.
Chat-GPT is better if you make the correct question Big Grin But in this case ChatGPT tell me :

"""To use the Pass-Through Mode of the MPU-9250's auxiliary I2C bus, you need to follow these steps:

Connect the external sensors you want to communicate with to the AUX_DA and AUX_CL pins of the MPU-9250.

Set the MPU-9250 into Pass-Through Mode by configuring the appropriate registers. The specific register and bit configuration can vary depending on the MPU-9250 library or code you are using. Refer to the MPU-9250 datasheet or the documentation of your chosen library for the exact register and bit values.

Once the MPU-9250 is in Pass-Through Mode, the auxiliary I2C bus control logic of the MPU-9250 is disabled, and the AUX_DA and AUX_CL pins are connected to the main I2C bus using internal analog switches.

Use your main I2C bus and the corresponding I2C library or functions provided by your microcontroller to communicate with the external sensors connected to the AUX_DA and AUX_CL pins. Treat the external sensors as if they were directly connected to the main I2C bus.

By using the Pass-Through Mode, you can establish direct communication between your microcontroller and the external sensors connected to the auxiliary I2C bus of the MPU-9250. This allows your microcontroller to act as the I2C master, controlling and exchanging data with the external sensors.

Please note that the specific configuration and implementation details may depend on the MPU-9250 library or code you are using. It's recommended to consult the documentation and examples provided with the library or code for further guidance on utilizing the Pass-Through Mode for the MPU-9250's auxiliary I2C bus."""

I find the datasheet that i attached... As i want to understand more, also if i don't have a specific formation but i'm only a self-taught, i would like to understand how to connect the bpm280 in pass-though mode (pag. 23)... only to see if i can know something new.

Is correct the anwer of chatGPT? And how i can find the libreries that openplotter is using and eventually cange it? (if it is this the correct way)

If someone have time to explain me how to do it i would be very gratefull (also if i'm going to use baltika_no_9 suggestion/solution).

(2023-05-24, 06:08 PM)luchin0 Wrote: [ -> ]Chat-GPT is better if you make the correct question Big Grin But in this case ChatGPT tell me :

"""To use the Pass-Through Mode of the MPU-9250's auxiliary I2C bus, you need to follow these steps:

Connect the external sensors you want to communicate with to the AUX_DA and AUX_CL pins of the MPU-9250.

Set the MPU-9250 into Pass-Through Mode by configuring the appropriate registers. The specific register and bit configuration can vary depending on the MPU-9250 library or code you are using. Refer to the MPU-9250 datasheet or the documentation of your chosen library for the exact register and bit values.

Once the MPU-9250 is in Pass-Through Mode, the auxiliary I2C bus control logic of the MPU-9250 is disabled, and the AUX_DA and AUX_CL pins are connected to the main I2C bus using internal analog switches.

Use your main I2C bus and the corresponding I2C library or functions provided by your microcontroller to communicate with the external sensors connected to the AUX_DA and AUX_CL pins. Treat the external sensors as if they were directly connected to the main I2C bus.

By using the Pass-Through Mode, you can establish direct communication between your microcontroller and the external sensors connected to the auxiliary I2C bus of the MPU-9250. This allows your microcontroller to act as the I2C master, controlling and exchanging data with the external sensors.

Please note that the specific configuration and implementation details may depend on the MPU-9250 library or code you are using. It's recommended to consult the documentation and examples provided with the library or code for further guidance on utilizing the Pass-Through Mode for the MPU-9250's auxiliary I2C bus."""

I find the datasheet that i attached... As i want to understand more, also if i don't have a specific formation but i'm only a self-taught, i would like to understand how to connect the bpm280 in pass-though mode (pag. 23)... only to see if i can know something new.

Is correct the anwer of chatGPT? And how i can find the libreries that openplotter is using and eventually cange it? (if it is this the correct way)

If someone have time to explain me how to do it i would be very gratefull (also if i'm going to use baltika_no_9 suggestion/solution).

i try to ask it to chatgpt:

To use the Pass-Through Mode of the MPU-9250's auxiliary I2C bus in a Raspberry Pi environment, you can follow these steps:

Make sure you have the necessary libraries installed on your Raspberry Pi to communicate with the MPU-9250 and the external sensors. The most common library for I2C communication on Raspberry Pi is smbus. You can install it by running the following command in your terminal:

arduino
Copy code
sudo apt-get install -y python3-smbus
Connect the MPU-9250 and the external sensors to the appropriate GPIO pins of the Raspberry Pi. Connect VCC and GND to the respective power and ground pins of the Raspberry Pi. Connect SDA and SCL to the corresponding I2C data and clock pins (e.g., GPIO 2 and GPIO 3).

Ensure that the I2C interface is enabled on your Raspberry Pi. You can enable it by following these steps:

Run sudo raspi-config in the terminal.
Select "Interfacing Options."
Select "I2C."
Choose "Yes" to enable the I2C interface.
Reboot the Raspberry Pi for the changes to take effect.
Install the mpu9250 Python library on your Raspberry Pi. This library provides an interface to interact with the MPU-9250 sensor. You can install it using the following command:

Copy code
pip install mpu9250-raspberrypi
Write your Python code to configure the MPU-9250 into Pass-Through Mode and communicate with the external sensors connected to the auxiliary I2C bus. Here's an example code snippet to get you started:

python
Copy code
import smbus
from mpu9250 import MPU9250

# Create an instance of the I2C bus
bus = smbus.SMBus(1)  # Use 1 for Raspberry Pi 3, or 0 for earlier versions

# Define the MPU-9250 address
mpu9250_address = 0x68  # Use 0x69 if AD0 is pulled high

# Create an instance of the MPU9250 class
mpu9250 = MPU9250(bus, mpu9250_address)

# Configure MPU-9250 into Pass-Through Mode
mpu9250.set_pass_through_mode(True)

# Perform I2C operations with the external sensors connected to AUX_DA and AUX_CL pins
# Use the standard SMBus operations like bus.write_byte(), bus.read_byte(), etc.

# Example: Read from an external sensor
external_sensor_address = 0x12
register_address = 0x20
data = bus.read_byte_data(external_sensor_address, register_address)
print(f"Data from external sensor: {data}")

# Restore MPU-9250 back to normal mode if needed
mpu9250.set_pass_through_mode(False)
Modify the code according to your specific external sensor's I2C address and the operations you want to perform.

Run the Python code on your Raspberry Pi and observe the output. Make sure you have proper wiring and connections to the MPU-9250 and the external sensors.

This should give you a starting point for using the Pass-Through Mode of the MPU-9250's auxiliary I2C bus in a Raspberry Pi environment. Remember to refer to the documentation and examples of the mpu9250 library for more details and advanced usage.
"""

Is it correct? Is it possible to reverse it if something goes wrong?
I very much admire your desire to learn! I've read the datasheet for the MPU9250 to understand the operation in pass through mode.

Firstly, if you try to follow the above instructions then you have lost nothing - everything is reversible.
The problems as I see it are:
1. You will have to write and maintain your own code specific for each sensor you wish to attach. That is the only way of extracting data from the remote sensor if you go that way. Furthermore the code will only be useful for the MPU9250 which is not a current device.
2. The BMP280 can provide three sets of data - pressure, temperature and, if required, altitude. The sample code above is reading just one piece of data (data = bus.read_byte_data(external_sensor_address, register_address). I do not know how you would say, write code to ask for temperature or temperature specifically, you would need to work out which register address to query if indeed it is possible.
3. Accessing the data from your BMP280 via your own code this way means that you can't just treat it like a normal I2C device where you just configure OpenPlotter with its address and define the data streams (e,g environment.outside.pressure etc) and after that Openplotter does all the hard work and makes that data available into SignalK. How do you get the data from your code into OpenPlotter? It's not impossible that's for sure but something else you would have to develop and maintain.

Connecting the SDA/SCL pins together of the BMP280 and MPU9250 directly to the Pi solves all of the above. Or get a sensor what has both the IMU and environmental sensor together. I use a Waveshare one with a MPU9255 and BMP280 on the same device.

I'd be delighted to know how you get on if you give this a go. For practical purposes, there is a very much simpler way to proceed but if it's the wish to learn you're after then go for it, I wish you the best of luck. Quite how useful in the future knowing how to code for an MPU9250 (a device that is already end of life since 2018) will be I don't know.

The external sensor option on the MPU9250 is really intended so that the remote sensor is managed from the MPU9250 by code specifically written for the MPU9250 rather than to make that remote sensor visible to a third device in this case the Pi. Pass through is probably OK but it looks a bit like a kludge to me but I am far from an expert.

When you crack it, send the data to OpenAI !

Best of luck


Edit: And don't forget that connecting them the way I suggested is exactly how the I2C bus was designed to work. UP to 128 devices can be accessed by your Pi/ESP32/whatever on the same SDA/SCL lines as long as they have different addresses of course. Why wouldn't you make use of that simple design feature?