Hello,
I have a problem with sending integer value. I'm using 3 arduino's and 2 pair of HC-05 BT modules. To the first one (let's call it "Central") I connected LDR sensor and 2 BT modules which connect to 2 other Arduino's: BT1 and BT2 [just to be clear - there is a connections: Central - BT1 and Central - BT2]. Form the central I'm sending the value read by LDR sensor to BT1 and BT2 simultaneously and here everything works fine - both Arduino's receive exactly the value that the LDR sensor read. Right now I want send a specific numerical value depending on the LDR value read from BT1 and BT2 for e.g. if if the LDR value is less than 500, sent the number 100 [I will need it in the future, because I intend to additionally use the Qwiic AK9753 presence sensor]. I searched all over the internet and couldn't find a solution. On the forum I found a person with a similar problem, for which it was proposed to read values as characters (link here : Sending a value between Arduinos using HC-05 Bluetooth modules ) I decided to try this way. But it dosen't help - the "Central" receives nothing. Interestingly, if one of the BT modules is turned off, the "Central" will receive a specific value, but it will not change regardless of the LDR value (for e.g If the first value was '200' it will recive only '200')
Not exactly. As I wrote before Arduino "Central" recive one of the numbers but only, when 1 od BT connection is active. If they are both, I get nothing. When I tried only his code on 2 Arduino's it worked.
Well, I can use 2 SoftwareSerial, because i tested eariler with sending LDR value to both Arduino and it worked. I took a closer look at it and yeah - I cannot transmit and receive data at the same time. So the question is - It is there any alternative solution?
I have done this - once, binding an HC05 and an HC06.
Granted, the process was a pain - but it worked.
(If you don't do everything right, then it's wrong.)
The difference is a tried to connect 2 HC-05 moduels. After a failed attempt I configured both moduels in old way watching this video: HC-05 configuration. This method previously guaranteed the correct reception of the LDR value.
Yes, and that's the "auto-connect" way, which is the root cause of your conundrum.
Using two HC-05 modules - did you make one a 'master' and the other a 'slave' ?
( You can't do BIND, PAIR with two M's (or two S's). )
The youtube guy isn't doing with two pairs (either).
If there are two separate M/S Pair/Bind sets, it seems that there would not be a problem.
Only speculating - "extreme" proximity could be an issue. (I really do not know.)
The pair/bind operation would take care of that, but maybe not.
Maybe there is another way. There is a function called listen() which listens to a specific device.
I wrote a code that receives data from 2 tiles alternately adding a delay. By checking this function alone I was able to receive different single number values simultaneously from 2 Arduinos. But combining this with sending LDR values unfortunately I still only receive data from 1 of them.
#include <SoftwareSerial.h>
SoftwareSerial BT1(3, 2);
char myData[10];
int ValueLDR;
int v1 = 1;
int v0 = 0;
void setup()
{
Serial.begin(9600);
BT1.begin(38400);
}
void loop()
{
if (BT1.available())
{
// reciving LDR value
byte m = BT1.readBytesUntil('\n', myData, 10);
myData[m] = '\0';
ValueLDR = atoi(myData);
//Serial.println(ValueLDR);
// sending
if (ValueLDR <= 500)
{
BT1.println(v0);
Serial.println(v0);
}
else
{
BT1.println(v1);
Serial.println(v1);
}
delay(100);
}
}
Code for BT2:
#include <SoftwareSerial.h>
SoftwareSerial BT2(3, 2);
char myData[10];
int ValueLDR;
int v1 = 1;
int v0 = 0;
void setup()
{
Serial.begin(9600);
BT2.begin(38400);
}
void loop()
{
if (BT2.available())
{
// reciving LDR value
byte m = BT2.readBytesUntil('\n', myData, 10);
myData[m] = '\0';
ValueLDR = atoi(myData);
//Serial.println(ValueLDR);
// sending
if (ValueLDR <= 500)
{
BT2.println(v0);
Serial.println(v0);
}
else
{
BT2.println(v1);
Serial.println(v1);
}
delay(100);
}
}
My question is: is it possible to bypass the limitation of the SoftwareSerial() library by using the listen() function mentioned earlier?
If not I have an alternative solution, buying a second LDR sensor and mounting both of them directly on the BT1 and BT2 boards. Even so, I would love for the original plan to work.
Somebody else had doubts about having two SoftwareSerials going.
I wonder how it might work with another device, one with two UARTs. Or using one with a hardware UART and SoftwareSerial.
With a Leonardo you can keep SerialMon on the USB, use its Serial1 for one BT 'channel' and open SoftwareSerial for the other - if that's the problem (and I don't know that it is).
If you used an LCD instead of SerialMonitor (to see your data), you could use the Uno UART on 0,1 and have one instance of SoftwareSerial. Maybe that would work - at least to find out if the two BT 'networks' can co-exist (without buying something else to find out).