Hello community, the following problem, Nano with Bluetooth HC05 module and Android smartphones. i send data to my smartphone every second AND WANT TO send data back to the nano at the push of a button on my smartphone. Sending from the nano works fine, but as soon as the smartphone sends, the nano does nothing. How do I lock the send and receive function mutually so that there is no time problem.
I forgot, only sending from the smartphone and only sending from the nano works
post your code, your circuit and details about your android app....
please read How to get the best out of this forum if you have doubts about what can help us help you
What is the app on the phone?
I created the APP with App inventor
and here the code of the nano
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10,11); // Bluetooth Modul
long BTTimer = 0;
long BTTimeout = 1000;
void loop()
{
if (millis() > BTTimeout + BTTimer )
{
BTTimer = millis();
BT_senden();
}
if (BTSerial.available() > 1)
{
BT_empfangen();
}
}
>
void BT_senden()
{
BTSerial.print(1);
BTSerial.print(",");
BTSerial.print(Spannung);
BTSerial.print(",");
BTSerial.print(Ampere);
BTSerial.print(",");
BTSerial.print(AHist);
BTSerial.print(",");
BTSerial.print(Temperatur);
BTSerial.print(",");
BTSerial.print(Luftfeuchtigkeit);
BTSerial.print(",");
BTSerial.print(Zellenspg1);
BTSerial.print(",");
BTSerial.print(Zellenspg2);
BTSerial.print(",");
BTSerial.print(Zellenspg3);
BTSerial.print(",");
BTSerial.print(Zellenspg4);
BTSerial.print(",");
BTSerial.print(KWHist);
BTSerial.println();
}
void BT_empfangen()
{
// all float
ShuntTyp = BTSerial.parseFloat();
ShuntOffset = BTSerial.parseInt();
Spannung = BTSerial.parseFloat();
Ampere = BTSerial.parseInt();
AHmax = BTSerial.parseInt();
AHist = BTSerial.parseInt();
KWHist = BTSerial.parseInt();
Ladefaktor = BTSerial.parseInt();
Temperatur = BTSerial.parseInt();
Luftfeuchtigkeit = BTSerial.parseInt();
Zellenspg1 = BTSerial.parseInt();
Zellenspg2 = BTSerial.parseInt();
Zellenspg3 = BTSerial.parseInt();
Zellenspg4 = BTSerial.parseInt();
}
You code is missing the setup() function.
What does the app send when the button is pressed?
indeed we need the setup
also if you want this to work in the future
use unsigned long and do
if (millis() - BTTimer > BTTimeout)
you should wait for SoftwareSerial to complete the sending before trying to listen as it cannot transmit and receive data at the same time
void setup()
{
Wire.begin();
Serial.begin(9600);
BTSerial.begin(9600);
if (!adc.init())
{
Serial.println("ADS1115 not connected!");
}
adc.startSingleMeasurement();
adc.setVoltageRange_mV(ADS1115_RANGE_0256 );
adc.setCompareChannels(ADS1115_COMP_2_3);
adc.setConvRate(ADS1115_8_SPS);
}
In the future post complete sketch. missing variable definition etc
but your main issue is probably that your software serial port is busy sending and receiving at the same time and it's not supported.
may be you could use the hardware serial port for your BT module. It means you need to unplug it when uploading the code and you loose the debug capability using the Serial monitor but at least you have a more capable UART
alternatively get an Arduino with more hardware serial ports like a Mega for example
Danke
that was the question
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.