-
Notifications
You must be signed in to change notification settings - Fork 11
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
Add support for NAU7802 I2C load cell ADC #32
Comments
That sounds super neat, it's certainly something that would suit a dedicated thing as it's pretty awkward with the HX11. It would be a great enhancement to have multiple sensing options. |
I started looking into this today. Here are a few things I looked at.
|
Brilliant. If it's not the default, then we can probably just implement a scan when the backend is selected and throw a warning and a link to a section in the Readme or a specific readme for the alternate board. The first step would likely be busting out the boards into different backends, a config migration would set the HX11 to the default and in the config box we can make them selectable. |
I've never done any Octoprint plugin dev before but I'm taking some time tonight and this weekend to set up a proper dev envrionment and dive in. As an example I'm looking at this plugin, which involves a lot more complex real-time control of an I2C device via Octoprint. https://github.com/ArduCAM/ArducamCameraControl/blob/master/ArducamCameraControl/__init__.py Thankfully the filament scale use case is a lot simpler, since we'll have drivers to work with. I'm a bit rusty with JS frontend stuff so I'm not sure if I'll be able to get to a proper finish line this weekend but I'll be learning a lot at least. So far I'm playing with setting up a backend with the Also, I'll be looking at setting up a common "scale" superclass to provide a common interface for drivers/state to keep things as simple as possible for the frontend. |
Awesome, more than happy to review code, make suggestions. I'm a bit rusty with JS, but I did a whole bunch of KnockoutJS (which is the MVC Octoprint leans on) with a project like 10 years ago, so it's not entirely foreign to me. |
Looks like I'm actually making some decent progress on the backend parts, but I'm cuirous about your thoughts regarding the customized HX711 driver that's currently included in the project. Since its effectively got to be fully refactored to squeeze it into more standardized interfaces it may be worthwhile to just look for a readily available driver to drop in. As luck would have it, I'm pretty intimately familiar with the HX711. Recently built and debugged my own driver implementation for CircuitPython with both GPIO and RP2040 PIO (which I wish we had on the Pi, but alas, some day maybe). Its a really great, inexpensive little chip and its pretty forgiving of bitbang timing issues, to a point. There are a few different HX711 drivers available via PyPi, but these three look the most interesting:
The last one looks the most promising with the most recent development going on so I think I'm going to jump into testing it once I get through some more of the NAU7802 stuff. But if you've got a preference or other ideas I'm definitely open to hearing them. :) edit: Switched to testing |
That all sounds brilliant! So most of my input to the project was to port it to Python 3, some minor reliability improvements, and adding some build automation (DevOps Engineer by day). My thoughts would be:
The library that used C bindings looked interesting, but there wasn't a really nice clean way for it to be installed without lots of manual steps. Which realistically rules it out of being usable as a default, there are enough unknowns involved when dealing with the wiring side of things without introducing a complex set of steps to get the software component working (there is an open issue discussing it at length). |
Alright, I managed to get a decent amount of work done on getting things set up. This commit on my fork covers the following work:
The changes have been tested thoroughly with both an HX711 and a NAU7802 setup and both work reliably, which is nice. The HX711 emits occasional error messages when reads take too long but it doesn't look like a serious problem, just a fact of life with the platform. Other than that though it works remarkably well for a quick weekend hack. Changing from currently-default NAU7802 to HX711 in this initial commit just requires changing the plugins:
filament_scale:
chip: hx711 I definitely agree that the automatic settings migration is an important requirement. Along the way I ended up changing the names of some settings and replaced the original There are still a few things left to do.
Didn't get to a point where I'm comfortable making a PR but hopefully this should be a good start. Not sure if I'll have enough time to get this to the finish line in the coming weeks or months, unfortunately, but hopefully it's a step in the right direction. |
If you're happy enough for me to make suggestions or add commits/refactoring, feel free to open a draft PR anyway. We can just chip away at as time allows and get a release out the door. I think it adds some super useful functionality and looks like it could make it much easier to develop on in future. |
Got a draft PR, #33, set up with the work-in-progress from my branch. My available time in the next few weeks will be a bit unpredictable but I'm happy to collaborate on getting this figured out. :) |
Awesome! That all looks really good, I finally started playing with my printer again, and I'll |
Yeah, shipping is kinda nuts from the US suppliers for sure. It looks like Mouser AU has the SparkFun board as well as one from Mikroe that I didn't know existed, if you're looking for cheaper shipping. Looks like DigiKey AU has the SparkFun and Mikroe boards available locally too, with the Adafruit board likely coming into stock in the Fall time frame. Although I haven't tested with the Mikroe board it should theoretically work just fine, assuming they stuck to the reference design. I'm a big fan of the Qwiic/STEMMA-QT connectors though so if I had to choose I'd probably just get the SparkFun one. :) |
The NAU7802 ADC is a pretty solid ADC that has one major advantage over the HX711: I2C communication. This allows for much more reliable reads (addressing #28) from higher-level code since it doesn't require any time-sensitive bit banging while still using only four pins.
The first downside is that the NAU7802 is a bit more expensive, but not prohibitively so. While HX711 breakouts can be found in the $1-5 range from a variety of vendors, NAU7802 breakouts are typically in the $5-20 range from only a few vendors.
Its also much more complex device to set up/manage than comparatively super-simple HX711. On the other hand, that makes it a lot more configurable for different use cases, and there are already some decent drivers to work with.
Driver options/examples:
smbus2
for I2C communication, so should work on Pi and other platforms without too many issues.Blinka
compatability layer on Raspberry Pi and other platforms to work with normal Python.Boards:
The text was updated successfully, but these errors were encountered: