Hi there!
I'm trying to connect a Pico to a MCP4728 adafruit I2C 12-bit quad DAC, but I'm not being able to.
So far I have 4 ADC sensors, ADC(4) with the onbard temperature, ADC(0), ADC(1), ADC(2) with pressure sensors.
Can anyone help me?
Thanks
import time
import machine
import struct
from mcp4728 import MCP4728
from mcp4728 import Channel
_MCP4728_DEFAULT_ADDRESS = 0x60
_MCP4728_CH_A_MULTI_EEPROM = 0x50
i2c_bus = 0x0
oil_sensor = machine.ADC(26)
gas_sensor = machine.ADC(27)
water_sensor = machine.ADC(28)
oil = oil_sensor.read_u16()
gas = gas_sensor.read_u16()
water = water_sensor.read_u16()
temp_sensor = machine.ADC(4)
temperature = temp_sensor.read_u16()
LED = machine.Pin(25, machine.Pin.OUT)
i2c = machine.I2C(0, scl=machine.Pin(9), sda=machine.Pin(8), freq=400000)
dac = MCP4728(i2c, 0x60)
while True:
LED(1)
print(oil, " oil integral") #oil valor lido pelo sensor em integral
to_volts = 0.5 / 10562
oil_2 = oil * to_volts #oil valor convertido para volts
print(round(oil_2,1), "oil volts")
oil_bar = 2.59 * oil_2 - 1.29 #oil valor convertido para BAR
print(round(oil_bar,1), "oil BAR")
print('_____________')
print(gas, "gas integral") #gas valor lido pelo sensor em integral
gas_2 = gas * to_volts #gas valor convertido para volts
print(round(gas_2,1), "gas volts")
gas_bar = 2.59 * gas_2 - 1.29 #gas valor convertido para BAR
print(round(gas_bar,1), "gas BAR")
print('_____________')
print(water, "water integral") #water valor lido pelo sensor em integral
water_2 = water * to_volts #water valor convertido para volts
print(round(water_2,1), "water volts")
water_bar = 2.59 * water_2 - 1.29 #water valor convertido para BAR
print(round(water_bar,1), "water BAR")
print('_____________')
to_volts_temp = 3.3 / 65535
temperature_2 = temperature * to_volts_temp
celsius_degrees = 27 - (temperature_2 - 0.706) / 0.001721
print(round(celsius_degrees,1), "C")
dac.a.value=int(round(oil_bar,0))
dac.b.value=int(round(gas_bar,0))
dac.c.value=int(round(water_bar,0))
dac.d.value=int(celsius_degrees)
print(dac.a.value, "oil")
print(dac.b.value, "gas")
print(dac.c.value, "water")
print(dac.d.value, "C")
print("__________________________________")
LED(0)
time.sleep(10)