SergeyPiskunov/micropython-hx711

module and ZeroDivision Error -- version mismatch?

kyubird opened this issue · 2 comments

Hello! To begin with, thank you very much for your micropython scripts for hx711! I have just started with Raspberry Pi Pico and micropython, and I would have been so lost if there wasn't this github page.

I was wondering what version of Thonny IDE or MicroPython version you ran the source code in? I am using Thonny 4.0.1 with Python 3.10.6 (64-bit) and Windows 11 (64-bit), and I get the following errors:

In setup.py

Traceback (most recent call last):
File "", line 5, in
ImportError: no module named 'setuptools'

In scales.py

Traceback (most recent call last):
File "", line 38, in
File "", line 25, in stable_value
File "", line 31, in _stabilizer
File "", line 31, in
ZeroDivisionError: divide by zero

The ImportError from setup.py might be just Thonny IDE version problem as I cannot ever install that setuptools pacakage although it's in plug-ins...

The scales.py ZeroDivisionError: divide by zero I tried to fix them by inserting
except ZeroDivisionError: and it seems to fix the error itself but then it gives syntax error.

I couldn't completely solve any of these issues, so I'd be very keen to just try the versions these scripts were originally run in!

Regards,

Hello! I'm glad you have found this github page useful!
This library was tested on the ESP8266 with MycroPython on it. The code was written on a Linux PC using Pycharm. It is hard to remember the exact versions as it was 5 years ago =) I think your issue with 'setuptools' is not related to an IDE, but to the Python interpreter itself. You wrote that you used Python 3.10.6, but this library was designed for MicroPython. I'd suggest you to install
this Micropython version on your PC: https://github.com/micropython/micropython/tree/master/ports/unix
and this one for the RaspberryPi: https://github.com/micropython/micropython/tree/master/ports/rp2
Then install the HX711 library using mpip http://docs.micropython.org/en/latest/reference/glossary.html?highlight=upip#term-mip or just copy its source into your project. That should help.
As for the zero division error - I will take a look, but for now, I can suggest you a bit of a hack. You may replace
weights.append(sum([1 for current in values if abs(prev - current) / (prev / 100) <= deviation])) line
with
weights.append(sum([1 for current in values if prev == current == 0 or prev != 0 and abs(prev - current) / (abs(prev) / 100) <= deviation]))

Hello, thank you for your reply! I am using Raspberry Pi Pico, running on MicroPython. MicroPython is installed in Raspberry Pi Pico as I connected it to the laptop.
It seems like Python 3.10.6 is what the Thonny IDE is based at rather than the language Raspberry Pi Pico runs in.
I downloaded the entire github file for Micropython and extracted them but still no luck..
I am not sure if it is a compatibility/IDE issue because it is even difficult to install the most basic libraries such as mip and pip. Probably might just try a different Raspberry Pi microcontroller!