Page 4 of 5
#define SEL 2 // When the SEL pin is held low, the data will
be
// routed to the PC via the USBserial bridge.
// That port is also the port used for program
ming
// by the Arduino IDE. When in bootloading mod
e, a
// pulldown resistor on the SmartBasic cause
s it
// to remain in programming mode.
#define ARDUINO_IDE LOW // Constants to make our routing ch
ange
#define AUX_TERMINAL HIGH // more obvious. When the SEL pin
is
// LOW, data is routed to the
// programming port.
void setup()
{
Serial.begin(115200); // Set up the hardware serial port.
pinMode(SEL, OUTPUT); // Make the select line an outpu
t...
digitalWrite(SEL, ARDUINO_IDE); // ...and connect the board
to
// the Arduino IDE's terminal.
}
void loop()
{
// The loop just says "Hello" to the two terminals, over and
// over, forever. Note the use of the "flush()" function. I
f
// omitted, the Arduino will reroute the serial data befor
e
// the transmission has been completed; flush() causes the
// Arduino to block until the serial data output buffer is
// empty. Failure to use flush() will result in data being
// sent to the wrong device, or to multiplexer changes duri
ng
// transmission which may cause framing errors or data
// corruption. *Always put in a flush() before you change
// destination devices or disable the output.*
Serial.flush();
digitalWrite(SEL, ARDUINO_IDE);
Serial.println("Hello, Arduino IDE!");
// Swap to the nonArduino terminal and say hello.
Serial.flush();
digitalWrite(SEL, AUX_TERMINAL);
Serial.println("Hello, auxilliary terminal!");
Serial.flush();
delay(500); // This is a ratelimiter only. The temptation t
o use
// delay() instead of flush() is strong, but fi
ght it.
// If you use delay, you will *certainly* make
a change
// to the code which makes the original delay t
ime too
// short for the new serial data stream, result
Need help?
Do you have a question about the FTDI SmartBasic and is the answer not in the manual?
Questions and answers