BrunoB81HK / PyNAU7802

Python port of the SparkFun Qwiic Scale NAU7802 Arduino Library
MIT License
10 stars 6 forks source link

[feature request] include i2c port number as an arg for initialization #4

Closed WillMorris510 closed 3 years ago

WillMorris510 commented 3 years ago

Users could initialize class instances on extra i2c ports added to /boot/config.txt, allowing multiple boards to connect to the RP.

BrunoB81HK commented 3 years ago

Hi Will,

Thanks you for your request!

I'm not quite sure if you mean a different I2C port or a different I2C address.

Port

While I have not personally tried it, I think it is already possible to do. Just create another bus in your script as such :

# Create the bus
bus1 = smbus2.SMBus(1)
bus2 = smbus2.SMBus(2)

# Create the first scale and initialize it
scale1 = PyNAU7802.NAU7802()
if scale1.begin(bus1):
    print("Connected!\n")
else:
    print("Can't find the scale, exiting ...\n")
    exit()

# Create the second scale and initialize it
scale2 = PyNAU7802.NAU7802()
if scale.begin(bus2):
    print("Connected!\n")
else:
    print("Can't find the scale, exiting ...\n")
    exit()

Address

The NAU7802 address is permanently programmed with “0101010” (0x2A). It would not be useful to change it since it is the only address possible.

If I misunderstood your request, be sure to let me know!

WillMorris510 commented 3 years ago

I see! I had misunderstood the declaration of begin to have port 1 hardcoded in when the bus is created. Hadn't been able to try since I'm waiting for more 7802's to arrive and I'm new to Python. Thank you for the detailed explanation it was very helpful.

BrunoB81HK commented 3 years ago

No problem, do not hesitate if you have any other questions!