A to D converter expansion board
We are working on this page now.
ADS1115 4 channel a to d expansion module
We are working on this page now.
Simple MicroPython code example
from machine import Pin, I2C
from time import sleep_ms
i2c = I2C(0, scl=Pin(17), sda=Pin(16), freq=400000)
ads = i2c
ads1115_addr = 0x48 # dec 72
# ads analog ins
adsIn_1 = 0
adsIn_2 = 0
adsIn_3 = 0
adsIn_4 = 0
def readAdsConfig():
ads.writeto(ads1115_addr, bytearray([1]))
result = ads.readfrom(ads1115_addr, 2)
return result[0] << 8 | result[1]
def readAdsValue(channel, config):
# add a try catch request timeout???
config &= ~(7<<12) # clear MUX
config &= ~(7<<9) # clear PGA
config |= (4 + channel)<<12
config |= (1<<15) # trigger conversion
config |= (1<<9) # Gain 4.09
config = [int(config>>i & 0xff) for i in [8,0]]
ads.writeto(ads1115_addr, bytearray([1] + config))
config = readAdsConfig()
while (config == 0x4383):
sleep_ms(10)
config = readAdsConfig()
ads.writeto(ads1115_addr, bytearray([0]))
sleep_ms(10)
result = ads.readfrom(ads1115_addr, 2)
return result[0] << 8 | result[1]
config = readAdsConfig()
while True:
print("adsIn_0 = ", readAdsValue(0, config), end = ', ')
print("adsIn_1 = ", readAdsValue(1, config), end = ', ')
print("adsIn_2 = ", readAdsValue(2, config), end = ', ')
print("adsIn_3 = ", readAdsValue(3, config))
print()
sleep_ms(100)