Skip to content
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

Trouble using in Micropython #2

Open
ProblemSolved99 opened this issue Oct 1, 2021 · 5 comments
Open

Trouble using in Micropython #2

ProblemSolved99 opened this issue Oct 1, 2021 · 5 comments

Comments

@ProblemSolved99
Copy link

Hi,

This library is awesome and I appreciate you putting the work into porting to Python.

I am trying to use this library in the micropython environment so I can use it with a Digi Xbee3.

I was able to locate a smbus library that provides an SMBus class for use on micropython.

I used an arduino to confirm Sparkfun board and load cell are working as expected.

I am able to use a I2C scan example for the Xbee3 to confirm that I am detected the breakout board properly and it is at the expected address (0x2A).

I am able to get through myScale.begin() without issue, but it appears when getReading() is called I get hung up on the self.available() which is always false.

Any suggestions would be very appreciated.

Thanks!

@amotl
Copy link

amotl commented Oct 2, 2021

Hi there,

first things first: Thank you very much for developing this Python-based implementation for driving the NAU7802, Will!

Then, also thanks a stack for bringing up the topic of MicroPython support, @ProblemSolved99. We are also looking for this to integrate into our datalogger application, see hiveeyes/terkin-datalogger#75. Some discussions around that topic can be found at, for example, [1] and [2]. While some of those resources are in German, you can use the translation feature when signing up as a member.

Looking at adapting the lowlevel interface to the I2C bus by using micropython-smbus is a sweet idea, it would be nice if this could work well.

With kind regards,
Andreas.

[1] https://community.hiveeyes.org/t/diskussion-zum-nuvoton-nau7802-24bit-2ch-adc/3237
[2] https://community.hiveeyes.org/search?q=nau7802

@amotl
Copy link

amotl commented Oct 2, 2021

Hi again,

I conducted some research and found those details I would like to share here.

It looks like the nau7802py library is using the read_byte and write_word_data methods of SMBus:

However, it looks like those methods are not implemented in the canonical version of the micropython-smbus library by @gkluoe, see init.py#L52-L67.

On the other hand, there has been a report by @MrRubberDucky99 at gkluoe/micropython-smbus#3 where @gkluoe followed up on by submitting gkluoe/micropython-smbus@23211716, implementing read_byte and write_byte. However, it looks like this has not been tested and integrated yet due to a lack of feedback.

Maybe we could use the energy from @ProblemSolved99 to investigate further and fill some gaps.

With kind regards,
Andreas.

@amotl
Copy link

amotl commented Oct 2, 2021

Dear @ProblemSolved99,

when looking at the code once more, taking my findings from above into consideration, the outcome from calling the begin() method is probably always False, because isConnected() would also return False.

nau7802py/nau7802py.py

Lines 143 to 154 in 294c415

# Sets up the NAU7802 for basic function
# If initialize is true (or not specified), default init and calibration is performed
# If initialize is false, then it's up to the caller to initalize and calibrate
# Returns true upon completion
def begin(self, initialized = True): # Check communication and initialize sensor
# Check if the device ack's over I2C
if self.isConnected() == False:
# There are rare times when the sensor is occupied and doesn't ack. A 2nd try resolves this.
if self.isConnected() == False:
return False

nau7802py/nau7802py.py

Lines 275 to 282 in 294c415

# Returns true if device is present
# Tests for device ack to I2C address
def isConnected(self): # Returns true if device acks at the I2C address
try:
self.bus.read_byte(self.deviceAddress)
return True
except:
return False

Because the exception raised when calling the method read_byte, which is not implemented, gets silently ignored, there is no indicator that this went wrong. So, I would be excited to hear back from you about the outcome when you start filling this gap by using gkluoe/micropython-smbus@23211716.

With kind regards,
Andreas.

@gkluoe
Copy link

gkluoe commented Oct 4, 2021

Hi All, just a note to say I'd love it if you could test the implementation of these in my usmbus module, as I still have no way to test it myself.

The updated version lives on a branch here: https://github.com/gkluoe/micropython-smbus/tree/%233 and you can find the raw file here: https://raw.githubusercontent.com/gkluoe/micropython-smbus/%233/usmbus/__init__.py

@WackoKacko
Copy link

Hey, guys. Two years later, I've got a NAU7802 and an ESP32 Wroom to test this with. There's still no MicroPython library for this thing, only a CircuitPython library, but I haven't been able to port it.

I've implemented micropython-smbus into my project and added implementations for read_byte(), write_byte(), read_word_data(), and write_word_data(), but my program can't get past myScale.begin() for Example 1 in this repo. Not sure how you got as far as you did, @ProblemSolved99. According to @amotl, .begin() shouldn't be returning True, which makes sense given what he shows.

I've published what I've tried here.

I'll give converting from CircuitPython to MicroPython tomorrow another go, I suppose, unless someone has some great news for me.

Cheers, guys.
-KB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants