If you don't have much time, you can just read blue part
I am trying to get RSSI value from HC05 and Arduino UNO for time, and I finally got RSSI
But the case is, it is very hard to get,
(I plug off the Arduino, plug off 5 v pin, then plug on arduino, press the button on the HC05 while plugging in 5v pin again, and pull my hand from the button to get AT command mode; send at+init and at+inq commands[I have to press the button while sending at+ing code) to finally RSSI code :/)
I have this code and it is working
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11);
char c = ' ';
boolean NL = true;
void setup() {
Serial.begin(38400);
BTSerial.begin(38400);
}
void loop()
{
if (BTSerial.available())
{
c = BTSerial.read();
Serial.write(c);
}
if (Serial.available())
{
c = Serial.read();
BTSerial.write(c);
if (NL) {
Serial.print(">");
NL = false;
}
Serial.write(c);
if (c == 10) {
NL = true;
}
}
}
I need it automatic and continuous. So; firstly, I though that
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11);
char c = ' ';
String command="at+init";
String command3="at+inqm=1,1,48";
String command2="at+inq";
boolean NL = true;
void setup() {
Serial.begin(38400);
BTSerial.begin(38400);
BTSerial.println(command);
if (BTSerial.available())
{
c = BTSerial.read();
Serial.write(c);
}
BTSerial.println(command3);
if (BTSerial.available())
{
c = BTSerial.read();
Serial.write(c);
}
}
void loop()
{
BTSerial.println(command2);
if (BTSerial.available())
{
c = BTSerial.read();
Serial.write(c);
}
if (Serial.available())
{
c = Serial.read();
BTSerial.write(c);
if (NL) {
Serial.print(">");
NL = false;
}
Serial.write(c);
if (c == 10) {
NL = true;
}
}
}
did not work
Then I though it might be because some timing case and that entering AT mode technique(Basically I though code works at wrong times)
So, I decided that maybe a system which would send at+inq command at every, for example, 30 seconds would work.
I though a parallel loop which works as a timer would do the job. After some googling, I learned double loop just does not work.
Then, I learned there is something called "timer". I checked it, but seemed a little complicated, so I looked trough reference to find something alternative.
I found millis() function and an example code. I planned to make a code which sends commands based on that function, like if(3000<millis()<4000) something...
But the case is, I don't know how much it takes to get one RSSI value. So I built an experiment code by inserting example code to my working one
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11);
unsigned long time;
char c = ' ';
boolean NL = true;
void setup() {
Serial.begin(38400);
BTSerial.begin(38400);
}
void loop()
{
if (BTSerial.available())
{
c = BTSerial.read();
Serial.write(c);
time = millis();
//prints time since program started
Serial.println(time);
delay(500);
}
if (Serial.available())
{
c = Serial.read();
BTSerial.write(c);
if (NL) {
Serial.print(">");
NL = false;
}
Serial.write(c);
if (c == 10) {
NL = true;
}
}
}
However, when I started with entering at+state? command, the respond is
And I have no idea what to do next
EDİT= Colours