programme giving me headaches

im trying to get a mega2560 to receive a serial out put from the bluetooth shield, and then just switch one of three pins on for one second
the code attached activates the bluetooth no prob, but it doesnt seem to communicate the single inputs and no pin seems to react id be greatful if anyone could look over it to see if there is a glaring error or can suggest a better way of doing it

thanks
/* Upload this sketch into Seeeduino and press reset*/

#include <SoftwareSerial.h> //Software Serial Port
#define RxD 5
#define TxD 4

#define DEBUG_ENABLED 1

SoftwareSerial blueToothSerial(RxD,TxD);

void setup()
{
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
pinMode(33,OUTPUT);
pinMode(35,OUTPUT);
pinMode(37,OUTPUT);
setupBlueToothConnection();

}

void loop()
{
char recvChar;
while(1){
if(blueToothSerial.available()){//check if there’s any data sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar);
}
if(Serial.available()){//check if there’s any data sent from the local serial terminal, you can add the other applications here
recvChar = Serial.read();
blueToothSerial.print(recvChar);
int inByte=Serial.read();
switch(inByte){
case’r’:
digitalWrite(33,HIGH);
delay(1000);
digitalWrite(33,LOW);
break;
case’l’:
digitalWrite(35,HIGH);
delay(1000);
digitalWrite(35,LOW);
break;
case’f’:
digitalWrite(37,HIGH);
delay(1000);
digitalWrite(37,LOW);
break;
default:
for(int thisPin=33;thisPin<38;thisPin++){
digitalWrite(thisPin,LOW);
}}

}
}
}

void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as “SeeedBTSlave”
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println(“The slave bluetooth is inquirable!”);
delay(2000); // This delay is required.
blueToothSerial.flush();
}

If you are using a Mega, then why are you also using SoftwareSerial? You do know the Mega has 4 UARTs right?

Also can you format your code so it can be read and also put your code inside code tags. Click the <> button above this face :neutral_face:.

im trying to connect via blue tooth to a psion which is running a industry programme that send out a ‘r’ ‘l’ or ‘f’
via tthe bluetooth it was the only way i could think of doing it i am very new and green at these so i need all the help i can get

thanks for your comments ill see if i can do something about tidying up the code but at the moment the problem is pressing as i need to get this working soon

      int inByte=Serial.read();
      switch(inByte){

You say that the Psion is sending r, l or f via Bluetooth but in this section of code you are not reading from Bluetooth. Is that right ?

   if(Serial.available())
    {//check if there's any data sent from the local serial terminal, you can add the other applications here
      recvChar  = Serial.read();
      blueToothSerial.print(recvChar);
      int inByte=Serial.read();
      switch(inByte){
      case'r':
        digitalWrite(33,HIGH);

You only enter the switch/case if data is available from the hardware serial. Is that right ?

Get rid of SoftwareSerial and use hardware serial Serial1 which has Tx1 and Rx1 on pins 18 and 19. It works much better than SoftwareSerial.

You use Serial1.print() in the same way that you use Serial.print() etc with the serial connection that connects to your PC.

Then there is no need for pinMode for those pins. You must have a GND connection to the Bluetooth module as well as Rx and Tx. Some Bluetooth modules only work at 3.3v so you need to step-down the Arduino Tx signal from 5v.

...R

If you insist on using SoftwareSerial, using it on pins that do not support pin change interrupts is just plain stupid. The SoftwareSerial documentation tells you which pins you can use. The ones that are not listed can NOT be used. Pins 4 and 5 are NOT listed.

UKHeliBob:       int inByte=Serial.read();       switch(inByte){

You say that the Psion is sending r, l or f via Bluetooth but in this section of code you are not reading from Bluetooth. Is that right ?

Bluetooth modules I know connect to TTL serial. You can send the AT commands or another way.

thanks to all for help, ill be trying these various things and suggestions but i am a novice at this and its difficult to get my head around some of the stuff but still trying

thanks again