The Question and Setup
I'm trying to have my Arduino Pro Mini (w/ ATmega328) communicate with a serial device via RS232. Specifically, I want the arduino to eventually communicate with a BKPrecision 1785B power supply and control its voltage, current, etc.
One caveat. I'm using my computer (via the only RS232 hookup on the arduino) to program and debug the code, and my arduino only has one serial port. Therefore, I decided to use the SoftwareSerial library to setup an additional software RS232 port (on digital pins) for communicating with the power supply.
What I've done to date
I tried implementing the above, but the BK1785 didn't show any sign of receiving or understanding the commands. I then plugged in a second computer into the SoftwareSerial port (instead of the power supply) to monitor communication and make sure that the commands were properly sent. The second computer (using Docklight as a serial monitor) noticed that information was being received, but it didn't match what was sent (see below). I can only assume that the I haven't set up the adruino to communicate correctly. It seems most likely that it must be either 1) the Software serial setup or 2) me incorrectly broadcasting the data.
Additional info
The power supply requires a packet of 26 bytes.
Docklight is setup as 9600, 8N1 (edit#1)
Arduino Code
This is the simplified code that I'm running on the Arduino.
#include <SoftwareSerial.h>
SoftwareSerial port1(4,3);
byte output[26]={170, 0, 32, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 203};
void setup()
{
Serial.begin(9600);
port1.begin(9600);
digitalWrite(6,LOW); //Set ground pin on SoftwareSerial to LOW
delay(5);
}
void loop()
{
for (int i=0;i<26;i++){
port1.write(output[i]);
}
delay(10000);
}
Output and Input
I'm broadcasting the following 26 bytes (shown below in dec. format) from the arduino (see code above) through the SoftwareSerial port: 170, 0, 32, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 203
My second computer (connected to the SoftwareSerial port of the arduino) is receiving the following 25 (not 26) bytes (also shown in dec. format): 149 191 253 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 105
Final thoughts
I've tried using both the write and print commands in the arduino, but neither appear to work. Honestly, I have no idea if using the for loop to send the 26 bytes is the correct way to send information like that. Is there a better method for sending a packet of bytes? I poked around on the internet, but I couldn't mind a similar example. I would appreciate any feedback for the community. Thanks!
Edit#2
I replaced the for loop in my code with the following line:
port1.write(output,26);
and received a the identical set of 25 bytes: 149 191 253 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 105
Edit#3
I'm trying to post images of my oscilloscope traces, but I don't have 10 reputation points yet.
Is the serial communication receive line supposed to be high when there is no data sent?