Arduino fast data transfer over bluetooth or Wifi

Hello All,

I am in a situation where I am reading 3 analog values from Atmega 328 ranging from 2khz sinusoidal till 8khz, the problem is in data transferring, I tried using RN41 with a delay in Arduino code of (250us). the receiving end is Lanview which receives the data and reconstruct the waveforms (not completely). but if I go lower than 100us like 50 us delay then Bluetooth doesn't work well and the connection breaks again and again.
I can only use wireless communication.
Is there any alternate where I can use different Bluetooth with a higher transfer rate or should I switch to ESP8266?

any suggestion?

any suggestion?

Fix your sending code or your receiving code, or both. Since you haven't posted either one, don't expect us to help you.

PaulS:
Fix your sending code or your receiving code, or both. Since you haven't posted either one, don't expect us to help you.

Well Thanks for your response, it was a general question.

let me add more specifics to the question.

saadabd:
Well Thanks for your response, it was a general question.

I think you can see, now, that there isn't a general answer.

Please post your program(s) in your next Reply and also post an example of the data that needs to be sent.

...R

int An[6]={0,0,0,0,0,0};
const int Re[6]={A0,A1,A2,A3,A4,A5};
int out[6]={0,0,0,0,0,0};
int Mag[3]={0,0,0};

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(115200);
}

void loop() {
// read the analog in value:
for (int i=0;i<6;i++)
{
An = analogRead(i);
// out = (An_/1024.0)1000.0; //works for 1 volts_
// out = (An_/1024.0)150.0; //works for 5v_
out_=An; //only for labview because sending integerdata over labview

* }*_

Mag[0]= (out[4]-out[5]); //x axis 4khz sinusoidal
Mag[1]= (out[2]-out[3]); //y axis 6khz
Mag[2]= (out[0]-out[1]); //z-axis 8khz
S_print();
delayMicroseconds(100);
}
void S_print()
{
* Serial.print("#");*
* for (int i=0;i<3;i++)*
* {*
Serial.write(Mag_>>8);Serial.write(Mag*);
}
}*_

Attached is Labview Vi.

arduino_analog_magxyz.zip (24.1 KB)

It's all the fault of the little guy with the dark glasses :slight_smile:

When posting code please use the code button </>
codeButton.png

so your code 
looks like this

and is easy to copy to a text editor See How to use the Forum

Also please use the AutoFormat tool to indent your code for easier reading.

..R

There is something seriously wrong with this line of code

Serial.write(Mag>>;Serial.write(Mag);

What is it intended to do?

If you just want to send the values in the array Mag why not do it like this

for (byte n = 0; n < 3; n++) // I prefer n because it is easier to read
{
    Serial.print(Mag[n]);
    Serial.print(',');  // comma delimiter 
}
Serial.println();

…R

Its a copy paste error, the correct line is

void S_print()
{
   Serial.print("#");
  for (int i=0;i<3;i++)
  {
    Serial.write(Mag>>8);Serial.write(Mag);
     }
}

Since i can transfer 8 bit data at a time, so i m dividing 16 bit HEX data into two 8 bit data to transfer via bluetooth through serial.

The program works fine when i increase the delay from 100us to 1000us, but then it will dostort my output waveform on the labview
please refer to my main question on the top of this thread.

I believe, even with the correct code you are not sending the data you think you are. I think it should be

Serial.write(Mag[i]>>8);Serial.write(Mag[i]]);

You can use Serial.write() to send a multi-byte value. RTFM

I think you could do Serial.write(Mag, sizeof(Mag));

...R

Robin2:
I believe, even with the correct code you are not sending the data you think you are. I think it should be

Serial.write(Mag[i]>>8);Serial.write(Mag[i]]);

You can use Serial.write() to send a multi-byte value. RTFM

I think you could do Serial.write(Mag, sizeof(Mag));

...R

My apologies, I shared the Arduino code which I wrote to test one data.
for sure it is

Serial.write(Mag[i]>>8);Serial.write(Mag[i]);

I have verified the data received on Labview the only issue is the speed of data transferring over Bluetooth.

saadabd:
I have verified the data received on Labview the only issue is the speed of data transferring over Bluetooth.

Then please post the program that does not have any errors and tell us how fast it does send data and how much faster you want it to work.

...R

I am reading input from magnetoresistive sensors and sending their difference to LabVIEW for further evaluation.
The Complete Arduino code is here.

int An[6]={0,0,0,0,0,0};
const int Re[6]={A0,A1,A2,A3,A4,A5};
int out[6]={0,0,0,0,0,0};
int Mag[3]={0,0,0};

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(115200);
}

void loop() {
  // read the analog in value:
  for (int i=0;i<6;i++)
  {
  An[i] = analogRead(i);
 // out[i] = (An[i]/1024.0)*1000.0; //works for 1 volts
 //  out[i] = (An[i]/1024.0)*150.0; //works for 5v
 out[i]=An[i]; //only for labview because sending integerdata over labview
  }
   
Mag[0]= (out[4]-out[5]);  //x axis
Mag[1]= (out[2]-out[3]);  //y axis
Mag[2]= (out[0]-out[1]);  //z-axis

S_print();

 delayMicroseconds(100); // this delay is an issue, 
}

void S_print()
{
   Serial.print("#");  //this is for labview to recognise new data is comming
  for (int i=0;i<3;i++)
  {
    Serial.write(Mag[i]>>8);Serial.write(Mag[i]);
     }
}

arduino_analog_magxyz.zip (24.1 KB)

saadabd:
The Complete Arduino code is here.

Thank you for posting the program. But you have not answered my questions in Reply #11 and there is not much point looking at the code without those answers - I won't know what to look for.

I don't plan to open a strange ZIP file - what is in it?

...R

The program is working as fast as i want it to work.
As i mentioned in my first thread that all i need to know is how fast can RN41 bluetooth transfer since, if arduino code runs with a delay of 1000us then the blluetooth keeps connected with the host. but this is not my requirement. i wanted to reduce arduino delay to 100us and at this delay BLUETOOTH RN41 is disconnecting again and again from the host…

The Zip file is LabView Vi. since the forum is not allowing me to attach .vi format see attached picture

Okay, I think I now understand the problem.

As far as I can see you want to send 6 bytes every 100 microsecs. If my maths is correct that amounts to 60,000 bytes per second. At 10 bits per byte (including start and stop bits) that would require a baud rate of at least 600,000. The baud rate in your program is only 115,200. The current baud rate can support about 11,000 bytes per second.

I have no idea whether your Bluetooth device is capable of working at a higher baud rate - you will need to check its datasheet. I know that an Uno can work happily at 500,000 baud and probably at 1,000,000 baud. But it may not be able to work at intermediate speeds. Again, read the Atmega 328 datasheet.

...R

Thanks.