Thread subject: Homeroasters - Home Roasting Coffee Community :: TC4 - Coding and tech issues

Posted by JimG on 04/16/2011 11:36 AM
#10

I've got something that's working well here with both the Uno (problem child) and the Duemilanove. Had the added benefit of getting rid of the forced delay to give the remote (Arduino, PICAXE) a chance to spin up.

Most of the time, 5 resets are required for the Duemilanove. This is because opening the serial port always resets the board.

On the Uno, most of the time 1 reset is required, sometimes 2. But it does not get reset when the serial port is opened.

Anxious to see how it behaves on your PICAXE, Brad.

The basics:
Code

// ------------------------------- reset the Arduino, etc.
void resetRemote() {
//    delay( START_DELAY ); // make sure the remote has had time to get started
    println("\nSynchronising with remote:");
    int i = 0;
    while( resetAck == 0 && i < 10 ) {
      comport.write( "RESET\n" );  // issue command to the TC4 to synchronize clocks
      delay( 500 );
      i++;
    }
    print( resetAck ); println( " reset(s) required." );
    if( resetAck != 0 )
      started = true;
}

// ------------------------------- save a frame when mouse is clicked
void mouseClicked() {
  if( !started ) {  // waiting for user to begin logging
    resetRemote();
  }
  else {
    makeJPG = true;  // queue a request to save a frame
  }
}

...... similar code for beginning of keyPressed()

// -------------------------------------------------------------
void serialEvent(Serial comport) { // this is executed each time a line of data is received from the TC4

    // grab a line of ascii text from the logger
    String msg = comport.readStringUntil('\n');

    // exit right away if blank line
    if (msg == null) return; // *****************
    msg = trim(msg);
    if (msg.length() == 0) return; // ****************

    // otherwise, check first to see if it is a comment --------------------------------------------
    if (msg.charAt(0) == '#') { // this line is a comment
      logfile.println(msg); // write it to the log no matter what
      println(msg); // write it to the terminal no matter what     
      String[] rec = split(msg, ",");  // comma separated input list
      if( rec[0].equals( "# Reset" ) ) { // acknowledge, and count, RESET's echoed back from remote
        ++resetAck;    // count them for possible debugging use
      }
        else if( started ) { // skip these roast markers if logging hasn't been started by the user
        if (rec[0].equals("# STRT")) {
          ba_x = T0[0][idx-1];
          ba_y = MAX_TEMP - T0[1][idx-1];
        } else if (rec[0].equals("# FC")) {
... snipped


Changes committed to the repository here:
https://tc4-shiel...c/pBourbon

Jim