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?