Hi There. I have a problem. I am using a MCP428 DAC Converter together with different sensors on a TCA9548A Multiplexer. But unfortunately I can not set the different DAC output channels on the voltages I declare, instead it will always show me 5v on each Channel. Has it got something to do with the settings of the i2c adress or rather with setting on the multiplexer?
Furthermore, i am quite new and dont know much about i2c adressing.
My idea is to set the channel values with the data of my sensors (temperature, humidity and so on)
Any help wuld be great!
#include <Wire.h>
#include <Adafruit_MCP4728.h>
#define TCAADDR 0x70
Adafruit_MCP4728 mcp;
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
void setup(void)
{
Serial.begin(9600);
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MCP4728 test!");
tcaselect(0);
if (!mcp.begin()) {
Serial.println("Failed to find MCP4728 chip");
while (1) {
delay(10);
}
}
}
void loop(void)
{
tcaselect(0);
mcp.setChannelValue(MCP4728_CHANNEL_A, 4095);
mcp.setChannelValue(MCP4728_CHANNEL_B, 2048);
mcp.setChannelValue(MCP4728_CHANNEL_C, 1024);
mcp.setChannelValue(MCP4728_CHANNEL_D, 0);
mcp.saveToEEPROM();
Serial.println("Written to DAC0");
delay(5000);
}
So this code works but i always measure 5v on every channel. But when i try the same without the multiplexer, it works and i can measure different voltage on each channel.
If I scan the I2C connections it show me this. I also dont understand why there is 2 xi2c adresses on the port i connected something.

I recommend to follow Adafruit's guide exactly, and verify that everything works, before introducing any modifications.
You do not want to do this in loop. It will wear out the EEProm very rapidly.
mcp.saveToEEPROM();
I did and it works! My problem is to get it work together with the multiplexer ![]()
oh okay, thanks im gonna delete the eeprom line
You may have wired the multiplexer incorrectly, but the photo cannot be interpreted. Please post a clear, hand drawn wiring diagram, with all pins and connections clearly labeled.
Because im using a uv sensor that hast the same i2cadress as the dac converter, i couldnt figure out to use them together without multiplexer.
I will check it out if it was channel 1 and 0 switched and will get back to you tomorrow! Thanks so far.
So I checked it out switching 0 and 1 and it will still be the same, 5V on every output channel of the Dac converter ![]()
Ok, so here is a handdrawn wiring diagram and the code of everything you see in the diagram. The UV-Sensor works by the way! Again, it is not possible for me to control the voltage that is going to the jack-outputs of the DAC Converter.
#include <Adafruit_MCP4728.h>
#include <Wire.h>
#include <Adafruit_SI1145.h>
#include <SPI.h>
#define TCAADDR 0x70
//UV-Sensor von Adafruit //
Adafruit_SI1145 uv = Adafruit_SI1145();
//DAC Converter
Adafruit_MCP4728 mcp;
int A_Volt = 0;
int B_Volt = 0;
int C_Volt = 0;
int D_Volt = 0;
////Through this function, we can tell the multiplexer to toggle between its eight channels and use the I²C protocol
//to communicate to any device connected to it. So it first communicates through pins SD0 and SC0, then through pins
//SD1 and SC1, all the way up to pins SD7 and SC7.
void tcaselect(uint8_t i) {
if (i > 7) return;
Wire.beginTransmission(TCAADDR);
Wire.write(1 << i);
Wire.endTransmission();
}
//--------------------------------------------------
// SETUP SETUO SETUP // SETUP SETUP SETUP //
//-------------------------------------------------
void setup(void) {
Wire.begin();
Serial.begin(9600);
Serial.println("\nTCA9548A Scanner ready!"); //Multiplexer
while (!Serial)
delay(10); // will pause Zero, Leonardo, etc until serial console opens
Serial.println("Adafruit MCP4728 Ready!"); //DAC Converter
// Try to initialize!
tcaselect(1);
if (!mcp.begin()) {
Serial.println("Failed to find MCP4728 chip");
while (1) {
delay(10);
}}
Serial.println("Adafruit SI1145 Ready");
tcaselect(7);
if (! uv.begin()) {
Serial.println("Didn't find Si1145");
while (1);
}
Serial.println("Let`s go :) !");
mcp.setChannelValue(MCP4728_CHANNEL_A, 4095); // 5V
mcp.setChannelValue(MCP4728_CHANNEL_B, 2048); // 2,5V
mcp.setChannelValue(MCP4728_CHANNEL_C, 1024); // 1,25V
mcp.setChannelValue(MCP4728_CHANNEL_D, 0); // 0 V
}
void loop() {
/////////////////Sensor Adafruit SI1145 UV ////////////////////////
tcaselect(7);
Serial.println("===================");
Serial.print("Vis: "); Serial.println(uv.readVisible());
Serial.print("IR: "); Serial.println(uv.readIR());
float UVindex = uv.readUV();
// the index is multiplied by 100 so to get the
// integer index, divide by 100!
UVindex /= 100.0;
Serial.print("UV: "); Serial.println(UVindex);
delay(1000);
Serial.println(B_Volt);
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

