Hi,
I'm trying to get a 3.3V bluetooth module to work with my Mega 2560.
First off, I'm powering the Mega via its power connector using a 9V power supply. I'm not using the USB port.
Communication with the bluetooth module works just fine when I use either Serial1 of the Mega or by using Softserial. However, I would like to use Serial on port 0/1 because later on the project will be moved to an Arduino Uno where all other pins are in use.
For the TX pin 1 of the Mega I am using a voltage divider to lower the 5V to 3.3V (using 2k and 1k resistors).
For the RX pin 0 I read that this is not necessary, so I connect it directly to the bluetooth module.
The problem is, it doesn't work. I can't toggle the LED by sending "on" or "off" via bluetooth when using Serial.
One thing I noticed is that I'm measuring 5V on pin 0. I found a thread about someone else with the same problem at [SOLVED more or less] Rx and Tx pins 0 and 1 at 5v on power up: confused - Project Guidance - Arduino Forum , but it just worked for him.
In my sketch, I am not using pin 0 directly, only via the Serial library.
Here is the sketch I am using:
int ledPin = 13;
String readString;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
while (Serial.available()) {
delay(3);
char c = Serial.read();
readString += c;
}
if (readString.length() >0) {
if (readString == "on")
{
digitalWrite(ledPin, HIGH);
}
if (readString == "off")
{
digitalWrite(ledPin, LOW);
}
readString="";
}
}
Thanks for your advice.