Hey guys!
I´m struggling with this second day, searched all the Google, I´m desperate.
I´m trying to send a key stroke on a pushButton press to RN42 and as a result do display this in Tera Term. It may sound like a very easy thing to do, but I´m not sure where the problem is.
Basically, I am aware of how to set it up, using SoftwareSerial library would like to send the stroke and receive it on a PC. Indicator LED blinks, also TX LED on Arduino and even LED on RN42 blinks, but no data are displayed. I flashed the HID soft from RN42 to HC05…not sure if this may be related. Here´s the sketch
/*
BT communication test
*/
#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
int inPin = 12; // the number of the pushbutton pin
int ledPin = 13; // choose the pin for the LED
int val = 0; // variable for reading the pushbutton status
//for tests
byte message[] = {0xAA, 0xBB, 0x06, 0x00, 0x00, 0x00, 0x01, 0x01, 0x03, 0x03 };
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(9600);
delay(50);
bluetooth.print("$$");
delay(50);
bluetooth.print("SN,Vlktch zmena\r\n");
delay(50);
bluetooth.print("S~,6\r\n");
delay(600);
bluetooth.print("SH,0000\r\n");
delay(2000);
bluetooth.print("R,1\r\n");
delay(400);
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
Serial.println("Serial ready, hello world!");
Serial.println("RN42 configured");
bluetooth.begin(9600);
Serial.println("BT Serial ready");
}
void loop()
{
val = digitalRead(inPin); // read input value of pushButton
if (val == LOW) {
digitalWrite(ledPin, LOW); // turn LED OFF
delay(100);
} else {
digitalWrite(ledPin, HIGH); // on push turn LED ON
Serial.println("0xFD, 0x03, 0x03, 0x80, 0x00"); //once pressed, content displayed in Serial, should be taken to the BT console of Teraterm(not working)
//Serial.write(message, sizeof(message)); message above, works
bluetooth.print("test"); //print test not working
bluetooth.write("test");//write test not working
delay(300);
}
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print((char)bluetooth.read());
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
}
}
I´ll be very happy for all the suggestions!
Mike