Go Down

Topic: Help needed with HC-05 (Read 432 times) previous topic - next topic

ash_bougui

I have successfully managed to write down something that get to read values from two potentiometers, but I'am still facing problems with the slave part. Can't figure out the problem.
Any Help please.
Code: [Select]
//                 == MASTER CODE ==
int potValuePins[] = { A0, A1 };

void setup() {
  Serial.begin(9600); // Default communication rate of the Bluetooth module
  for (auto pin : potValuePins) {
    pinMode(pin, INPUT);
  }
}
void loop() {
  for (auto pin : potValuePins) {
    Serial.write(pin); // Send the pin number
    Serial.write(analogRead(pin)); // Send the pin value with a trailing newline as a delimiter
    int value=analogRead(pin);
    Serial.print(" Pin is: ");
    Serial.print(pin);
    Serial.print("\t");
    Serial.print("Value is: ");
    Serial.println(value);
   
  }
}




Code: [Select]
//                 == SLAVE CODE ==
#include <Servo.h>
 
Servo myServo1;
Servo myServo2;
void setup() {
  Serial.begin(9600);
  myServo1.attach(9);
  myServo2.attach(10);
}
void loop() {

  if (Serial.available()) {
    char input[3];
    Serial.readBytes(input, 2);
    int pin = input[0];
    int angle = input[1];
    Serial.print("the pin:");
    Serial.print(pin);
    Serial.print("\t");
    Serial.print("the angle:");
    Serial.println( angle);
    //Serial.readStringUntil('\n'+ input[1]);
   
    switch (pin) {
      case A0:
        myServo1.write(angle);
        break;
      case A1:
        myServo2.write(angle);
        break;
      default:
        Serial.println("Unknown value");
        break;
    }
  }
}

vinceherman

Help us out.
Describe the problem.

What does the sketch do that you do not expect it to do?
What does the sketch not do that you do expect it to do?

ash_bougui

The values sent by the Master are not received the same by the slave. (that is the first problem)
Which is going to take us to the second problem, naturally, that the servos are not following the move of the pots.
I cannot understand which part is wrong in my code.

slipstick

Using hardware serial on pins 0, 1 for both the HC-05 and debug prints to the Serial monitor doesn't seem like a very good idea.

Steve


Go Up