Reading I2C registers to access e.g. MPU-9250

Hi there!

I want to access a MPU-9250 via Node-RED. Unfortunately the node-red-contrib-mpu9250 is not working anymore with newer node.js systems and up to now the git issue is pending but I need the data, so I decided to access the MPU on my own.

First I accessed it via Python, which is working. But I rather would like to use a specific node instead.
I tried node-red-contrib-i2c which offers an i2c write, a send and a scan node. I didn't need the scan node as I knew the address but it helped me to understand that the node only accepts decimal format.
So, instead of 0x68 I entered 104 and could communicate with the MPU-9250.

However, I can't find any easy way to read just a specific register or a dump of all registers. So what i2cdump or i2cget offers.
I can send commands, set it to specific modes and send a read command afterwards but I am looking for an easy way to read a specific register.

Does anyone know if this is existing? It is working with an exec node using i2cget directly but... not the nicest way to solve it.

Update:

I did take a different way now. I did install node-red-contrib-python-function and was able to add Python to Node-RED. In Python I am able to talk to the MPU9250, read out registers etc. So, this way works now...

It would be nice if you shared a little more of what you did. Maybe a flow? Looking at same chip

Hi Gerry,

Of course. I am still optimizing it - e.g. tilt compensation for the compass values but this shouldn't take too long. And calibration is something I want to add.
I started to use a public Python library first but as this doesn't take over much effort, I decided to read out the registers on my own, just using the "smbus" library to access I2C.
Works great. Only drawback on this solution is that Python is running in a kind of virtual environment. If you make a mistake which leads to a compiler error but you are triggering the node e.g. each 0,5 seconds, it is hard to get a new build deployed as this process is not stopped. So, you should always stop the inject node interval first.

I did attach some picture. The main code is the "read mpu 9250" node, too much code to copy it. But if you need it already now, I can send the flow. Otherwise I would first finalize tilt compensation and maybe calibration.
dashboard


prepare_pyhton

You can start node red without starting the flows using node-red --safe. Then you can fix it and then deploy.

I've hit that limit myself here, not sure of a way around it, maybe send it direct message?

Thanks - but usually I get it deployed with some attempts. So, no worries. Just not as convenient compared to the JAVA function node.

But good news: I got it working now. Including the calibration. This was a sort of a nightmare, as the bias-offsets are in 16bit register with a 15bit number, bit zero is preserved which needs a lot of bit manipulation to get it sorted out. And the register is always using +-16g full scale while I use 2g, this needs to be taken into consideration as well.

So, it took a while to get this working.

I got pitch and roll and calibration, all based on the accelerometer. I also got all raw values of all sensors and the corrected temperature value.
I didn't solve the magnetic heading/yaw fully yet due to a lack of time and the correction for heading is more complicated compared to pitch and roll. You need to find the position based on roll and yaw to correct the magnetometer reading to get the real north. This is postponed, happy that the other part is working.

I will test it within the next days and create a description within the next 2-3 weeks. If you need this one, send me a note and I can forward the current status.
The main routine got a bit longer now...

Sent you a direct message

Got the message and did send the flow via mail. And some further information...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.