Sending Serial data

Chaps,
I have a product which is controlled via RS232 serial commands. I would like to make an intermediate board between it and what will control it using arduino, the reason for this is that I only have a switched 5v output on the object that will control it.
I have made a code

#include <SoftwareSerial.h>

SoftwareSerial Serial22(10, 11); // RX, TX


int analogPin = 9;     

int val = 0;   
int on=0;
int state=0;
int sent=0;

int burst=0;
int burstExecute=0;
int burstCount=0;
long burstMillis=0;
long changeMillis=0;
int change=0;
int activate=0;

void setup()

{
  pinMode(2,OUTPUT);
  pinMode(9,INPUT);
  pinMode(13,OUTPUT);
  Serial.begin(9600);        
  Serial22.begin(19200);
  Serial22.println("Hello, world?");

}

void loop()

{
  unsigned long currentMillis = millis();
  val = digitalRead(analogPin); 
  
  if((currentMillis - burstMillis > 1000)&&(activate==1)){
    changeMillis=currentMillis;
    activate = 2;
  }
  if((currentMillis-changeMillis>50)&&(activate==2)){
    changeMillis=currentMillis;
    state=!state;
  }
    
  
  if((val==1)&&(on==0)){
    //digitalWrite(13,HIGH);
    on=1;
    burstMillis=currentMillis;
    activate=1;
    
    //state=!state;
    //Serial22.print("$L 1CR");
    //Serial.println("$L 1CR");
  }
  
    if(val==0){
            burstMillis=currentMillis;
            activate=0;
      if(on==1){
      on=0;
      state=!state;
      
     // digitalWrite(13,LOW);
      //Serial22.print("$L 0CR");
     // Serial.println("$L 0CR");
    }
    }
    if((state==0)&&(sent==1)){
      digitalWrite(13,LOW);
      Serial22.print("$L 0CR");
      Serial.println("$L 0CR");
      sent=0;
    }
    if((state==1)&&(sent==0)){
      digitalWrite(13,HIGH);
      Serial22.print("$L 1CR");
      Serial.println("$L 1CR");
      sent=1;
    }
      
      
}

As you can see if you read the code, this sends out the desired serial data each time a state is changed, that state is changed each time the switch which controls the 5v output is toggled,
the switch must go from off to on and back to off in order to toggle the “state”
If I leave the switch on then it will pulse the state at a certain defined speed.
The problem is that the LED on PIN13 is doing what I expect, ie lighting when the “$L 1CR” command is sent and turning off when “$L 0CR” is sent. These commands are being received both over the hardware serial and software serial through FTDI chips. ( I had fun rolling back the driver after the october 1st update that blocks fake chips)
but the end product, never reacts to the commands,
when i send these commands through hyper terminal it works fine, the baud should be 19200, and flow control off, other than that stop bits, parity and data bits are all standard.
Any ideas?

What is the electrical connection to the board? Is it RS232 which is really +/- 12 V not 0 to 5V.

You know I dont know that,
But, what I do know is that when I connect it to the hardware serial port on my panasonic toughtbook it works,
When I tried with the FTDI convertors it didnt,
maybe youre right and the voltage is 12v hence the FTDI not working to send it data,
I will try to get a datasheet.

The datasheet says control is RS232.
pffffff I guess that buggered the idea of sending data to it directly with softwareserial.
Is there a way to convert it relativly easily ?

spruce_m00se:
Is there a way to convert it relativly easily ?

From RS232 to UART?
I like to use the MAX232 chip for 5V systems, but the MAX3232 can operate at 3.3V and 5V.

If you are handy, maybe one of these circuits:
http://tinyurl.com/q839fm7

LarryD:
If you are handy, maybe one of these circuits:
HERE

Link isn't working...

http://tinyurl.com/q839fm7

so would one of these be likely to sort the problem out?

Looks OK, but is you connector a DB09 male or female also do you need any combination of RTS/CTS/DSR/DTR?

I dont think I need any reset ability,
I would remove the connector and solder it straight to the arduino and other device,

this looks interesting
http://www.ebay.co.uk/itm/Mini-RS232-TTL-Converter-Module-Board-Adapter-MAX3232-120kbps-3-5V-Serial-Port-/111473618849?pt=UK_Sound_Vision_Other&hash=item19f4586fa1

Would this be what im looking for?
its pricey, but available locally and I need to get it working quickly,

ok , it wasnt locally available,
im now looking at this

they will ups it to me, and they are nice people :slight_smile: