Closed WillMorris510 closed 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
.
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()
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!
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.
No problem, do not hesitate if you have any other questions!
Users could initialize class instances on extra i2c ports added to
/boot/config.txt
, allowing multiple boards to connect to the RP.