greetings,
i'm trying to handle strings sent from android bluetooth to the arduino and vise versa.
for example if i send from the android string "hello" i can see it clearly at the serial port, however i can't deal with this string to "string compare" it for example to do an action or something, where i can only read single characters by serial read which are translated to asci code.
that's for recieving from the android to the arduino.
as for transmitting from the arduino to the android, i'm trying to get data from the serial port which is a hexadecimal reading of an infrared reciever and send this data as a string via bluetooth, where i use fprint to convert the hexadecimal which is "unsigned long int" to "string" but when i send this via bluetooth i get nothing or boxes.
NOTE:
- i'm using Ken Shirriff's library:
A Multi-Protocol Infrared Remote Library for the Arduino
-and one the samples of usbhostshield 2 called "SPP.ino" in bluetooth folder:
http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino
-SerialBT.print actually sends data via the bluetooth it's doesn't print something at the serial monitor
here is my code:
#include <SPP.h>
#include <IRremote.h>
USB Usb;
BTD Btd(&Usb);
SPP SerialBT(&Btd);
IRsend irsend;
boolean firstMessage = true;
int i=0;
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(115200);
irrecv.enableIRIn();
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while(1); //halt
}
Serial.print(F("\r\nSPP Bluetooth Library Started"));
}
void loop() {
Usb.Task();
if(SerialBT.connected) {
if(firstMessage) {
firstMessage = false;
SerialBT.println(F("Hello from Arduino")); // Send welcome message
}
if(Serial.available())
{
SerialBT.print(Serial.read());
}
if(SerialBT.available())
{ Serial.write(SerialBT.read());
// delay(100);
int a=0;
char c;
a=SerialBT.read();
// c=SerialBT.read();
SerialBT.println(a);
}
}
else
firstMessage = true;
if (irrecv.decode(&results)) {
Serial.print(results.value, HEX);
char buf[50];
sprintf(buf, "test",results.value,HEX);
SerialBT.println(buf);
// i get test and nothing then//
irrecv.resume();
}
}