High-Speed Serial Transfer


hey guys,

i'm having trouble sending serial data @ fast speed (5000 samples per second) through bluetooth serial connection , having reproduced correctly @ receiving end.

for setup, have pair of rn-42 modules (https://www.sparkfun.com/products/12577) interfacing pair of teensy 3.1 microcontrollers (https://www.pjrc.com/teensy/teensy31.html). microcontrollers communicating bluetooth modules @ 230400 baud rate.

basically, want send low quality audio mic transmitter receiver. i'm using interrupts @ transmitter end have audio sampled @ 5000 hz.

now, when send sine wave through transmitter, on receiver a square-waveish version of sine wave, along bunch of other random jumps when analogwrite() signal.

teensy has true 12-bit analog output, expected near perfect reproduction of sine wave if feed analogread values correctly receiver. thoughts on causing receiver receive poor signal? code transmitting , receiving included below.

code: [select]

//transmitter code
int led = 13; //power led
int sample_rate_hz = 5000; //sampling rate
uint16_t val; //variable microphone input
const int audio_input_pin = 14; //the signal feed pin 14
const int analog_read_resolution = 12; //12 bit resolution
const int analog_read_averaging = 12;
const int cts_pin = 17;
intervaltimer samplingtimer; //set interval timer, lets specify sampling rate

void setup()
{
  //pinmode(led, output);
  pinmode(cts_pin, input);
// digitalwrite(led, high); //turn on led o teensy
  serial.begin(115200);
  serial1.begin(230400); //begin serial communications bluetooth , usb if necessary
  analogreadresolution(analog_read_resolution);
  analogreadaveraging(analog_read_averaging); //set analog read resolution , averaging

  delay(2000);

  samplingbegin(); //begin reading audio immediately

}

void loop() //do nothing, interrupt timers handle data acquisition , sending
{
 
}

void samplingbegin() //set sampling rate, call samplingcallback function every 1000000/sampling rate microseconds.
{
  samplingtimer.begin(samplingcallback, 1000000/sample_rate_hz);
}

void samplingcallback() //continously read in analog input (noise if no input)
{
  if(digitalread(cts_pin) == low) //if bluetooth's internal buffer not overwhelmed.
{
  val = analogread(audio_input_pin);
  serial1.print("<"); //send entire integer, marker start , end recognized receiver.
  serial1.print(val);
  serial1.print(">");
  }
}


code: [select]

//receiver code
int led = 13;
char input;


void setup()
{
  pinmode(led, output);
  digitalwrite(led, high);
  serial.begin(115200);
  serial1.begin(230400); //open bluetooth comm
  analogwriteresolution(12);
  delay(3000);


}

void loop()
{
if(serial1.available())
  {
    while(serial1.finduntil("<", ">")) //find <, store values int until > met.
    {
      int val = serial1.parseint(); //create int characters between < , >
      analogwrite(a14, val);
    }
  }

}


time little math.  230400 / 10 / 5000 = 4.608 bytes per sample.  assuming perfect communications (no retries) have 4.608 bytes per sample available.

code: [select]
 serial1.print("<");
 serial1.print(val);
 serial1.print(">");


assuming input has balanced histogram on 0 1023 range, on average 4.916 bytes per sample needed.

you trying push data through pipe.  you need more efficient encoding (fewer bytes per sample) or bigger pipe (higher baud rate).


Arduino Forum > Using Arduino > Programming Questions > High-Speed Serial Transfer


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support