I am trying to read data from a balance/scales throught a Max232 converter that is connected to a arduino duemilanove w/Atmega 328 board to pin 2rx and 3tx then connected to my computer with USB cable.
I'm trying the following code but do not get any data from the balance.
#include <SoftwareSerial.h>
//rx and tx pins for software serial - connect to laptop
int rx_pin = 2;
int tx_pin = 3;
int reading;
int baudrate = 9600;
int startbyte;
int userInput[3];
int byte_1;
int byte_2;
int i;
int smoke_toggle = LOW;
int led_toggle = LOW;
int status = LOW;
SoftwareSerial softSerial = SoftwareSerial(rx_pin, tx_pin);
void setup()
{
// Connections to balance
Serial.begin(baudrate);
// default is 8N1. Need to change to 7N1
// change to 7 data bits
UCSR0C =UCSR0C | B00000100;
softSerial.println("start");
Unless the reference for SoftwareSerial is not current (entirely possible), begin() only allows you to set the baud rate. Since the scale needs 7N1, that poses a real problem. Switching the roles of the hardware and software serials might not be possible unless the pc has a serial port as well as USB.
Hmm, I thought I'd seen support for 7N1 in softwareserial, but when I peruse the latest source I don't see it. Maybe I was reading a feature request or something...
EmilyJane is correct, you may need to move some things around so that you talk to the scale via the hardware UART and talk to the PC using softwareserial.
Unless there is a way you can make the scale speak 8N1?