Sending various values via HC-05 from one arduino to another

HI! I will describe my project briefly:

I have a strip of leds (WS2813) and I'm making a multifunctional RGB lamp. This led stip is attached to an arduino. It's just supposed to receive data and light the stip.

I want to control it using some potentiometers (to change colors, brightness, number of leds to light etc), and some buttons (to change modes, to change the temperature of the white and so on).
This is supposed to be controlled by the other arduino with the HC-05 module in master mode.

The issue is that apparently I can send only one char type variable while I have at least 5 integers to send.
Is there any solution for this kind of problems? Any library that I can use or different module that can send more data at once?

With all that unintelligible code, it is hard to see what the problem might be. I doubt Bluetooth is the problem, but you might

  1. prove the code is kosher by connecting the Arduinos together WITH wires.

  2. then try to do the same thing but replace the wires with Blueteeth. No change of code is required. IF you use hardware serial, no libraries required in either instance.

You problem may be just a matter of serial input, but that is really just a guess.

First problem is that I can send only char type variables, no others like int or signed short. At least can I transform my int into a char type ==> Send ==> Decode from char to int again?

If so, how to do it?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

…R

Skiermaxhtc:
First problem is that I can send only char type variables, no others like int or signed short. At least can I transform my int into a char type ==> Send ==> Decode from char to int again?

If so, how to do it?

To convert an int into chars:

int integer = 4234;
char msb = (integer >> 8) & 0xFF;
char lsb = integer & 0xFF;

To convert back:

int integer = (msb << 8) + lsb;

AND, to reliably transfer serial data, you should use a dedicated and tested library. See this one, for example.

Here’s some example code from the library:

TX Arduino:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  myTransfer.txBuff[0] = 'h';
  myTransfer.txBuff[1] = 'i';
  myTransfer.txBuff[2] = '\n';
  
  myTransfer.sendData(3);
  delay(100);
}

RX Arduino:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  if(myTransfer.available())
  {
    Serial.println("New Data");
    for(byte i = 0; i < myTransfer.bytesRead; i++)
      Serial.write(myTransfer.rxBuff[i]);
    Serial.println();
  }
  else
  {
    Serial.print("ERROR: ");
    Serial.println(myTransfer.status);
  }
}