I have a project with DHT22. i use 2 DAC MCP4725 to export 0-5V temprature and humidity. Now i only do one of them. how to export 2 data by I2C protocol???. I make a code by mysefl but it doesn't work. Can you help me fix it???. Thank you
#include <Wire.h>
#include <Adafruit_MCP4725.h>
Adafruit_MCP4725 dac; // constructor
#include <DHT.h>;
//Constants
#define DHTPIN 7 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); ////
float hum; //Stores humidity value
float temp; //Stores temperature value
float ctemp;
void setup(void) {
Serial.begin(9600);
dac.begin(0x60);
dac.begin(0x62);
dht.begin();
}
void loop()
{
delay(2000);
//Read data and store it to variables hum and temp
hum = dht.readHumidity();
temp= dht.readTemperature();
ctemp= temp+40;
uint32_t dac_value;
Wire.beginTransmission(0x60);
Wire.write(0);
Wire.endTransmission(0x60);
dac_value = hum*4095.9/100;
dac.setVoltage(dac_value, false);
Wire.beginTransmission(0x62);
Wire.write(0);
Wire.endTransmission(0x62);
dac_value = ctemp*4095.9/120;
dac.setVoltage(dac_value, false);
}
DAC.ino (951 Bytes)