New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QMC5883L support for hmc5883l.c module (#2187) #2188
Conversation
app/modules/hmc5883l.c
Outdated
uint32_t sda; | ||
uint32_t scl; | ||
|
||
platform_print_deprecation_note("hmc5883l.init() is replaced by hmc5883l.setup()", "in the next version"); | ||
platform_print_deprecation_note("hmc5883l.init() is replacd by hmc5883l.setup()", "in the next version"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a spelling mistake.
app/modules/hmc5883l.c
Outdated
@@ -106,11 +176,22 @@ static int hmc5883_read(lua_State* L) { | |||
return 3; | |||
} | |||
|
|||
static int xmc5883_read(lua_State* L) { | |||
uint8_t i2c_addr; | |||
i2c_addr = xmc5883_identify(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a delay on each call of read(). Why not save the i2c_addr in xmc5883_i2c_addr (as part of setup/init) and then just access the right address immediately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was considering approach you suggested, but I wasn't really sure if nodemcu modules stores their states between each LUA command call - that's why I decided to determine chip type each time. But if it's possible to store such value, then I'll do it the way you suggest.
4a97b82
to
220d07d
Compare
220d07d
to
ff7bb2d
Compare
Changes commited |
I'd merge this one if there's confirmation that HMC5883L isn't broken. @pjsg maybe? |
@devsaurus hold on for a moment, please. Few days ago I've found a minor issue with my change, when used with HMC/QMC disconnected from I2C bus. By default in such case it should throw error luaL_error(L, "device not found") but it doesn't happen (I suspect it's because module identification done here: https://github.com/infrat/nodemcu-firmware/blob/ff7bb2d525815ab65a56b03ec19776a3387f12d8/app/modules/hmc5883l.c#L55 ) It doesn't affect the library in way making it unusable, but it's a bug and I should fix it. |
I don't have either device.... |
I have used the HMC library from the latest master build successfully, and the "device not connected" error is thrown when the HMC is not on the bus. I have not tested this particular HMC build. However, I had some additions to the module in mind, since, at least for the HMC chip, I think the module is too simple and can be made much better. I have opened #2206 for that and planned to make some changes over the Christmas holidays myself. My idea is that for the HMC, and really for any compass module, it is good to have the library output the heading value, since the NodeMCU does not have built-in trigonometry and have more configuration options than just reading the raw data with some given presets. Unfortunately, I only have the HMC chip so I can add features only for that at this time. I would like to hear your thoughts on this. |
A fundamental problem is that the module name is equal to the chip name. Hence, someone looking for support for QMC5883L would be disappointed because he/she would only see HMC5883L in the modules list. The same applies for search engines of course. We can change the title on line 1 in |
Yeah, I agree with you but in fact it's quite hard to deal with that. For the moment, I see two ways: we can do it as is done in this PR, or create separate library for QMC. The question is which is better? Even I can't say which is better to me. Both solutions has pros and cons. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change title in documentation and navigation item name as proposed at #2188 (comment)
I studied the datasheets of the two chips and understand the headaches here better now. Both only share the same model number 5883 and the fact that they're magnetometers. Apart from these, register interface and operation modes differ. Initially I though that QMC5883 would be the bigger/newer/extended version of HMC5883 but no - they're different architectures IMO.
I would avoid that for the reasons above.
Not my favorite solution but provides a better separation. Third alternative (same topic as #1242 (comment)): Remove the chip-specific module and integrate HMC5883 and QMC5883 (and future ones) in a hmc = magnetometer.hmc5883l(i2c_id)
newconfig = hmc:setup({MS=0, DO=4, MA=3, GN=1, MD=1}) -- normal measurement, 15Hz, 8 avg, single-shot mode
-- wait some time or wait for GPIO trigger by DRDY
x, y, z = hmc:read()
qmc = magnetometer.qmc5883l(i2c_id) Implementations on C level would be quite specific to the chip type, same for the Pros
Cons
What do you think - would this third option be a feasible way out? |
@devsaurus if you compare block diagrams of both chips - they're very similar. From architectural point of view there are not too much differences between them. They have different registers addressing, and probably clock is little bit different too. Sad thing is that many manufacturers use QMC and HMC interchangeably what makes customers little bit confused (like in my case). Regarding module code, third option you suggested I like the most. It seems to be clear enough and straightforward. Do we have any modules using such architectural approach? |
u8g and ucg are the only ones if I remember correctly, but they are quite complex to serve as a blueprint. Given there's consensus to head into this direction (@marcelstoer, @pjsg?) then I'd volunteer to set up such a module including current hmc5883l code. I don't intend to offload this maintenance effort to you 😃. |
we're heading into a different (better) direction
OFC direction! because it's a magnetometer ;) @devsaurus I think I can try to setup both modules in the way you suggested, so don't worry. I'd be really happy to have some influence on this project. At least, if I wouldn't manage I'll ask you for some help. |
Ok, then let's close this PR and either @infrat or @devsaurus will create a new one. |
Thanks you very for your support! It's highly appreciated. It's not urgent at all from my point of view. Feel free to come up even with a prototype if you look for early feedback. |
Fixes #2187 .
dev
branch rather than formaster
.docs/en/*
.QMC5883L chip support introduced to hmc5883l.c library. Unfortunately, I don't have magnetometer based on HMC5883L chip to test it. My changes are tested ONLY with QMC5883L!