Traduit de English par IA ·
« cmd » est une appellation SMBus. Dans une écriture par blocs SMBus, le premier octet après l’adresse s’appelle l’octet de commande, et pour les circuits basés sur des registres comme l’ADS1115, cet octet est le pointeur de registre. Votre première ligne place donc le pointeur sur le registre Config (0x01) et y écrit 0xC3 puis 0x83. Sur le bus : start, 0x90, 0x01, 0xC3, 0x83, stop.0xC383 signifie : lancer une conversion unique, AIN0 par rapport à GND, plage ±4,096 V, mode single-shot, 128 échantillons/s. La lecture place le pointeur sur 0x00 (registre de conversion) et lit deux octets.Votre bug vient de l’ordre des octets. L’ADS1115 envoie d’abord l’octet de poids fort, et le résultat est signé :
data = bus.read_i2c_block_data(0x48, 0x00, 2)
raw = (data[0] << 8) | data[1]
if raw > 0x7FFF:
raw -= 0x10000
volts = raw * 4.096 / 32768
Avec les octets inversés, une petite variation dans l’octet de poids faible devient un énorme saut, ce qui explique vos 900 contre 52 000. Pour AIN1, modifiez les bits MUX : [0xD3, 0x83]. Et 10 ms suffisent à 128 SPS (une conversion dure environ 8 ms), donc la temporisation convient.
« cmd » is SMBus naming. In an SMBus block write the first byte after the address is called the command byte, and for register-based chips like the ADS1115 that byte is the register pointer. So your first line puts the pointer on the Config register (0x01) and writes 0xC3 then 0x83 into it. On the wire: start, 0x90, 0x01, 0xC3, 0x83, stop.
0xC383 means: start a single conversion, AIN0 against GND, ±4.096 V range, single-shot mode, 128 samples/s. The read sets the pointer to 0x00 (Conversion register) and reads two bytes.
Your bug is the byte order. The ADS1115 sends the most significant byte first, and the result is signed:
data = bus.read_i2c_block_data(0x48, 0x00, 2)
raw = (data[0] << 8) | data[1]
if raw > 0x7FFF:
raw -= 0x10000
volts = raw * 4.096 / 32768
With the bytes swapped, a small change in the low byte becomes a huge jump, which is your 900 vs 52,000. For AIN1 change the MUX bits: [0xD3, 0x83]. And 10 ms is enough at 128 SPS (one conversion is about 8 ms), so the sleep is fine.

