#42523
Can someone help me. I am trying to send mapped analog values from 0 to 100 from a master bluno beetle to a linked/paired slave bluno beetle. I want the slave to take the value and multiply it by a value and print the result to the serial monitor. It doesn't seem to work though.

I feel like its an issue with the bluno beetles using the serial communication and me trying to use the serial monitor at the same time but maybe not. Right now I get the value from the master beetle and it shows up on slave serial monitor but it never prints the values value to the screen or anything else.

Thank you,
Code: Select all
//Master Code


int old_value;  //Prior reading value from analogRead

void setup()
{
  Serial.begin(115200);
  Serial.print("Simple Master Beetle Program--BLUETOOTH");
}

void loop()
{

  //Current code that takes and maps analog value from potentiometer and sends to slave device.
  int mappedValue = map(analogRead(A0), 0, 1023, 0, 100);
  if (abs(mappedValue - old_value) > 1) {
    old_value = mappedValue;  // save the changed value
    Serial.println(mappedValue);
    //Serial.write("");
    //Serial.write(mappedValue);
  }
delay(1000);
}

Code: Select all
//Slave Code

int values = 10;
char com;

void setup()
{
  Serial.begin(115200);
  Serial.println("Simple Slave Beetle Program----BLUETOOTH");
}

void loop()
{

  while (Serial.available() > 0) {
    com = Serial.read();
    Serial.println("Yes");
    delay(10);
    Serial.println(com);
    values = values * com;
    Serial.print("Values is: ");
    Serial.println(values);
  }

}

#42532
Hi, thank you for your support and contact.
We have checked the code you posted, here are some suggestions.
1. The Serial.write() method is required to transfer data over Bluetooth.
2. Serial.print () will also transmit data via Bluetooth during a Bluetooth connection, which is slightly disruptive to the experiment, but not a problem.
Here the code for your reference
Code: Select all
//Master Code
int old_value; 
void setup()
{
  Serial.begin(115200);
  Serial.print("Simple Master Beetle Program--BLUETOOTH");
}

void loop()
{
  int mappedValue = map(analogRead(A0), 0, 1023, 0, 100);
  if (abs(mappedValue - old_value) > 1) {
    old_value = mappedValue;  // save the changed value
    Serial.write(mappedValue);
  }
delay(1000);
}
Code: Select all
//Slave Code
int values = 10;
char com;
void setup()
{
  Serial.begin(115200);
  Serial.println("Simple Slave Beetle Program----BLUETOOTH");
}

void loop()
{
  while (Serial.available() > 0) {
    com = Serial.read();
    Serial.println("Yes");
    delay(10);
    Serial.println(com);
    values = values * int(com);
    Serial.print("Values is: ");
    Serial.println(values);
  }
}