Hi! I am the tipical newbie with problems... thanks in advance
I'm trying to run a bluetooth device with a test sketch. The intention is that by sending an ascii character through another Bluetooth device (in this case the character "i"), turns on an LED on pin 13. The problem is:
If I use the standard hardware serial (Rx on pin 0 and Tx on pin 1), does NOT work. But if I use the software serial library <SoftwareSerial.h>(Rx on pin 2 and Tx on pin 3), it works.
In the first case I use this sketch: (does NOT work)
// Schema: Arduino - TTL Bluetooh: GND to GND, 3V3 to 3.3, Rx(pin0) to Tx, Tx(pin1) to Rx. With external power supply
void setup(){
Serial.begin(9600); //Bluetooth
pinMode(13, OUTPUT);
}
void loop() {
byte data;
char* menssage;
if (Serial.available()) {
data=Serial.read();
switch(data){
case 105: // i
digitalWrite(13, HIGH);
menssage="LED on";
break;
case 107: // k
digitalWrite(13, LOW);
menssage="LED off";
break;
default:
Serial.print(data);
Serial.print(": ");
menssage="Error";
delay(200);
}
}
}
In the second case I use this other sketch: (It works)
// Schema: Arduino - TTL Bluetooh: GND to GND, 3V3 to 3.3, Rx(pin2) to Tx, Tx(pin3) to Rx. USB connected to PC, NOT external power supply
#include <SoftwareSerial.h>
SoftwareSerial SerialExtra (2, 3);
void setup(){
Serial.begin(9600); // Debug
SerialExtra.begin(9600); // Bluetooth
pinMode(13, OUTPUT);
}
void loop() {
byte data;
char* menssage;
if (SerialExtra.available()) {
data=SerialExtra.read();
switch(data){
case 105: // i
digitalWrite(13, HIGH);
menssage="LED on";
break;
case 107: // k
digitalWrite(13, LOW);
menssage="LED off";
break;
default:
Serial.print(data);
Serial.print(": ");
menssage="Error";
delay(200);
}
}
}
My Arduino is the standard "Uno" model and the TTL bluetooth is like this:
http://www.ebay.es/itm/Serial-USB-Bluetooth-RF-TTL-Transceiver-Module-RS232-3-3V-DC-8mA-for-Arduino-/290647062190
I have tried several configurations and searched the web... I've even reflash the 8u2, but the "Hardware serial " doesn't seem to work
Where can be the error? Does this device can not work with the standard serial pins 0&1?
By the way, happy new year!!