Pages: [1]   Go Down
Author Topic: Trouble with Serial and relay board  (Read 1073 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Greetings all.
I'm having trouble interfacing an arduino board with a National Control Devices/Control Anything ProXR Relay board.
The ProXR looks for serial commands, in DEC format, such as:

(254, 108) //254=command address, 108=activate relay1, bank1

So, I've tried outputting this data in multiple ways, but haven't been able to get the Arduino to activate, or even be recognized by the relay board. I know I've achieved this in the past by using serout on a basic stamp board without issue.

I've been trying the simplest command sets possible, something like:

int ledPin = 13;

void setup(){
  Serial.begin(9600);
}

void loop(){

 Serial.print('254', DEC);
 Serial.println('108', DEC);
 digitalWrite(ledPin, HIGH);
 delay(500);
 Serial.print('254', DEC);
 Serial.println('100', DEC);
 digitalWrite(ledPin, LOW);
 delay(500);

}


I've tried this with variations, such as:

Serial.print(254, DEC);
Serial.println(108, DEC);

Or no println, just prints, etc. Or with quotations. Or without DEC.
Nothing works. The baud rate is correct, and the relay board functions from it's PC control software without issue.
It has a log which shows each command set being entered on a separate lines, but in the manual, it details the commands codes such as this:

(254, 108)
(etc...)

If anyone has any thoughts, please let me know! I'm perplexed!

Thanks,
Jason
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Use NewSoftSerial to "create" a second serial port (assuming you're not living in the land of Mega luxury), and "talk" to your device on a serial channel not shared with programming and the serial monitor...

Details...

http://sheepdogguides.com/arduino/art4SeIntro.htm
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Actually I do have a Mega (I've been testing on it, and a Diecimila), and even using Serial2 (or any other for that matter) didn't improve the situation!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Reading the documentation for the board, I think it wants you to send the ASCII character code for the decimal number therefore I would think the statement:

Serial.print('254', BYTE);

Would be more appropriate.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just tried replacing DEC with BYTE, and also tried some changes to print/println, but still no luck.
Although the manual states the ASCII character code, it also specifically states in DEC format elsewhere, and in their windows software the log window also indicates it is transmitting as DEC...?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try sending the value without the single quotes:

Serial.print(254, BYTE);
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

joec - just tried that, with various combos of print/println, and no still no luck!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That really should work, Serial.print(254, BYTE); should emulate the VB function MSComm1.output = Chr$(254); that they use in their documentation examples.

To Send ASCII 254 from Visual Basic, you will use the following
line:
MSComm1.Output = Chr$(254)

In Qbasic, you can send ASCII 254 using the following line of
code:
Print #1, Chr$(254);
Note that sending ASCII character code 254 is NOT the same
as sending ASCII characters 2, 5, and 4 from a terminal program.
Typing 2, 5, and 4 on the keyboard will transmit three
ASCII character codes.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That was my conclusion as well, which is why this is so frustrating!

I have to have this board done by tomorrow evening, so any other thoughts or suggested would be much appreciated.
Given what the manual says, and the Arduino reference info for Serial.print and Serial.println, this should be working!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are using the Serial.print(254, BYTE); construct in your program it should be sending the correct data. If it still doesn't work I would review the hardware connection. It appears the relay board requires an RS232 interface, are you using an RS232 converter shield with your Ardunio. Are you sure your cable is correct, Xmit to Rec and Rec to Xmit. Is baud rate correct? I think you have the software correct, you can verify the Serial.print(254, BYTE); construct by sending Serial.print(65, BYTE); out to your PC, decimal 65 should display as an ASCII 'A' character, unfortunately 254 does not have an ASCII equivilant character so you can't check that very easily.
Logged

Sussex UK / CT USA
Offline Offline
Edison Member
*
Karma: 0
Posts: 1028
Forums forever
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Try "talking" to the board from a PC, using Hyperterminal or PuTTY, just to see if it is listening. If it won't work that way either, maybe the board is faulty.

You HAVE dealt with the RS-232 vs TTL signal level issues, haven't you?

Need more on THAT?... see...

http://www.arunet.co.uk/tkboyd/ec/ec1ser232.htm
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8897
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to check the input to the NCD device to see if it accepts ttl or the inverted rs232, and you may need to put a cr/lf on the end of the transmission using something like Serial.println(readString);
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello - thanks for this recent round of remarks.

@tkybd: I noted testing it form the PC software, and it operates without a hitch.

@zoomcat/joec: I'm using the serial shifter seen here: http://www.sparkfun.com/datasheets/Prototyping/RS232-Shifter-v2.pdf - however with or without it I don't get positive results (powering it with +12V by the way).
The CR issues has had me wondering a few times, but seeing that I've tried various combinations of Serial/print vs Serial.println and nothing changes, well, I've started to rule it out as being the issue.

As far as hardware, I've swapped the wires around (tx/rx) but it doesn't change a thing.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No Termination such as lf/cr are required.  The controller is expecting a real RS 232 input.  The arduino may have a uart output which would need to go through a Max 202 chip to bring the signal to true RS 232 levels and polarity.  This Chip inverts the polarity of the data which may be why this is not working.
Logged

Pages: [1]   Go Up
Jump to: