Serial communication with MCP4725 DAC's with Arduino/Max 6

Hugo Collet's icon

Hello.

I am trying to use an Arduino board to monitor the voltage of two MCP 4725 DAC's with different values.

I input the value through a Max patcher (Max 6, from https://docs.cycling74.com/max5/tutorials/max-tut/communicationschapter02.html) and transmit it to the Arduino board.Then it translates the 0-255 we enter in Max into DAC values for the setvoltage(value) method (0-4095).

My first issue is that i can't assign a value in my loop. We could simply do (0 to 255) * 16,06 = (0 to 4095) obviously but i had to do that huge ugly switch case.

The second one is that i can't find a way to store 2 different values from Max.

Here is my code if it helps :

void loop(void) {

unsigned long currentMillis = millis();

if(Serial.available()) // check to see if there's serial data in the buffer
{ serialvalue = Serial.read(); // read a byte of serial data
} if(currentMillis - previousMillis > interval) { switch(serialvalue){ case 255: dac1.setVoltage(4095,false); dac2.setVoltage(4095,false); break; ... etc.

Our final idea is to be able to monitor 4 DAC's with Max at different voltages. I've beeen trying to go throng Serial.read() and Serial.readBytes() functions without success.

Thanks for your help.

Hugo Collet's icon

My current goal is to be able to send a 4095 to the DAC through Arduino, i am only able to send 0 to 255 value at the moment.