We are working on a project that deals with Bluetooth device tracking using RSSI values. In a prototype that we are putting together, we have two transceivers, they are mainly breakout boards developed by SparkFun using the RN-41 Bluetooth module by Microchip.
We can set up the two modules to communicate with one another with one connected to Arduino and we can enter command mode and initiate the connection through the serial monitor. We can also initiate an RSSI reading through the serial monitor; when this happens we get an output of the following format:
RSSI=ff,ff
RSSI=fd,fd
RSSI=fc,fc
RSSI=fd,fc
These will keep printing to the serial monitor until we send the command 'l'. The two hex values are separated by the comma. We are mainly looking for the first hex value which is the CURRENT reading. The second hex value (after the comma) is the LOWEST reading that has ever occurred so far in the test.
THE PROBLEM:
We would like to read in that first hex value and store it for program use. Any ideas on the most efficient way to achieve this?
Here is an example of the code that we have to initiate the connection and start reading the values:
/*
Example Bluetooth Serial Passthrough Sketch
by: Jim Lindblom
SparkFun Electronics
date: February 26, 2013
license: Public domain
This example sketch converts an RN-42 bluetooth module to
communicate at 9600 bps (from 115200), and passes any serial
data between Serial Monitor and bluetooth module.
*/
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
String data;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(57600); // The Bluetooth Mate defaults to 115200bps
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(100); // Short delay, wait for the Mate to send back CMD
// bluetooth.println("U,9600,N"); // Temporarily Change the baudrate to 9600, no parity
// // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
// bluetooth.begin(9600); // Start bluetooth serial at 9600
bluetooth.println("i");
delay(15000);
bluetooth.println("c");
delay(15000);
bluetooth.print("$"); // Print three times individually
bluetooth.print("$");
bluetooth.print("$"); // Enter command mode
delay(1000);
bluetooth.println("l");
}
void loop()
{
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print((int)bluetooth.read());
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
bluetooth.print((int)Serial.read());
Serial.print((char)Serial.read());
}
// and loop forever and ever!
}