3

I am trying to control an omni wheel robot which has 4 motors using 2 joysticks, plus there are some actuation switches which I want to control too. I am using arduino mega and a pair of bluetooth wireless module(HC-05).

This bluetooth modules works on serial communication. How should I program arduino to send both the analog values provided by the joystick and the input from the switch continuously?

Ben
  • 5,855
  • 3
  • 28
  • 48

1 Answers1

1

The simplest solution is throwing all values into a comma seperated string:

use the the standard strcat():

 char data[256];
 chat temp[16];
 data[0]=0;
 temp[0]=0;

 itoa(analogRead(A1),temp,10); 
 strcat(data,temp);
 strcat(data,",");
 itoa(analogRead(A2),temp,10);
 strcat(data,temp);
 strcat(data,",");
 itoa(analogRead(A3),temp,10);
 strcat(data,temp);
 strcat(data,",");
 itoa(analogRead(A4),temp,10);
 strcat(data,temp);
 strcat(data,",");
 itoa(digitalRead(5),temp,10);
 strcat(data,temp);
 strcat(data,",");
 itoa(digitalRead(6),temp,10);
 strcat(data,temp);
TobiasK
  • 1,657
  • 1
  • 9
  • 17
  • A good idea would be to add some starting character to show where data frame begins. So, assuming you would start your frame with '#' you would get: #VAL1,VAL2,VAL3... – mactro Mar 16 '15 at 14:13
  • In addition to a start character, you should also consider sending a check-sum or crc. This will help ensure the integrity of the data. – Ben Apr 14 '15 at 16:52