You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to have an MPU-9250 Nine-Axis (Gyro + Accelerometer + Compass) sensor driver in NodeMCU Lua.
I have the GY-91 sensor which consist of BMP280 (air pressue sensor) and MPU-9250 sensor. This sensor itself consist of MPU-6500 (accelerometer + gyroscope) and AK8963 (magnetometer).
The communication goes through I2C.
For BMP280 I use the Lua + C BME280 driver (PR #3132).
Following the discussion in #3128 I decided to write the driver purely in Lua. There is not any sophisticated mathematics needed (compared to BME280) and all the work is basically just talking to the sensor and doing some simple calculation.s
Basically I ported the Arduino MPU9250 driver to Lua - see mpu9250.lua.
For the time being the driver is still using some tmr.delay. I intend to get rid off majority or all of them once the driver is fully working - I face some issues - see below. Optimization will come later.
Limitations
For the moment the driver works only under Lua 5.3 due to several reasons:
// operator - this can be replaced with math.floor
bitwise operations - bit module is here but the expressions will get difficult to read
trigonometric functions - sin, asin and atan is needed for extended functionality of the driver. While these are available in Lua 5.3 a special module or backport of math library would be need under Lua 5.1
"main function has more than 50 local variables" - the driver needs to store all the registry addresses. Though only those that are used in the code are used (the rest is commented out) the number of local variables easily surpasses the threshold. This can be overcome but not for cloud builder users. Lua 5.3 has probably the threshold higher so the module is ok for it.
Given all this it is very tempting to stay just in Lua 5.3.
Questions
Do you think it was a good decision to do the implementation purely in Lua? The file is large. Almost 1000 lines of code (many of it being comments). So to make it run smooth it needs to be run from LFS.
The arithmetic in MadgwickQuaternionUpdate function is not too much difficult calculations (addition, multiplication) but I am not sure how this is efficient in Lua and whether a C implementation would make sense here. In the testing application the calculation speed is not an issue.
The implementation uses a lot of arrays usually with 3 items. It would not be difficult to change it to local values (a[1], a[2], a[3] -> a1, a2, a3) which would be probably more efficient. But the code would be more difficult to read. Does it worth the change?
Issues
I face an issue with the accelerometer. The Y and Z axis seem to work correctly. But for X axis I receive 0 value (registers MPU9250_ACCEL_XOUT_H and MPU9250_ACCEL_XOUT_L content is 0x80 and 0x00 respectively all the time).
Can anyone test the driver? I'm suspicious that these can be a sensor hardware issue. The sensor setup sequence seems to be correct.
The text was updated successfully, but these errors were encountered:
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Missing feature
I'd like to have an MPU-9250 Nine-Axis (Gyro + Accelerometer + Compass) sensor driver in NodeMCU Lua.
I have the GY-91 sensor which consist of BMP280 (air pressue sensor) and MPU-9250 sensor. This sensor itself consist of MPU-6500 (accelerometer + gyroscope) and AK8963 (magnetometer).
The communication goes through I2C.
For BMP280 I use the Lua + C BME280 driver (PR #3132).
Following the discussion in #3128 I decided to write the driver purely in Lua. There is not any sophisticated mathematics needed (compared to BME280) and all the work is basically just talking to the sensor and doing some simple calculation.s
Basically I ported the Arduino MPU9250 driver to Lua - see mpu9250.lua.
A working example is here: vario.lua.
For the time being the driver is still using some
tmr.delay
. I intend to get rid off majority or all of them once the driver is fully working - I face some issues - see below. Optimization will come later.Limitations
For the moment the driver works only under Lua 5.3 due to several reasons:
//
operator - this can be replaced withmath.floor
bit
module is here but the expressions will get difficult to readsin
,asin
andatan
is needed for extended functionality of the driver. While these are available in Lua 5.3 a special module or backport ofmath
library would be need under Lua 5.1Given all this it is very tempting to stay just in Lua 5.3.
Questions
MadgwickQuaternionUpdate
function is not too much difficult calculations (addition, multiplication) but I am not sure how this is efficient in Lua and whether a C implementation would make sense here. In the testing application the calculation speed is not an issue.a[1], a[2], a[3]
->a1, a2, a3
) which would be probably more efficient. But the code would be more difficult to read. Does it worth the change?Issues
I face an issue with the accelerometer. The Y and Z axis seem to work correctly. But for X axis I receive 0 value (registers
MPU9250_ACCEL_XOUT_H
andMPU9250_ACCEL_XOUT_L
content is0x80
and0x00
respectively all the time).Can anyone test the driver? I'm suspicious that these can be a sensor hardware issue. The sensor setup sequence seems to be correct.
The text was updated successfully, but these errors were encountered: