Getting Artisan to talk to Arduino - Page 5

Discuss roast levels and profiles for espresso, equipment for roasting coffee.
User avatar
EddyQ
Posts: 1051
Joined: 8 years ago

#41: Post by EddyQ »

FilePhil wrote:I have wrote a small example how to send data to Artisan using the TC4 protocol.
It's straight forward and easy to extend.

https://github.com/FilePhil/TC4-Emulator
Folks,

I'm super green with coding Arduino's. But I started with FilePhil's code and couldn't get Artisan to talk to it using TC4. I made a simple modification that got it working very reliably and not needing power resets. Seems the code needed the serial port initialized and baud rate defined. So I stripped out all but what is necessary from FilePhil's code and attached my sketch below.
//TC4 Emulator.ino

bool unit_F = true; //true = °F - false = °C

double tempA=200;//ET Temp 
double tempB=300;//BT Temp 


//Parsing Serial Commands
void handleSerialCommand(){   

    if (Serial.available()>0){
        String msg = Serial.readStringUntil('\n');

        if (msg.indexOf("CHAN;")== 0){  //Ignore this Setting
            Serial.print("#OK");
        }
        else if (msg.indexOf("UNITS;")== 0){

            if (msg.substring(6,7)=="F"){   //Change to Farenheit
                unit_F = true;
                Serial.println("#OK Farenheit");
            }
            else if (msg.substring(6,7)=="C"){  //Change to Celsius
                unit_F = false;
                Serial.println("#OK Celsius");
            }

        }
        else if (msg.indexOf("READ")==0){   //Send Temps
           Command_READ();

        }
          
     } 

}
//Send Data
void Command_READ(){    
    Serial.print("0.00,");
    Serial.print(tempA,4);
    Serial.print(",");
    Serial.print(tempB,4);
    Serial.println(",0.00,0.00");
}


void setup() {
// initialize USB serial
    Serial.begin(115200);
    while (! Serial); // Wait untilSerial is ready
}


void loop() {
    handleSerialCommand();
}
This code simply sends two temperatures (defined in code) to Artisan. For reference, I am using a Arduino Uno R3 that I got in the mail this week from Arduino.
LMWDP #671

Post Reply