'Using a hex string as an address variable
I'm trying to create a few I2C objects for my raspberry pi and want to cycle through addresses 0x48..0x4B. However I can't figure out how to send the hex address value to the method properly. To simplify things, here is the code just trying to send the first value:
import board
import busio
import adafruit_ads1x15.ads1115 as ADS
i2c = busio.I2C(board.SCL, board.SDA)
address_as_int = 72
address_as_hex = hex(address_as_int)
print (address_as_hex) # returns 0x48 like it's suppose to
try:
ads0 = ADS.ADS1115(i2c, address = address_as_hex) # Errors out
except:
print(f"Didn't find a device on {address_as_hex}") # Didn't find a device on 0x48
But running this:
ads0 = ADS.ADS1115(i2c, address = 0x48)
finds my device.
My guess is that the method is seeing address_as_hex as a string and not a hex number, but even if I declare the string a hex number like this
ads0 = ADS.ADS1115(i2c, address = hex(address_as_hex))
It still doesn't see it as a proper hex address.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
