3
$\begingroup$

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?

$\endgroup$

1 Answer 1

1
$\begingroup$

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);
$\endgroup$
2
  • $\begingroup$ 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... $\endgroup$
    – mactro
    Commented Mar 16, 2015 at 14:13
  • $\begingroup$ 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. $\endgroup$
    – Ben
    Commented Apr 14, 2015 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.