Skip to content

Instantly share code, notes, and snippets.

@soundanalogous
Last active April 2, 2020 18:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soundanalogous/3c21496ce3f1a1af2235 to your computer and use it in GitHub Desktop.
Save soundanalogous/3c21496ce3f1a1af2235 to your computer and use it in GitHub Desktop.
Firmata Serial protocol device emulator
/*
* Emulate a simple serial device in order to test the Firmata Serial protocol.
* Connect the rxPin to the TX pin of the configured port of the board running StandardFirmata
* Connect the txPin to the RX pin of the configured port of the board running StandardFirmata
*
* Use Serial to read and write to the board running StandardFirmata
* Use SoftwareSerial to write data to a console to test SERIAL_WRITE
*/
#include <SoftwareSerial.h>
int count = 0;
byte rxPin = 10;
byte txPin = 11;
int baud = 9600;
SoftwareSerial mySerial(rxPin, txPin);
void setup()
{
mySerial.begin(baud);
Serial.begin(57600);
while (!Serial) {
;
}
}
void loop()
{
// Test READ_CONTINUOUSLY mode
// write data from the emulated Serial device to the board running StandardFirmata
Serial.write(count++);
if (count > 255) count = 0;
delay(200);
// Test SERIAL_WRITE
// read data received from the board running StandardFirmata
while (Serial.available()) {
// could alternatively blink LEDs or something here if a console serial
// cable is not available.
mySerial.write(Serial.read());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment