Skip to content

Instantly share code, notes, and snippets.

@treeherder
Last active December 21, 2015 19:59
Show Gist options
  • Save treeherder/6358375 to your computer and use it in GitHub Desktop.
Save treeherder/6358375 to your computer and use it in GitHub Desktop.
serial buffer device for arduino
#include <SoftwareSerial.h>
SoftwareSerial serial_device(7, 8);
unsigned char buff[512]; /* buffer */
int index=0;
void setup()
{
serial_device.begin(19200); /* baud rate */
Serial.begin(19200); /* works better when they match*/
}
void loop()
{
if (serial_device.available()) /* wait for data */
{
while(serial_device.available())
{
buff[index++]=serial_device.read(); /* writing data into buff*/
if(index == 64)break;
}
Serial.write(buff,index); /*tx*/
clr_buff_arr(); /*zero buffer array and index*/
index = 0;
}
if (Serial.available()) /*wait*/
serial_device.write(Serial.read()); /* rx*/
}
void clr_buff_arr()
{
for (int i=0; i<index;i++)
{ buff[i]=NULL;} /* clear each index */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment