Day 17: Chapter 7 (1 of 4)

(I just spent the weekend in spokane rebuilding my web/mail servers I am obviously going to have to backfill here. )

Physical Agreement.

ama2tplinkIn one of my projects I have a 3.3v router and a 5v arduino. I use a 74ahc125 buffer to translate between the two.

Serial Out From the MicroController (143)

void setup() { 
 //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
      // because all of the others reboot when the serial port is opened.
  }
  Serial.println("Hello World");
} 

void loop() { 
// nothing to do here.
}

Serial Input to a Microcontroller

void setup() { 
 //Initialize serial and wait for port to open:
  Serial.begin(9600); 
} 

void loop() { 
  if (Serial.available()){
    Serial.write(Serial.read());
  }
}
.

Serial Freeze and Blocking Functions (P#153)

The Arduino/Wiring buffers serial input and reads are non blocking so to get the same behavior we can count the millis since the last read and output a ‘.’ every 10.

long int lastRead;
void setup() { 
  Serial.begin(9600); 
  readTimeout=millis();
} 

void loop() { 
  if (Serial.available()){
    Serial.write(Serial.read());
    readTimeout=millis();
  } else {
    if((millis()-readTimeout)>10) {
       Serial.write('.');
       readTimeout=millis();
    }
  }
}
Advertisements

About feurig

My name is Donald Davis, I make Suspect Devices. (www.suspectdevices.com)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: