Changed examples that use SerialUSB to use Serial, also fixed bug associated with use of the reserved word 'index' as a variable name

This commit is contained in:
Roger Clark 2014-12-30 11:36:32 +11:00
parent d172043e49
commit a6bf8a4bd7
24 changed files with 311 additions and 316 deletions

View File

@ -38,6 +38,7 @@ void setup() {
pinMode(analogInPin, INPUT_ANALOG); pinMode(analogInPin, INPUT_ANALOG);
// Configure LED pin // Configure LED pin
pinMode(pwmOutPin, PWM); pinMode(pwmOutPin, PWM);
Serial.begin(115200); // Ignored by Maple. But needed by boards using Hardware serial via a USB to Serial Adaptor
} }
void loop() { void loop() {
@ -49,8 +50,8 @@ void loop() {
pwmWrite(pwmOutPin, outputValue); pwmWrite(pwmOutPin, outputValue);
// print the results to the serial monitor: // print the results to the serial monitor:
SerialUSB.print("sensor = " ); Serial.print("sensor = " );
SerialUSB.print(sensorValue); Serial.print(sensorValue);
SerialUSB.print("\t output = "); Serial.print("\t output = ");
SerialUSB.println(outputValue); Serial.println(outputValue);
} }

View File

@ -22,6 +22,7 @@ const int analogInputPin = 15;
void setup() { void setup() {
// Declare analogInputPin as INPUT_ANALOG: // Declare analogInputPin as INPUT_ANALOG:
pinMode(analogInputPin, INPUT_ANALOG); pinMode(analogInputPin, INPUT_ANALOG);
Serial.begin(115200); // Ignored by Maple. But needed by boards using Hardware serial via a USB to Serial Adaptor
} }
void loop() { void loop() {
@ -29,5 +30,5 @@ void loop() {
int analogValue = analogRead(analogInputPin); int analogValue = analogRead(analogInputPin);
// print the result: // print the result:
SerialUSB.println(analogValue); Serial.println(analogValue);
} }

View File

@ -24,7 +24,7 @@
const int numReadings = 10; const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading int index1 = 0; // the index1 of the current reading
int total = 0; // the running total int total = 0; // the running total
int average = 0; // the average int average = 0; // the average
@ -33,7 +33,8 @@ int inputPin = 15; // analog input pin
void setup() { void setup() {
// Declare the input pin as INPUT_ANALOG: // Declare the input pin as INPUT_ANALOG:
pinMode(inputPin, INPUT_ANALOG); pinMode(inputPin, INPUT_ANALOG);
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Initialize all the readings to 0: // Initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++) { for (int thisReading = 0; thisReading < numReadings; thisReading++) {
readings[thisReading] = 0; readings[thisReading] = 0;
@ -42,22 +43,22 @@ void setup() {
void loop() { void loop() {
// Subtract the last reading: // Subtract the last reading:
total = total - readings[index]; total = total - readings[index1];
// Read from the sensor: // Read from the sensor:
readings[index] = analogRead(inputPin); readings[index1] = analogRead(inputPin);
// Add the reading to the total: // Add the reading to the total:
total = total + readings[index]; total = total + readings[index1];
// Advance to the next position in the array: // Advance to the next position in the array:
index = index + 1; index1 = index1 + 1;
// If we're at the end of the array... // If we're at the end of the array...
if (index >= numReadings) { if (index1 >= numReadings) {
// ...wrap around to the beginning: // ...wrap around to the beginning:
index = 0; index1 = 0;
} }
// Calculate the average: // Calculate the average:
average = total / numReadings; average = total / numReadings;
// Send it to the computer (as ASCII digits) // Send it to the computer (as ASCII digits)
SerialUSB.println(average, DEC); Serial.println(average, DEC);
} }

View File

@ -1,7 +1,7 @@
/* /*
ASCII table ASCII table
Connect to the Maple SerialUSB using the Serial Monitor, then press Connect to the Maple Serial using the Serial Monitor, then press
any key and hit enter. any key and hit enter.
Prints out byte values in all possible formats: Prints out byte values in all possible formats:
@ -25,13 +25,16 @@
by Bryan Newbold by Bryan Newbold
*/ */
void setup() { void setup()
{
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Wait for the user to press a key // Wait for the user to press a key
while (!SerialUSB.available()) while (!Serial.available())
continue; continue;
// Prints title with ending line break // Prints title with ending line break
SerialUSB.println("ASCII Table ~ Character Map"); Serial.println("ASCII Table ~ Character Map");
} }
// First visible ASCII character: '!' is number 33: // First visible ASCII character: '!' is number 33:
@ -44,29 +47,29 @@ void loop() {
// Prints value unaltered, i.e. the raw binary version of the // Prints value unaltered, i.e. the raw binary version of the
// byte. The serial monitor interprets all bytes as // byte. The serial monitor interprets all bytes as
// ASCII, so 33, the first number, will show up as '!' // ASCII, so 33, the first number, will show up as '!'
SerialUSB.print(thisByte, BYTE); Serial.print(thisByte, BYTE);
SerialUSB.print(", dec: "); Serial.print(", dec: ");
// Prints value as string as an ASCII-encoded decimal (base 10). // Prints value as string as an ASCII-encoded decimal (base 10).
// Decimal is the default format for SerialUSB.print() and // Decimal is the default format for Serial.print() and
// SerialUSB.println(), so no modifier is needed: // Serial.println(), so no modifier is needed:
SerialUSB.print(thisByte); Serial.print(thisByte);
// But you can declare the modifier for decimal if you want to. // But you can declare the modifier for decimal if you want to.
// This also works if you uncomment it: // This also works if you uncomment it:
// SerialUSB.print(thisByte, DEC); // Serial.print(thisByte, DEC);
SerialUSB.print(", hex: "); Serial.print(", hex: ");
// Prints value as string in hexadecimal (base 16): // Prints value as string in hexadecimal (base 16):
SerialUSB.print(thisByte, HEX); Serial.print(thisByte, HEX);
SerialUSB.print(", oct: "); Serial.print(", oct: ");
// Prints value as string in octal (base 8); // Prints value as string in octal (base 8);
SerialUSB.print(thisByte, OCT); Serial.print(thisByte, OCT);
SerialUSB.print(", bin: "); Serial.print(", bin: ");
// Prints value as string in binary (base 2); also prints ending // Prints value as string in binary (base 2); also prints ending
// line break: // line break:
SerialUSB.println(thisByte, BIN); Serial.println(thisByte, BIN);
// If printed last visible character '~' or 126, stop: // If printed last visible character '~' or 126, stop:
if (thisByte == 126) { // You could also use if (thisByte == '~') { if (thisByte == 126) { // You could also use if (thisByte == '~') {

View File

@ -24,6 +24,7 @@
int ledPin = 9; int ledPin = 9;
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Declare ledPin as an OUTPUT: // Declare ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
} }
@ -32,11 +33,11 @@ void loop() {
int brightness; int brightness;
// Check if data has been sent from the computer: // Check if data has been sent from the computer:
if (SerialUSB.available()) { if (Serial.available()) {
// Read the most recent byte (which will be from 0 to 255), then // Read the most recent byte (which will be from 0 to 255), then
// convert it to be between 0 and 65,535, which are the minimum // convert it to be between 0 and 65,535, which are the minimum
// and maximum values usable for PWM: // and maximum values usable for PWM:
brightness = map(SerialUSB.read(), 0, 255, 0, 65535); brightness = map(Serial.read(), 0, 255, 0, 65535);
// Set the brightness of the LED: // Set the brightness of the LED:
pwmWrite(ledPin, brightness); pwmWrite(ledPin, brightness);
} }

View File

@ -29,13 +29,14 @@
const int analogInPin = 15; const int analogInPin = 15;
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Declare pin 15 as an analog input: // Declare pin 15 as an analog input:
pinMode(analogInPin, INPUT_ANALOG); pinMode(analogInPin, INPUT_ANALOG);
} }
void loop() { void loop() {
// send the value of analog input 15: // send the value of analog input 15:
SerialUSB.println(analogRead(analogInPin)); Serial.println(analogRead(analogInPin));
} }
/* Processing code for this example /* Processing code for this example

View File

@ -26,15 +26,16 @@
int incomingByte; // a variable to read incoming serial data into int incomingByte; // a variable to read incoming serial data into
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Initialize the built-in LED pin as an output: // Initialize the built-in LED pin as an output:
pinMode(BOARD_LED_PIN, OUTPUT); pinMode(BOARD_LED_PIN, OUTPUT);
} }
void loop() { void loop() {
// See if there's incoming serial data: // See if there's incoming serial data:
if (SerialUSB.available() > 0) { if (Serial.available() > 0) {
// Read the oldest byte in the serial buffer: // Read the oldest byte in the serial buffer:
incomingByte = SerialUSB.read(); incomingByte = Serial.read();
// If it's a capital H (ASCII 72), turn on the LED: // If it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') { if (incomingByte == 'H') {
digitalWrite(BOARD_LED_PIN, HIGH); digitalWrite(BOARD_LED_PIN, HIGH);

View File

@ -29,6 +29,7 @@ int thirdSensor = 0; // digital sensor value
int inByte = 0; // incoming serial byte int inByte = 0; // incoming serial byte
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
pinMode(0, INPUT_ANALOG); // First (analog) sensor is on pin 0 pinMode(0, INPUT_ANALOG); // First (analog) sensor is on pin 0
pinMode(1, INPUT_ANALOG); // Second (analog) sensor is on pin 1 pinMode(1, INPUT_ANALOG); // Second (analog) sensor is on pin 1
pinMode(2, INPUT); // Third (digital) sensor is on pin 2 pinMode(2, INPUT); // Third (digital) sensor is on pin 2
@ -37,9 +38,9 @@ void setup() {
void loop() { void loop() {
// if we get a valid byte, read analog ins: // if we get a valid byte, read analog ins:
if (SerialUSB.available() > 0) { if (Serial.available() > 0) {
// get incoming byte: // get incoming byte:
inByte = SerialUSB.read(); inByte = Serial.read();
// read first analog input, map it into the range 0-255: // read first analog input, map it into the range 0-255:
firstSensor = map(analogRead(0), 0, 4095, 0, 255); firstSensor = map(analogRead(0), 0, 4095, 0, 255);
// delay 10 ms to let the ADC value change: // delay 10 ms to let the ADC value change:
@ -49,15 +50,15 @@ void loop() {
// read switch, map it to 0 or 255 // read switch, map it to 0 or 255
thirdSensor = map(digitalRead(2), 0, 1, 0, 255); thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values: // send sensor values:
SerialUSB.print(firstSensor, BYTE); Serial.print(firstSensor, BYTE);
SerialUSB.print(secondSensor, BYTE); Serial.print(secondSensor, BYTE);
SerialUSB.print(thirdSensor, BYTE); Serial.print(thirdSensor, BYTE);
} }
} }
void establishContact() { void establishContact() {
while (SerialUSB.available() <= 0) { while (Serial.available() <= 0) {
SerialUSB.print('A', BYTE); // send a capital A Serial.print('A', BYTE); // send a capital A
delay(300); delay(300);
} }
} }

View File

@ -30,6 +30,7 @@ int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte int inByte = 0; // incoming serial byte
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
pinMode(0, INPUT_ANALOG); // First (analog) sensor is on pin 0 pinMode(0, INPUT_ANALOG); // First (analog) sensor is on pin 0
pinMode(1, INPUT_ANALOG); // Second (analog) sensor is on pin 1 pinMode(1, INPUT_ANALOG); // Second (analog) sensor is on pin 1
pinMode(2, INPUT); // digital sensor is on digital pin 2 pinMode(2, INPUT); // digital sensor is on digital pin 2
@ -38,9 +39,9 @@ void setup() {
void loop() { void loop() {
// if we get a valid byte, read analog ins: // if we get a valid byte, read analog ins:
if (SerialUSB.available() > 0) { if (Serial.available() > 0) {
// get incoming byte: // get incoming byte:
inByte = SerialUSB.read(); inByte = Serial.read();
// read first analog input, map it into the range 0-255: // read first analog input, map it into the range 0-255:
firstSensor = map(analogRead(0), 0, 4095, 0, 255); firstSensor = map(analogRead(0), 0, 4095, 0, 255);
// delay 10 ms to let the ADC value change: // delay 10 ms to let the ADC value change:
@ -50,17 +51,17 @@ void loop() {
// read switch, map it to 0 or 255 // read switch, map it to 0 or 255
thirdSensor = map(digitalRead(2), 0, 1, 0, 255); thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values: // send sensor values:
SerialUSB.print(firstSensor, DEC); Serial.print(firstSensor, DEC);
SerialUSB.print(","); Serial.print(",");
SerialUSB.print(secondSensor, DEC); Serial.print(secondSensor, DEC);
SerialUSB.print(","); Serial.print(",");
SerialUSB.println(thirdSensor, DEC); Serial.println(thirdSensor, DEC);
} }
} }
void establishContact() { void establishContact() {
while (SerialUSB.available() <= 0) { while (Serial.available() <= 0) {
SerialUSB.println("0,0,0"); // send an initial string Serial.println("0,0,0"); // send an initial string
delay(300); delay(300);
} }
} }

View File

@ -1,10 +1,10 @@
/* /*
Multiple serial test Multiple serial test
Receives from Serial1, sends to SerialUSB. Receives from Serial1, sends to Serial.
The circuit: The circuit:
* Maple connected over SerialUSB * Maple connected over Serial
* Serial device (e.g. an Xbee radio, another Maple) * Serial device (e.g. an Xbee radio, another Maple)
created 30 Dec. 2008 created 30 Dec. 2008
@ -18,13 +18,14 @@ int inByte; // Byte read from Serial1
void setup() { void setup() {
// Initialize Serial1 // Initialize Serial1
Serial1.begin(9600); Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
Serial1.begin(115200);
} }
void loop() { void loop() {
// Read from Serial1, send over USB: // Read from Serial1, send over USB on Maple (or uses hardware serial 1 and hardware serial 2 on non-maple boards:
if (Serial1.available()) { if (Serial1.available()) {
inByte = Serial1.read(); inByte = Serial1.read();
SerialUSB.print(inByte, BYTE); Serial.print(inByte, BYTE);
} }
} }

View File

@ -25,17 +25,18 @@ const int greenPin = 16; // sensor to control green color
const int bluePin = 17; // sensor to control blue color const int bluePin = 17; // sensor to control blue color
void setup() { void setup() {
pinMode(redPin, INPUT_ANALOG); Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
pinMode(greenPin, INPUT_ANALOG); pinMode(redPin, INPUT_ANALOG);
pinMode(bluePin, INPUT_ANALOG); pinMode(greenPin, INPUT_ANALOG);
pinMode(bluePin, INPUT_ANALOG);
} }
void loop() { void loop() {
SerialUSB.print(analogRead(redPin)); Serial.print(analogRead(redPin));
SerialUSB.print(","); Serial.print(",");
SerialUSB.print(analogRead(greenPin)); Serial.print(analogRead(greenPin));
SerialUSB.print(","); Serial.print(",");
SerialUSB.println(analogRead(bluePin)); Serial.println(analogRead(bluePin));
} }
/* Processing code for this example /* Processing code for this example

View File

@ -28,6 +28,7 @@ const int threshold = 400; // A random threshold level that's in
// the range of the analog input // the range of the analog input
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Initialize the built-in LED pin as an output: // Initialize the built-in LED pin as an output:
pinMode(BOARD_LED_PIN, OUTPUT); pinMode(BOARD_LED_PIN, OUTPUT);
@ -48,5 +49,5 @@ void loop() {
} }
// Print the analog value: // Print the analog value:
SerialUSB.println(analogValue, DEC); Serial.println(analogValue, DEC);
} }

View File

@ -27,6 +27,7 @@ const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 600; // sensor maximum, discovered through experiment const int sensorMax = 600; // sensor maximum, discovered through experiment
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
pinMode(0, INPUT_ANALOG); pinMode(0, INPUT_ANALOG);
} }
@ -39,16 +40,16 @@ void loop() {
// Do something different depending on the range value: // Do something different depending on the range value:
switch (range) { switch (range) {
case 0: // your hand is on the sensor case 0: // your hand is on the sensor
SerialUSB.println("dark"); Serial.println("dark");
break; break;
case 1: // your hand is close to the sensor case 1: // your hand is close to the sensor
SerialUSB.println("dim"); Serial.println("dim");
break; break;
case 2: // your hand is a few inches from the sensor case 2: // your hand is a few inches from the sensor
SerialUSB.println("medium"); Serial.println("medium");
break; break;
case 3: // your hand is nowhere near the sensor case 3: // your hand is nowhere near the sensor
SerialUSB.println("bright"); Serial.println("bright");
break; break;
} }
} }

View File

@ -22,6 +22,7 @@
*/ */
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Initialize the LED pins: // Initialize the LED pins:
for (int thisPin = 2; thisPin <= 6; thisPin++) { for (int thisPin = 2; thisPin <= 6; thisPin++) {
pinMode(thisPin, OUTPUT); pinMode(thisPin, OUTPUT);
@ -30,8 +31,8 @@ void setup() {
void loop() { void loop() {
// Read the sensor: // Read the sensor:
if (SerialUSB.available() > 0) { if (Serial.available() > 0) {
int inByte = SerialUSB.read(); int inByte = Serial.read();
// Do something different depending on the character received. // Do something different depending on the character received.
// The switch statement expects single number values for each // The switch statement expects single number values for each
// case; in this example, though, you're using single quotes // case; in this example, though, you're using single quotes

View File

@ -26,6 +26,7 @@ int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button int lastButtonState = 0; // previous state of the button
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// initialize the button pin as a input: // initialize the button pin as a input:
pinMode(BOARD_BUTTON_PIN, INPUT); pinMode(BOARD_BUTTON_PIN, INPUT);
// initialize the LED as an output: // initialize the LED as an output:
@ -43,14 +44,14 @@ void loop() {
// if the current state is HIGH, then the button went from // if the current state is HIGH, then the button went from
// off to on: // off to on:
buttonPushCounter++; buttonPushCounter++;
SerialUSB.println("on"); Serial.println("on");
SerialUSB.print("number of button pushes: "); Serial.print("number of button pushes: ");
SerialUSB.println(buttonPushCounter, DEC); Serial.println(buttonPushCounter, DEC);
} }
else { else {
// if the current state is LOW, then the button went from // if the current state is LOW, then the button went from
// on to off: // on to off:
SerialUSB.println("off"); Serial.println("off");
} }
// save the current state as the last state, for next time // save the current state as the last state, for next time

View File

@ -9,7 +9,7 @@
surely isn't the best way to do VGA video with a Maple, but it demonstrates surely isn't the best way to do VGA video with a Maple, but it demonstrates
the Timer functionality and is a cool hack so here it is. the Timer functionality and is a cool hack so here it is.
SerialUSB is disabled to get rid of most interrupts (which mess with timing); Serial is disabled to get rid of most interrupts (which mess with timing);
the SysTick is probably the source of the remaining flickers. This means that the SysTick is probably the source of the remaining flickers. This means that
you have to use perpetual bootloader or the reset button to flash new you have to use perpetual bootloader or the reset button to flash new
programs. programs.
@ -88,7 +88,7 @@ uint8 logo[18][16] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}, }; {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,}, };
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Setup our pins // Setup our pins
pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
pinMode(VGA_R, OUTPUT); pinMode(VGA_R, OUTPUT);
@ -104,7 +104,7 @@ void setup() {
// This gets rid of the majority of the interrupt artifacts; // This gets rid of the majority of the interrupt artifacts;
// a SysTick.end() is required as well // a SysTick.end() is required as well
SerialUSB.end(); Serial.end();
// Configure // Configure

View File

@ -2,7 +2,7 @@
Interactive Test Session for LeafLabs Maple Interactive Test Session for LeafLabs Maple
Useful for testing Maple features and troubleshooting. Useful for testing Maple features and troubleshooting.
Communicates over SerialUSB. Communicates over Serial.
This code is released into the public domain. This code is released into the public domain.
*/ */
@ -21,6 +21,7 @@ const char* dummy_data = ("qwertyuiopasdfghjklzxcvbnmmmmmm,./1234567890-="
// -- setup() and loop() ------------------------------------------------------ // -- setup() and loop() ------------------------------------------------------
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Set up the LED to blink // Set up the LED to blink
pinMode(BOARD_LED_PIN, OUTPUT); pinMode(BOARD_LED_PIN, OUTPUT);
@ -29,20 +30,20 @@ void setup() {
Serial2.begin(BAUD); Serial2.begin(BAUD);
Serial3.begin(BAUD); Serial3.begin(BAUD);
// Send a message out over SerialUSB interface // Send a message out over Serial interface
SerialUSB.println(" "); Serial.println(" ");
SerialUSB.println(" __ __ _ _"); Serial.println(" __ __ _ _");
SerialUSB.println(" | \\/ | __ _ _ __ | | ___| |"); Serial.println(" | \\/ | __ _ _ __ | | ___| |");
SerialUSB.println(" | |\\/| |/ _` | '_ \\| |/ _ \\ |"); Serial.println(" | |\\/| |/ _` | '_ \\| |/ _ \\ |");
SerialUSB.println(" | | | | (_| | |_) | | __/_|"); Serial.println(" | | | | (_| | |_) | | __/_|");
SerialUSB.println(" |_| |_|\\__,_| .__/|_|\\___(_)"); Serial.println(" |_| |_|\\__,_| .__/|_|\\___(_)");
SerialUSB.println(" |_|"); Serial.println(" |_|");
SerialUSB.println(" by leaflabs"); Serial.println(" by leaflabs");
SerialUSB.println(""); Serial.println("");
SerialUSB.println(""); Serial.println("");
SerialUSB.println("Maple interactive test program (type '?' for help)"); Serial.println("Maple interactive test program (type '?' for help)");
SerialUSB.println("----------------------------------------------------------"); Serial.println("----------------------------------------------------------");
SerialUSB.print("> "); Serial.print("> ");
} }
@ -50,16 +51,16 @@ void loop () {
toggleLED(); toggleLED();
delay(100); delay(100);
while (SerialUSB.available()) { while (Serial.available()) {
uint8 input = SerialUSB.read(); uint8 input = Serial.read();
SerialUSB.println(input); Serial.println(input);
switch(input) { switch(input) {
case '\r': case '\r':
break; break;
case ' ': case ' ':
SerialUSB.println("spacebar, nice!"); Serial.println("spacebar, nice!");
break; break;
case '?': case '?':
@ -68,7 +69,7 @@ void loop () {
break; break;
case 'u': case 'u':
SerialUSB.println("Hello World!"); Serial.println("Hello World!");
break; break;
case 'w': case 'w':
@ -82,11 +83,11 @@ void loop () {
break; break;
case '.': case '.':
while (!SerialUSB.available()) { while (!Serial.available()) {
Serial1.print("."); Serial1.print(".");
Serial2.print("."); Serial2.print(".");
Serial3.print("."); Serial3.print(".");
SerialUSB.print("."); Serial.print(".");
} }
break; break;
@ -103,7 +104,7 @@ void loop () {
break; break;
case 'W': case 'W':
while (!SerialUSB.available()) { while (!Serial.available()) {
Serial1.print(dummy_data); Serial1.print(dummy_data);
Serial2.print(dummy_data); Serial2.print(dummy_data);
Serial3.print(dummy_data); Serial3.print(dummy_data);
@ -111,9 +112,9 @@ void loop () {
break; break;
case 'U': case 'U':
SerialUSB.println("Dumping data to USB. Press any key."); Serial.println("Dumping data to USB. Press any key.");
while (!SerialUSB.available()) { while (!Serial.available()) {
SerialUSB.print(dummy_data); Serial.print(dummy_data);
} }
break; break;
@ -126,10 +127,10 @@ void loop () {
break; break;
case 'f': case 'f':
SerialUSB.println("Wiggling D4 as fast as possible in bursts. " Serial.println("Wiggling D4 as fast as possible in bursts. "
"Press any key."); "Press any key.");
pinMode(4, OUTPUT); pinMode(4, OUTPUT);
while (!SerialUSB.available()) { while (!Serial.available()) {
fast_gpio(4); fast_gpio(4);
delay(1); delay(1);
} }
@ -140,18 +141,18 @@ void loop () {
break; break;
case '_': case '_':
SerialUSB.println("Delaying for 5 seconds..."); Serial.println("Delaying for 5 seconds...");
delay(5000); delay(5000);
break; break;
// Be sure to update cmd_print_help() if you implement these: // Be sure to update cmd_print_help() if you implement these:
case 't': // TODO case 't': // TODO
SerialUSB.println("Unimplemented."); Serial.println("Unimplemented.");
break; break;
case 'T': // TODO case 'T': // TODO
SerialUSB.println("Unimplemented."); Serial.println("Unimplemented.");
break; break;
case 's': case 's':
@ -159,30 +160,30 @@ void loop () {
break; break;
case 'd': case 'd':
SerialUSB.println("Pulling down D4, D22. Press any key."); Serial.println("Pulling down D4, D22. Press any key.");
pinMode(22, INPUT_PULLDOWN); pinMode(22, INPUT_PULLDOWN);
pinMode(4, INPUT_PULLDOWN); pinMode(4, INPUT_PULLDOWN);
while (!SerialUSB.available()) { while (!Serial.available()) {
continue; continue;
} }
SerialUSB.println("Pulling up D4, D22. Press any key."); Serial.println("Pulling up D4, D22. Press any key.");
pinMode(22, INPUT_PULLUP); pinMode(22, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP); pinMode(4, INPUT_PULLUP);
while (!SerialUSB.available()) { while (!Serial.available()) {
continue; continue;
} }
SerialUSB.read(); Serial.read();
pinMode(4, OUTPUT); pinMode(4, OUTPUT);
break; break;
// Be sure to update cmd_print_help() if you implement these: // Be sure to update cmd_print_help() if you implement these:
case 'i': // TODO case 'i': // TODO
SerialUSB.println("Unimplemented."); Serial.println("Unimplemented.");
break; break;
case 'I': // TODO case 'I': // TODO
SerialUSB.println("Unimplemented."); Serial.println("Unimplemented.");
break; break;
case 'r': case 'r':
@ -202,51 +203,51 @@ void loop () {
break; break;
default: // ------------------------------- default: // -------------------------------
SerialUSB.print("Unexpected: "); Serial.print("Unexpected: ");
SerialUSB.print(input); Serial.print(input);
SerialUSB.println(", press h for help."); Serial.println(", press h for help.");
} }
SerialUSB.print("> "); Serial.print("> ");
} }
} }
// -- Commands ---------------------------------------------------------------- // -- Commands ----------------------------------------------------------------
void cmd_print_help(void) { void cmd_print_help(void) {
SerialUSB.println(""); Serial.println("");
SerialUSB.println("Command Listing"); Serial.println("Command Listing");
SerialUSB.println("\t?: print this menu"); Serial.println("\t?: print this menu");
SerialUSB.println("\th: print this menu"); Serial.println("\th: print this menu");
SerialUSB.println("\tw: print Hello World on all 3 USARTS"); Serial.println("\tw: print Hello World on all 3 USARTS");
SerialUSB.println("\tn: measure noise and do statistics"); Serial.println("\tn: measure noise and do statistics");
SerialUSB.println("\tN: measure noise and do statistics with background stuff"); Serial.println("\tN: measure noise and do statistics with background stuff");
SerialUSB.println("\ta: show realtime ADC info"); Serial.println("\ta: show realtime ADC info");
SerialUSB.println("\t.: echo '.' until new input"); Serial.println("\t.: echo '.' until new input");
SerialUSB.println("\tu: print Hello World on USB"); Serial.println("\tu: print Hello World on USB");
SerialUSB.println("\t_: do as little as possible for a couple seconds (delay)"); Serial.println("\t_: do as little as possible for a couple seconds (delay)");
SerialUSB.println("\tp: test all PWM channels sequentially"); Serial.println("\tp: test all PWM channels sequentially");
SerialUSB.println("\tW: dump data as fast as possible on all 3 USARTS"); Serial.println("\tW: dump data as fast as possible on all 3 USARTS");
SerialUSB.println("\tU: dump data as fast as possible on USB"); Serial.println("\tU: dump data as fast as possible on USB");
SerialUSB.println("\tg: toggle GPIOs sequentially"); Serial.println("\tg: toggle GPIOs sequentially");
SerialUSB.println("\tG: toggle GPIOs at the same time"); Serial.println("\tG: toggle GPIOs at the same time");
SerialUSB.println("\tf: toggle pin 4 as fast as possible in bursts"); Serial.println("\tf: toggle pin 4 as fast as possible in bursts");
SerialUSB.println("\tr: monitor and print GPIO status changes"); Serial.println("\tr: monitor and print GPIO status changes");
SerialUSB.println("\ts: output a sweeping servo PWM on all PWM channels"); Serial.println("\ts: output a sweeping servo PWM on all PWM channels");
SerialUSB.println("\tm: output data on USART1 and USART3 with various rates"); Serial.println("\tm: output data on USART1 and USART3 with various rates");
SerialUSB.println("\tb: print information about the board."); Serial.println("\tb: print information about the board.");
SerialUSB.println("\t+: test shield mode (for quality assurance testing)"); Serial.println("\t+: test shield mode (for quality assurance testing)");
SerialUSB.println("Unimplemented:"); Serial.println("Unimplemented:");
SerialUSB.println("\te: do everything all at once until new input"); Serial.println("\te: do everything all at once until new input");
SerialUSB.println("\tt: output a 1khz squarewave on all GPIOs"); Serial.println("\tt: output a 1khz squarewave on all GPIOs");
SerialUSB.println("\tT: output a 1hz squarewave on all GPIOs"); Serial.println("\tT: output a 1hz squarewave on all GPIOs");
SerialUSB.println("\ti: print out a bunch of info about system state"); Serial.println("\ti: print out a bunch of info about system state");
SerialUSB.println("\tI: print out status of all headers"); Serial.println("\tI: print out status of all headers");
} }
void cmd_adc_stats(void) { void cmd_adc_stats(void) {
SerialUSB.println("Taking ADC noise stats."); Serial.println("Taking ADC noise stats.");
digitalWrite(BOARD_LED_PIN, 0); digitalWrite(BOARD_LED_PIN, 0);
for (uint32 i = 0; i < BOARD_NR_ADC_PINS; i++) { for (uint32 i = 0; i < BOARD_NR_ADC_PINS; i++) {
delay(5); delay(5);
@ -255,7 +256,7 @@ void cmd_adc_stats(void) {
} }
void cmd_stressful_adc_stats(void) { void cmd_stressful_adc_stats(void) {
SerialUSB.println("Taking ADC noise stats under duress."); Serial.println("Taking ADC noise stats under duress.");
for (uint32 i = 0; i < BOARD_NR_ADC_PINS; i++) { for (uint32 i = 0; i < BOARD_NR_ADC_PINS; i++) {
for (uint32 j = 0; j < BOARD_NR_PWM_PINS; j++) { for (uint32 j = 0; j < BOARD_NR_PWM_PINS; j++) {
@ -285,34 +286,34 @@ void cmd_everything(void) { // TODO
// print to usb // print to usb
// toggle gpios // toggle gpios
// enable pwm // enable pwm
SerialUSB.println("Unimplemented."); Serial.println("Unimplemented.");
} }
void cmd_serial1_serial3(void) { void cmd_serial1_serial3(void) {
HardwareSerial *serial_1_and_3[] = {&Serial1, &Serial3}; HardwareSerial *serial_1_and_3[] = {&Serial1, &Serial3};
SerialUSB.println("Testing 57600 baud on USART1 and USART3. " Serial.println("Testing 57600 baud on USART1 and USART3. "
"Press any key to stop."); "Press any key to stop.");
usart_baud_test(serial_1_and_3, 2, 57600); usart_baud_test(serial_1_and_3, 2, 57600);
SerialUSB.read(); Serial.read();
SerialUSB.println("Testing 115200 baud on USART1 and USART3. " Serial.println("Testing 115200 baud on USART1 and USART3. "
"Press any key to stop."); "Press any key to stop.");
usart_baud_test(serial_1_and_3, 2, 115200); usart_baud_test(serial_1_and_3, 2, 115200);
SerialUSB.read(); Serial.read();
SerialUSB.println("Testing 9600 baud on USART1 and USART3. " Serial.println("Testing 9600 baud on USART1 and USART3. "
"Press any key to stop."); "Press any key to stop.");
usart_baud_test(serial_1_and_3, 2, 9600); usart_baud_test(serial_1_and_3, 2, 9600);
SerialUSB.read(); Serial.read();
SerialUSB.println("Resetting USART1 and USART3..."); Serial.println("Resetting USART1 and USART3...");
Serial1.begin(BAUD); Serial1.begin(BAUD);
Serial3.begin(BAUD); Serial3.begin(BAUD);
} }
void cmd_gpio_monitoring(void) { void cmd_gpio_monitoring(void) {
SerialUSB.println("Monitoring pin state changes. Press any key to stop."); Serial.println("Monitoring pin state changes. Press any key to stop.");
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) { for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i)) if (boardUsesPin(i))
@ -321,19 +322,19 @@ void cmd_gpio_monitoring(void) {
gpio_state[i] = (uint8)digitalRead(i); gpio_state[i] = (uint8)digitalRead(i);
} }
while (!SerialUSB.available()) { while (!Serial.available()) {
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) { for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i)) if (boardUsesPin(i))
continue; continue;
uint8 current_state = (uint8)digitalRead(i); uint8 current_state = (uint8)digitalRead(i);
if (current_state != gpio_state[i]) { if (current_state != gpio_state[i]) {
SerialUSB.print("State change on pin "); Serial.print("State change on pin ");
SerialUSB.print(i, DEC); Serial.print(i, DEC);
if (current_state) { if (current_state) {
SerialUSB.println(":\tHIGH"); Serial.println(":\tHIGH");
} else { } else {
SerialUSB.println(":\tLOW"); Serial.println(":\tLOW");
} }
gpio_state[i] = current_state; gpio_state[i] = current_state;
} }
@ -348,44 +349,44 @@ void cmd_gpio_monitoring(void) {
} }
void cmd_sequential_adc_reads(void) { void cmd_sequential_adc_reads(void) {
SerialUSB.print("Sequentially reading most ADC ports."); Serial.print("Sequentially reading most ADC ports.");
SerialUSB.println("Press any key for next port, or ESC to stop."); Serial.println("Press any key for next port, or ESC to stop.");
for (uint32 i = 0; i < BOARD_NR_ADC_PINS; i++) { for (uint32 i = 0; i < BOARD_NR_ADC_PINS; i++) {
if (boardUsesPin(i)) if (boardUsesPin(i))
continue; continue;
SerialUSB.print("Reading pin "); Serial.print("Reading pin ");
SerialUSB.print(boardADCPins[i], DEC); Serial.print(boardADCPins[i], DEC);
SerialUSB.println("..."); Serial.println("...");
pinMode(boardADCPins[i], INPUT_ANALOG); pinMode(boardADCPins[i], INPUT_ANALOG);
while (!SerialUSB.available()) { while (!Serial.available()) {
int sample = analogRead(boardADCPins[i]); int sample = analogRead(boardADCPins[i]);
SerialUSB.print(boardADCPins[i], DEC); Serial.print(boardADCPins[i], DEC);
SerialUSB.print("\t"); Serial.print("\t");
SerialUSB.print(sample, DEC); Serial.print(sample, DEC);
SerialUSB.print("\t"); Serial.print("\t");
SerialUSB.print("|"); Serial.print("|");
for (int j = 0; j < 4096; j += 100) { for (int j = 0; j < 4096; j += 100) {
if (sample >= j) { if (sample >= j) {
SerialUSB.print("#"); Serial.print("#");
} else { } else {
SerialUSB.print(" "); Serial.print(" ");
} }
} }
SerialUSB.print("| "); Serial.print("| ");
for (int j = 0; j < 12; j++) { for (int j = 0; j < 12; j++) {
if (sample & (1 << (11 - j))) { if (sample & (1 << (11 - j))) {
SerialUSB.print("1"); Serial.print("1");
} else { } else {
SerialUSB.print("0"); Serial.print("0");
} }
} }
SerialUSB.println(""); Serial.println("");
} }
pinMode(boardADCPins[i], OUTPUT); pinMode(boardADCPins[i], OUTPUT);
digitalWrite(boardADCPins[i], 0); digitalWrite(boardADCPins[i], 0);
if (SerialUSB.read() == ESC) if (Serial.read() == ESC)
break; break;
} }
} }
@ -396,11 +397,11 @@ bool test_single_pin_is_high(int high_pin, const char* err_msg) {
if (boardUsesPin(i)) continue; if (boardUsesPin(i)) continue;
if (digitalRead(i) == HIGH && i != high_pin) { if (digitalRead(i) == HIGH && i != high_pin) {
SerialUSB.println(); Serial.println();
SerialUSB.print("\t*** FAILURE! pin "); Serial.print("\t*** FAILURE! pin ");
SerialUSB.print(i, DEC); Serial.print(i, DEC);
SerialUSB.print(' '); Serial.print(' ');
SerialUSB.println(err_msg); Serial.println(err_msg);
ok = false; ok = false;
} }
} }
@ -420,7 +421,7 @@ bool wait_for_low_transition(uint8 pin) {
void cmd_gpio_qa(void) { void cmd_gpio_qa(void) {
bool all_pins_ok = true; bool all_pins_ok = true;
const int not_a_pin = -1; const int not_a_pin = -1;
SerialUSB.println("Doing QA testing for unused GPIO pins."); Serial.println("Doing QA testing for unused GPIO pins.");
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) { for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i)) continue; if (boardUsesPin(i)) continue;
@ -428,25 +429,25 @@ void cmd_gpio_qa(void) {
pinMode(i, INPUT); pinMode(i, INPUT);
} }
SerialUSB.println("Waiting to start."); Serial.println("Waiting to start.");
ASSERT(!boardUsesPin(0)); ASSERT(!boardUsesPin(0));
while (digitalRead(0) == LOW) continue; while (digitalRead(0) == LOW) continue;
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) { for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i)) { if (boardUsesPin(i)) {
SerialUSB.print("Skipping pin "); Serial.print("Skipping pin ");
SerialUSB.println(i, DEC); Serial.println(i, DEC);
continue; continue;
} }
bool pin_ok = true; bool pin_ok = true;
SerialUSB.print("Checking pin "); Serial.print("Checking pin ");
SerialUSB.print(i, DEC); Serial.print(i, DEC);
while (digitalRead(i) == LOW) continue; while (digitalRead(i) == LOW) continue;
pin_ok = pin_ok && test_single_pin_is_high(i, "is also HIGH"); pin_ok = pin_ok && test_single_pin_is_high(i, "is also HIGH");
if (!wait_for_low_transition(i)) { if (!wait_for_low_transition(i)) {
SerialUSB.println("Transition to low timed out; something is " Serial.println("Transition to low timed out; something is "
"very wrong. Aborting test."); "very wrong. Aborting test.");
return; return;
} }
@ -454,16 +455,16 @@ void cmd_gpio_qa(void) {
pin_ok = pin_ok && test_single_pin_is_high(not_a_pin, "is still HIGH"); pin_ok = pin_ok && test_single_pin_is_high(not_a_pin, "is still HIGH");
if (pin_ok) { if (pin_ok) {
SerialUSB.println(": ok"); Serial.println(": ok");
} }
all_pins_ok = all_pins_ok && pin_ok; all_pins_ok = all_pins_ok && pin_ok;
} }
if (all_pins_ok) { if (all_pins_ok) {
SerialUSB.println("Finished; test passes."); Serial.println("Finished; test passes.");
} else { } else {
SerialUSB.println("**** TEST FAILS *****"); Serial.println("**** TEST FAILS *****");
} }
for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) { for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
@ -476,30 +477,30 @@ void cmd_gpio_qa(void) {
} }
void cmd_sequential_gpio_writes(void) { void cmd_sequential_gpio_writes(void) {
SerialUSB.println("Sequentially toggling all unused pins. " Serial.println("Sequentially toggling all unused pins. "
"Press any key for next pin, ESC to stop."); "Press any key for next pin, ESC to stop.");
for (uint32 i = 0; i < BOARD_NR_GPIO_PINS; i++) { for (uint32 i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i)) if (boardUsesPin(i))
continue; continue;
SerialUSB.print("Toggling pin "); Serial.print("Toggling pin ");
SerialUSB.print((int)i, DEC); Serial.print((int)i, DEC);
SerialUSB.println("..."); Serial.println("...");
pinMode(i, OUTPUT); pinMode(i, OUTPUT);
do { do {
togglePin(i); togglePin(i);
} while (!SerialUSB.available()); } while (!Serial.available());
digitalWrite(i, LOW); digitalWrite(i, LOW);
if (SerialUSB.read() == ESC) if (Serial.read() == ESC)
break; break;
} }
} }
void cmd_gpio_toggling(void) { void cmd_gpio_toggling(void) {
SerialUSB.println("Toggling all unused pins simultaneously. " Serial.println("Toggling all unused pins simultaneously. "
"Press any key to stop."); "Press any key to stop.");
for (uint32 i = 0; i < BOARD_NR_GPIO_PINS; i++) { for (uint32 i = 0; i < BOARD_NR_GPIO_PINS; i++) {
@ -508,7 +509,7 @@ void cmd_gpio_toggling(void) {
pinMode(i, OUTPUT); pinMode(i, OUTPUT);
} }
while (!SerialUSB.available()) { while (!Serial.available()) {
for (uint32 i = 0; i < BOARD_NR_GPIO_PINS; i++) { for (uint32 i = 0; i < BOARD_NR_GPIO_PINS; i++) {
if (boardUsesPin(i)) if (boardUsesPin(i))
continue; continue;
@ -524,34 +525,34 @@ void cmd_gpio_toggling(void) {
} }
void cmd_sequential_pwm_test(void) { void cmd_sequential_pwm_test(void) {
SerialUSB.println("Sequentially testing PWM on all unused pins. " Serial.println("Sequentially testing PWM on all unused pins. "
"Press any key for next pin, ESC to stop."); "Press any key for next pin, ESC to stop.");
for (uint32 i = 0; i < BOARD_NR_PWM_PINS; i++) { for (uint32 i = 0; i < BOARD_NR_PWM_PINS; i++) {
if (boardUsesPin(i)) if (boardUsesPin(i))
continue; continue;
SerialUSB.print("PWM out on header D"); Serial.print("PWM out on header D");
SerialUSB.print(boardPWMPins[i], DEC); Serial.print(boardPWMPins[i], DEC);
SerialUSB.println("..."); Serial.println("...");
pinMode(boardPWMPins[i], PWM); pinMode(boardPWMPins[i], PWM);
pwmWrite(boardPWMPins[i], 16000); pwmWrite(boardPWMPins[i], 16000);
while (!SerialUSB.available()) { while (!Serial.available()) {
delay(10); delay(10);
} }
pinMode(boardPWMPins[i], OUTPUT); pinMode(boardPWMPins[i], OUTPUT);
digitalWrite(boardPWMPins[i], 0); digitalWrite(boardPWMPins[i], 0);
if (SerialUSB.read() == ESC) if (Serial.read() == ESC)
break; break;
} }
} }
void cmd_servo_sweep(void) { void cmd_servo_sweep(void) {
SerialUSB.println("Testing all PWM headers with a servo sweep. " Serial.println("Testing all PWM headers with a servo sweep. "
"Press any key to stop."); "Press any key to stop.");
SerialUSB.println(); Serial.println();
disable_usarts(); disable_usarts();
init_all_timers(21); init_all_timers(21);
@ -567,7 +568,7 @@ void cmd_servo_sweep(void) {
// 1.50ms = 4915counts = 90deg // 1.50ms = 4915counts = 90deg
// 1.75ms = 5734counts = 180deg // 1.75ms = 5734counts = 180deg
int rate = 4096; int rate = 4096;
while (!SerialUSB.available()) { while (!Serial.available()) {
rate += 20; rate += 20;
if (rate > 5734) if (rate > 5734)
rate = 4096; rate = 4096;
@ -589,21 +590,21 @@ void cmd_servo_sweep(void) {
} }
void cmd_board_info(void) { // TODO print more information void cmd_board_info(void) { // TODO print more information
SerialUSB.println("Board information"); Serial.println("Board information");
SerialUSB.println("================="); Serial.println("=================");
SerialUSB.print("* Clock speed (cycles/us): "); Serial.print("* Clock speed (cycles/us): ");
SerialUSB.println(CYCLES_PER_MICROSECOND); Serial.println(CYCLES_PER_MICROSECOND);
SerialUSB.print("* BOARD_LED_PIN: "); Serial.print("* BOARD_LED_PIN: ");
SerialUSB.println(BOARD_LED_PIN); Serial.println(BOARD_LED_PIN);
SerialUSB.print("* BOARD_BUTTON_PIN: "); Serial.print("* BOARD_BUTTON_PIN: ");
SerialUSB.println(BOARD_BUTTON_PIN); Serial.println(BOARD_BUTTON_PIN);
SerialUSB.print("* GPIO information (BOARD_NR_GPIO_PINS = "); Serial.print("* GPIO information (BOARD_NR_GPIO_PINS = ");
SerialUSB.print(BOARD_NR_GPIO_PINS); Serial.print(BOARD_NR_GPIO_PINS);
SerialUSB.println("):"); Serial.println("):");
print_board_array("ADC pins", boardADCPins, BOARD_NR_ADC_PINS); print_board_array("ADC pins", boardADCPins, BOARD_NR_ADC_PINS);
print_board_array("PWM pins", boardPWMPins, BOARD_NR_PWM_PINS); print_board_array("PWM pins", boardPWMPins, BOARD_NR_PWM_PINS);
print_board_array("Used pins", boardUsedPins, BOARD_NR_USED_PINS); print_board_array("Used pins", boardUsedPins, BOARD_NR_USED_PINS);
@ -627,14 +628,14 @@ void measure_adc_noise(uint8 pin) {
M2 = M2 + delta * (data[i] - mean); M2 = M2 + delta * (data[i] - mean);
} }
SerialUSB.print("header: D"); Serial.print("header: D");
SerialUSB.print(pin, DEC); Serial.print(pin, DEC);
SerialUSB.print("\tn: "); Serial.print("\tn: ");
SerialUSB.print(100, DEC); Serial.print(100, DEC);
SerialUSB.print("\tmean: "); Serial.print("\tmean: ");
SerialUSB.print(mean); Serial.print(mean);
SerialUSB.print("\tvariance: "); Serial.print("\tvariance: ");
SerialUSB.println(M2 / 99.0); Serial.println(M2 / 99.0);
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
} }
@ -674,7 +675,7 @@ void usart_baud_test(HardwareSerial **serials, int n, unsigned baud) {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
serials[i]->begin(baud); serials[i]->begin(baud);
} }
while (!SerialUSB.available()) { while (!Serial.available()) {
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
serials[i]->println(dummy_data); serials[i]->println(dummy_data);
if (serials[i]->available()) { if (serials[i]->available()) {
@ -711,14 +712,14 @@ void disable_usarts(void) {
} }
void print_board_array(const char* msg, const uint8 arr[], int len) { void print_board_array(const char* msg, const uint8 arr[], int len) {
SerialUSB.print("\t"); Serial.print("\t");
SerialUSB.print(msg); Serial.print(msg);
SerialUSB.print(" ("); Serial.print(" (");
SerialUSB.print(len); Serial.print(len);
SerialUSB.print("): "); Serial.print("): ");
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
SerialUSB.print(arr[i], DEC); Serial.print(arr[i], DEC);
if (i < len - 1) SerialUSB.print(", "); if (i < len - 1) Serial.print(", ");
} }
SerialUSB.println(); Serial.println();
} }

View File

@ -1,8 +1,8 @@
/* /*
SerialUSB Stress Test Serial Stress Test
Connect via Serial2 (header pins D0 and D1 on the Maple) for the back channel; Connect via Serial2 (header pins D0 and D1 on the Maple) for the back channel;
otherwise just connect with SerialUSB and press BUT to cycle through (hold otherwise just connect with Serial and press BUT to cycle through (hold
it for at least a second). it for at least a second).
The output will be pretty cryptic; see inline comments for more info. The output will be pretty cryptic; see inline comments for more info.
@ -28,6 +28,7 @@ uint32 state = 0;
void setup() void setup()
{ {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Set up the LED to blink // Set up the LED to blink
pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
@ -58,82 +59,82 @@ void loop() {
// this pattern makes it easy to see dropped bytes. // this pattern makes it easy to see dropped bytes.
case QUICKPRINT: case QUICKPRINT:
for(int i = 0; i<40; i++) { for(int i = 0; i<40; i++) {
SerialUSB.print('.'); Serial.print('.');
SerialUSB.print('|'); Serial.print('|');
} }
Serial2.println(SerialUSB.pending(),DEC); Serial2.println(Serial.pending(),DEC);
SerialUSB.println(); Serial.println();
break; break;
// Send large/log stuff // Send large/log stuff
case BIGSTUFF: case BIGSTUFF:
SerialUSB.println("01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"); Serial.println("01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
SerialUSB.println((uint32)123456789,DEC); Serial.println((uint32)123456789,DEC);
SerialUSB.println(3.1415926535); Serial.println(3.1415926535);
Serial2.println(SerialUSB.pending(),DEC); Serial2.println(Serial.pending(),DEC);
break; break;
// Try a bunch of different types and formats // Try a bunch of different types and formats
case NUMBERS: case NUMBERS:
SerialUSB.println("Numbers! -----------------------------"); Serial.println("Numbers! -----------------------------");
Serial2.println("Numbers! -----------------------------"); Serial2.println("Numbers! -----------------------------");
SerialUSB.println('1'); Serial.println('1');
Serial2.println('1'); Serial2.println('1');
SerialUSB.println(1,DEC); Serial.println(1,DEC);
Serial2.println(1,DEC); Serial2.println(1,DEC);
SerialUSB.println(-1,DEC); Serial.println(-1,DEC);
Serial2.println(-1,DEC); Serial2.println(-1,DEC);
SerialUSB.println(3.14159265); Serial.println(3.14159265);
Serial2.println(3.14159265); Serial2.println(3.14159265);
SerialUSB.println(3.14159265,9); Serial.println(3.14159265,9);
Serial2.println(3.14159265,9); Serial2.println(3.14159265,9);
SerialUSB.println(123456789,DEC); Serial.println(123456789,DEC);
Serial2.println(123456789,DEC); Serial2.println(123456789,DEC);
SerialUSB.println(-123456789,DEC); Serial.println(-123456789,DEC);
Serial2.println(-123456789,DEC); Serial2.println(-123456789,DEC);
SerialUSB.println(65535,HEX); Serial.println(65535,HEX);
Serial2.println(65535,HEX); Serial2.println(65535,HEX);
SerialUSB.println(65535,OCT); Serial.println(65535,OCT);
Serial2.println(65535,OCT); Serial2.println(65535,OCT);
SerialUSB.println(65535,BIN); Serial.println(65535,BIN);
Serial2.println(65535,BIN); Serial2.println(65535,BIN);
break; break;
// Very basic prints // Very basic prints
case SIMPLE: case SIMPLE:
Serial2.println("Trying write('a')"); Serial2.println("Trying write('a')");
SerialUSB.write('a'); Serial.write('a');
Serial2.println("Trying write(\"b\")"); Serial2.println("Trying write(\"b\")");
SerialUSB.write("b"); Serial.write("b");
Serial2.println("Trying print('c')"); Serial2.println("Trying print('c')");
SerialUSB.print('c'); Serial.print('c');
Serial2.println("Trying print(\"d\")"); Serial2.println("Trying print(\"d\")");
SerialUSB.print("d"); Serial.print("d");
Serial2.println("Trying print(\"efg\")"); Serial2.println("Trying print(\"efg\")");
SerialUSB.print("efg"); Serial.print("efg");
Serial2.println("Trying println(\"hij\\n\\r\")"); Serial2.println("Trying println(\"hij\\n\\r\")");
SerialUSB.print("hij\n\r"); Serial.print("hij\n\r");
SerialUSB.write(' '); Serial.write(' ');
SerialUSB.println(); Serial.println();
Serial2.println("Trying println(123456789,DEC)"); Serial2.println("Trying println(123456789,DEC)");
SerialUSB.println(123456789,DEC); Serial.println(123456789,DEC);
Serial2.println("Trying println(3.141592)"); Serial2.println("Trying println(3.141592)");
SerialUSB.println(3.141592); Serial.println(3.141592);
Serial2.println("Trying println(\"DONE\")"); Serial2.println("Trying println(\"DONE\")");
SerialUSB.println("DONE"); Serial.println("DONE");
break; break;
// Disables the USB peripheral, then brings it back up a // Disables the USB peripheral, then brings it back up a
// few seconds later // few seconds later
case ONOFF: case ONOFF:
Serial2.println("Shutting down..."); Serial2.println("Shutting down...");
SerialUSB.println("Shutting down..."); Serial.println("Shutting down...");
SerialUSB.end(); Serial.end();
Serial2.println("Waiting 4seconds..."); Serial2.println("Waiting 4seconds...");
delay(4000); delay(4000);
Serial2.println("Starting up..."); Serial2.println("Starting up...");
SerialUSB.begin(); Serial.begin();
SerialUSB.println("Hello World!"); Serial.println("Hello World!");
Serial2.println("Waiting 4seconds..."); Serial2.println("Waiting 4seconds...");
delay(4000); delay(4000);
state++; state++;

View File

@ -24,6 +24,7 @@ int count2 = 0;
void setup() void setup()
{ {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Set up the LED to blink // Set up the LED to blink
pinMode(LED_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT);
@ -57,10 +58,10 @@ void setup()
void loop() { void loop() {
// Display the running counts // Display the running counts
SerialUSB.print("Count 1: "); Serial.print("Count 1: ");
SerialUSB.print(count1); Serial.print(count1);
SerialUSB.print("\t\tCount 2: "); Serial.print("\t\tCount 2: ");
SerialUSB.println(count2); Serial.println(count2);
// Run... while BUT is held, pause Count2 // Run... while BUT is held, pause Count2
for(int i = 0; i<1000; i++) { for(int i = 0; i<1000; i++) {

View File

@ -30,6 +30,7 @@ const int threshold = 100; // threshold value to decide when the detected sound
int sensorReading = 0; // variable to store the value read from the sensor pin int sensorReading = 0; // variable to store the value read from the sensor pin
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
// Declare the knockSensor as an analog input: // Declare the knockSensor as an analog input:
pinMode(knockSensor, INPUT_ANALOG); pinMode(knockSensor, INPUT_ANALOG);
// declare the built-in LED pin as an output: // declare the built-in LED pin as an output:
@ -45,7 +46,7 @@ void loop() {
// toggle the built-in LED // toggle the built-in LED
toggleLED(); toggleLED();
// send the string "Knock!" back to the computer, followed by newline // send the string "Knock!" back to the computer, followed by newline
SerialUSB.println("Knock!"); Serial.println("Knock!");
} }
delay(100); // delay to avoid printing too often delay(100); // delay to avoid printing too often
} }

View File

@ -1,10 +1,11 @@
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
pinMode(0, INPUT_ANALOG); pinMode(0, INPUT_ANALOG);
} }
void loop() { void loop() {
int sensorValue = analogRead(0); int sensorValue = analogRead(0);
SerialUSB.println(sensorValue, DEC); Serial.println(sensorValue, DEC);
} }

View File

@ -1,8 +1,9 @@
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
pinMode(2, INPUT); pinMode(2, INPUT);
} }
void loop() { void loop() {
int sensorValue = digitalRead(2); int sensorValue = digitalRead(2);
SerialUSB.println(sensorValue, DEC); Serial.println(sensorValue, DEC);
} }

View File

@ -1,7 +1,8 @@
void setup() { void setup() {
Serial.begin(115200); // Ignored by Maple. But needed by boards using hardware serial via a USB to Serial adaptor
} }
void loop() { void loop() {
SerialUSB.println("Hello World!"); Serial.println("Hello World!");
delay(1000);
} }

View File

@ -1,29 +0,0 @@
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Analog\AnalogInOutSerial\AnalogInOutSerial.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Analog\AnalogInput\AnalogInput.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Analog\AnalogInSerial\AnalogInSerial.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Analog\Calibration\Calibration.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Analog\Fading\Fading.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Analog\Smoothing\Smoothing.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\ASCIITable\ASCIITable.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\Dimmer\Dimmer.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\Graph\Graph.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\MIDI\Midi.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\PhysicalPixel\PhysicalPixel.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\SerialCallResponse\SerialCallResponse.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\SerialCallResponseASCII\SerialCallResponseASCII.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\SerialPassthrough\SerialPassthrough.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Communication\VirtualColorMixer\VirtualColorMixer.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Control\Arrays\Arrays.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Control\ForLoopIteration\ForLoopIteration.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Control\IfStatementConditional\IfStatementConditional.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Control\switchCase\switchCase.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Control\switchCase2\switchCase2.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Control\WhileStatementConditional\WhileStatementConditional.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Digital\Blink\Blink.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Digital\BlinkWithoutDelay\BlinkWithoutDelay.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Digital\Button\Button.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Digital\Debounce\Debounce.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Digital\StateChangeDetection\StateChangeDetection.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Display\barGraph\barGraph.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Display\RowColumnScanning\RowColumnScanning.pde
c:\Users\rclark\Documents\Arduino\hardware\Arduino_STM32\examples\Maple\CrudeVGA\CrudeVGA.pde