[Code Snippet] Talking to Arduino via OTG cable

75 views
Skip to first unread message

Dave Smart

unread,
Oct 7, 2014, 5:02:09 AM10/7/14
to androi...@googlegroups.com
Hi All,

I got this Arduino demo working with AndroidScript's USB Espruino example and a Galaxy S3, with the following sketch running on an Arduino Uno board.   

These are the current default serial properties used by AndroidScript:

baud = 115200, databits = 8, stopbits = 1,  parity = none



// Sample Arduino sketch for use with usb-serial-for-android.
// Prints an ever-increasing counter, and writes back anything
// it receives.

static int counter = 0;
void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.print("Tick #");
  Serial.print(counter++, DEC);
  Serial.print("\n");

  if (Serial.peek() != -1) {
    Serial.print("Read: ");
    do {
      Serial.print((char) Serial.read());
    } while (Serial.peek() != -1);
    Serial.print("\n");
  }
  delay(1000);
}

Reply all
Reply to author
Forward
0 new messages