Skip to content

Instantly share code, notes, and snippets.

@xrl
Last active August 29, 2015 13:58
Show Gist options
  • Save xrl/9946387 to your computer and use it in GitHub Desktop.
Save xrl/9946387 to your computer and use it in GitHub Desktop.
A proof of concept for connecting a raspberry pi and arduino by UART

RasPI to Arduino (Nano 3.3v)

  1. get the raspberry pi to stop waiting for UART login (https://github.com/lurch/rpi-serial-console)
  2. flash the following test program to the Arduino (done from OSX Arduino IDE)
  3. wire up arduino and pi (http://neophob.com/2013/01/serial-communication-between-raspberry-pi-and-arduino/)
  4. talk to the arduino over minicom sudo minicom -b 115200 -o -D /dev/ttyAMA0
#define BUFFER_LEN (255)
#define BAUD (115200)

char buffer[BUFFER_LEN];
char readlen;
boolean bufferReady = false;

void setup(){
  Serial.begin(BAUD);
}

void serialEvent(){
  readlen = Serial.readBytesUntil('\n',buffer,BUFFER_LEN);
  buffer[readlen] = '\0';
  bufferReady = true;
}

void loop(){
  if(bufferReady){
    Serial.println(buffer);
    bufferReady = false;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment