0

I am attempting to send data from device to host using the Gazelle protocol, however, when reading a time varying signal in on MATLAB the values continuously change elements in the array.

Here is the Simblee/Rfduino host code:

#include <SimbleeGZLL.h>
device_t role = HOST;
char array[5];
void setup() {
  Serial.begin(9600);
  SimbleeGZLL.begin(role);
  timer_one(1); // 1 ms timer
}

void loop() {
  Serial.flush();
  printf(EMG);
}


void SimbleeGZLL_onReceive(device_t device, int rssi, char *data, int len)
{
  if (len > 0) {
    digitalWrite(2,HIGH);
    array[0] = data[0];
    array[1] = data[1];
    array[2] = data[2];
    array[3] = data[3];
    array[4] = '\0'; 
    } else SimbleeGZLL.sendToDevice(device, 'A');
} 

And the device code:

include

device_t role = DEVICE1;

volatile int state;
char array[4];

void setup() {
  SimbleeGZLL.begin(role);
  Serial.begin(9600);
  timer_one(1); 
}

void loop() {

      array[0] = analogRead(2);
      array[1] = analogRead(3);
      array[2] = analogRead(4);
      array[3] = analogRead(5);   
      SimbleeGZLL.sendToHost(EMG,4);   
}

Could someone please provide some assistance to identify where the issue may lie? Thank you!

pjay
  • 11
  • 2

1 Answers1

0
  1. Matlab is not super reliable with serial communication. I actually had a similar issue with a serial device where the input values would be out of order. Are you signaling when to start and stop printing? What does your matlab code look like?

  2. I would set up a ring buffer on the host and the device to deal with the asycn time issues.

  3. You are going to get timing issues with the current method. What kind of frequency are you going for? The analogRead is super slow, and double multiple in a row seems to make things even slower. Could you try to set up an ADC interrupt?

  4. Where is your timer code?

user3120471
  • 23
  • 2
  • 3
  • 8