title: SoftwareSerial communication to RS232 device with Arduino
body: <p><strong>The Question and Setup</strong></p>
  
  <p>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.  </p>
  
  <p>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.  </p>
  
  <p><strong>What I've done to date</strong></p>
  
  <p>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.  </p>
  
  <p><strong>Additional info</strong></p>
  
  <p>The power supply requires a packet of 26 bytes.<br>
  Docklight is setup as 9600, 8N1  (edit#1)</p>
  
  <p><strong>Arduino Code</strong></p>
  
  <p>This is the simplified code that I'm running on the Arduino.  </p>
  
  <pre><code>#include &lt;SoftwareSerial.h&gt;
  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&lt;26;i++){
       port1.write(output[i]);
     }
     delay(10000);
  }
  </code></pre>
  
  <p><strong>Output and Input</strong></p>
  
  <p>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</p>
  
  <p>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 </p>
  
  <p><strong>Final thoughts</strong></p>
  
  <p>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!  </p>
  
  <p><strong>Edit#2</strong></p>
  
  <p>I replaced the for loop in my code with the following line:</p>
  
  <pre><code>port1.write(output,26);
  </code></pre>
  
  <p>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</p>
  
  <p><strong>Edit#3</strong></p>
  
  <p>I'm trying to post images of my oscilloscope traces, but I don't have 10 reputation points yet.<br>
  Is the serial communication receive line supposed to be high when there is no data sent?  </p>