MCP4725 12bit DAC question(s)

I have a sketch running a Nova Sensor NPA-201-EV breakout board pressure transducer. Data is being displayed to a LCD display. Everything so far works just fine. But I need an analog voltage output that is proportional to the output of the pressure transducer. I added an Adafruit MCP4725 DAC thinking it was an easy I2C addition, but apparently not. I thought the MCP4725 once activated read what was on the I2C bus and converted to a voltage output. But apparently I'm missing something. My programing skills are limited, so I could use a little help here.

So far the only voltage output I get is whatever I set the dac.setVoltage(0, false); to, in this case "0". But the analog voltage does not change when I apply a vacuum to the pressure transducer. What am I missing?

Thanks
-Dan

#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac;

// Set this value to 9, 8, 7, 6 or 5 to adjust the resolution
#define DAC_RESOLUTION (8)

#include <LiquidCrystal.h>
/*#define TCAADDR 0x70
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
*/
const int sensor_addr = 0x00;
const int read_delay = 20;

int rbuf[5];
float P, T, Pconv, Tconv;
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); //Digital pins to which you connect the LCD

void setup() {

dac.begin(0x62);
dac.setVoltage(0, false);

lcd.begin(16,4);

}

void loop() {

// NPA201 barometric pressure sensor
int i;
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(250000); // start serial communication

Wire.beginTransmission(sensor_addr); // transmit to device
Wire.write(0xAC); // send command for full sensor read
Wire.endTransmission(); // stop transmitting

delay(read_delay); // datasheet suggests at least 20 milliseconds

if (Wire.requestFrom(sensor_addr, 5) >= 0) {
i = 0;
for (i = 0; i < 5; i++) {
rbuf = Wire.read();

  • }*

  • // Join two bytes for to make 16-bit readings for pressure and temp*

  • P = word(rbuf[1],rbuf[2]);*

  • T = word(rbuf[3],rbuf[4]);*

  • // Convert using formula in data sheet*
    _ Tconv = T / 65535 * (85+40) - 40;_
    _ Pconv = P / 65535 * (1260 - 260) + 260;_

  • Serial.print (rbuf[0]); Serial.print(" "); Serial.print ("rbuf[0] /"); //Serial.print(byte(rbuf[0]));*

  • Serial.print (rbuf[1]); Serial.print(" "); Serial.print ("rbuf[1] /"); //Serial.print(byte(rbuf[1]));*

  • Serial.print (rbuf[2]); Serial.print(" "); Serial.print ("rbuf[2] /"); //Serial.print(byte(rbuf[2]));*

  • Serial.print (rbuf[3]); Serial.print(" "); Serial.print ("rbuf[3] /"); //Serial.print(byte(rbuf[3]));*

  • Serial.print (rbuf[4]); Serial.print(" "); Serial.print ("rbuf[4] /"); //Serial.print(byte(rbuf[4]));*

  • Serial.print (rbuf[5]); Serial.print(" "); Serial.print ("rbuf[5] "); Serial.print(byte(rbuf[5]));*

  • Serial.print (T); Serial.print(" "); Serial.print ("T "); Serial.print(byte(T));*

  • Serial.print (P); Serial.print(" "); Serial.print ("P "); Serial.print(byte(P));*

  • Serial.println();*
    /*
    //lcd.clear();
    lcd.setCursor(0,0);
    lcd.print ("Pres: ");
    lcd.print ((Pconv/68.94744825)-0.0);
    lcd.print("psi");
    lcd.print(" ");
    //lcd.clear();
    lcd.setCursor(0,1);
    lcd.print ("Temp: ");
    lcd.print ((Tconv*9/5)+32);
    lcd.print("F");
    lcd.print(" ");
    lcd.setCursor(0,2);
    lcd.print (T);
    lcd.print(" ");
    lcd.setCursor(0,3);
    lcd.print (Tconv);
    lcd.print(" C");
    //lcd.print(" ");
    */

  • //lcd.backlight();*

  • lcd.setCursor(0,0); lcd.print(Pconv); lcd.setCursor(7,0); lcd.print("mb"); //lcd.setCursor(10,0); lcd.print("P="); lcd.setCursor(12,0); lcd.print(P);*

  • lcd.setCursor(0,1); lcd.print(Pconv/68.94744825); lcd.setCursor(5,1); lcd.print("psi"); lcd.setCursor(9,1); lcd.print(Pconv/33.8639); lcd.setCursor(14,1); lcd.print("Hg");*
    _ lcd.setCursor(0,2); lcd.print(Tconv); lcd.setCursor(5,2); lcd.print("C"); lcd.setCursor(10,2); //lcd.print("T=");lcd.setCursor(12,2); lcd.print(T);_
    _ lcd.setCursor(9,2); lcd.print((Tconv
    1.8)+32); lcd.setCursor(14,2); lcd.print("*F");_

  • lcd.setCursor(0,3); lcd.print(millis()/1000);*

  • //lcd.setCursor(0,1);*

  • //lcd.print(T);*

  • // lcd.setCursor(0,2);*
    // lcd.print(Tconv);

  • // lcd.setCursor(0,3);*

  • delay(1000); // delay in msec*

  • }*
    }

hitecdan:
#define DAC_RESOLUTION (8)

Cool 8)

hitecdan:
So far the only voltage output I get is whatever I set the dac.setVoltage(0, false); to, in this case "0".

That is the only place in your code where you call dac.setVoltage().
At the point in your code where you want to change the output voltage of the DAC, you have to call this function passing the value you want to output.

Use code tags </> to post code without unwanted modifications. See the top entries in this forum...

Thanks for the help. I added dac.setVoltage(Pconv, false); to the loop and now I'm getting a voltage out the seems to follow pressure changes to the transducer.

-Dan