hello,
I have a question about of how to send multiple data of integer with the hc-05 modul.
I'm using 2 x HC-05 Modules (1x slave and 1x master). They are connected and set up with the baudrate of 115200. The communication between both modules are working well.
Also I have a gyro (MPU-6050) and I need to send 3 values of integers which are ranged between 0-180.
So my question is how I could send those 3 data simultaneously from my HC-05 (Master) to my HC-05 (Slave) because I need to control 3x servomotors.
That means:
ServoA = gyro x-axis (--> values between 0-180)
ServoB = gyro y-axis (--> values between 0-180)
ServoC = gyro z-axis (--> values between 0-180)
I'm using the serial1.write() function because my HC-05 master module is connected with the arduino micro.
The HC-05 slave module is connected to the arduino mega 2560.
So I just need to know how I could send those 3 data as an array with the serial1.write() function.
If I send only a single integer as in the code below it is working. But I don't know how I could send all 3 integer simulatenously.
Here is a snippet of the slave and master code:
Master:
The whole code is just withdraw from the author jrowberg for the MPU-6050 Module. That's why I just post a snippet of the values I am sending from Master to Slave.
int servo1 = map(ypr[0] * 180/M_PI, -180, 180, 0, 180);
int servo2 = map(ypr[1] * 180/M_PI, -90, 90, 0, 180);
int servo3 = map(ypr[2] * 180/M_PI, -90, 90, 0, 180);
Serial1.write(servo1);
Slave:
#include <SoftwareSerial.h>
#include <Servo.h>
int readdata;
Servo myservo1;
Servo myservo2;
Servo myservo3;
void setup()
{
myservo1.attach(3);
myservo2.attach(5);
myservo3.attach(9);
Serial.begin(115200); // HC-05 default speed in AT command more
}
void loop() {
if (Serial.available())
{
int readdata = Serial.read();
myservo1.write(readdata);
}
}
If anyone have an idea of how I could send my data simulatenously I would be very thankful if you could make an example code.