I have a Compact Mega 2650 with the JY-MCU Bluetooth module. I have the BT module connected to pin 2 and 4 (Rx and Tx on the JY-MCY, Tx and Rx defined on SoftwareSerial). All that I want is to write something on the Mega and read it on the computer. The computer and the JY-MCU pair with no problem, and I open a serial terminal and connect to the BT port at 9600 baud to read what the arduino sends. I am running the following code on the Mega:
#include <SoftwareSerial.h>
const int rxPin = 4; //SoftwareSerial RX pin, connect to JY-MCY TX pin
const int txPin = 2; //SoftwareSerial TX pin, connect to JY-MCU RX pin
// level shifting to 3.3 volts may be needed
SoftwareSerial mySerial(rxPin, txPin); // RX, TX
const int ledPin = 13; // led pin
int state = 0; // if state is 1, the LED will turn on and
// if state is 0, the LED will turn off
int flag = 0; // a flag to prevent duplicate messages
void setup() {
// sets the pins as outputs:
// pinMode(ledPin, OUTPUT);
mySerial.begin(9600);
// digitalWrite(ledPin, LOW); // LED is initially off
}
void loop() {
//reads serial input and saves it in the state variable
if(mySerial.available() > 0){
mySerial.println("1234");
delay(1000);
}
}
I get nothing at all back. Any ideas on how I can approach debugging this? Is there an obvious problem with the code? Thanks for the help.
Bret