Balance (Mettler) readout using RS232

I have no idea. Someone else will have to help with that question.

Thanks for your help by the way.

Also, the Mettler Balance has a "continuous" mode in the rs232 settings which I enabled b/c that was the only way to see the output in putty. When I connect to the balance the 'R' light on the RS232->TTl lights up steady and that's when the chip gets hot. Could the continuous mode be the culprit? really shouldn't be sending so much data that the chip is overheating though.

Played a bit more and when I have everything connected to the arduino and I jumper the rx and tx pins on the board I get my serial input returned to me, but when I connect pins 2 and 3 on the d-sub I do not get the input echoed back.

Makes me think something on the board is defective.

sailhobie:
Could the continuous mode be the culprit?

No.

I am having trouble reading the balance output on the arduio leonardo

Your code? Your problems?

SOLVED

it was a "gender" issue, where the rx/tx were not hooked up properly between balance and converter. The balance has a female and the rs232 converter board was also a female so the tx was not connect to the rx and vice versa.

ended up using a null mdoem cable with two female ends and attaching a straight thru male converter on each end...and voila it worked.

Thanks everybody for thinking about it with me.

Hi there ..
My case is almost identical to your case .. I am still finding the solution ...

I want to control a UPS device using its Rs232 port via Arduino. I made a circuit consisting of MAX3232 on a small wire board which is in between arduino and UPS Rs232 port.

When I connect the UPS directly with my PC and send serial commands using a terminal software, the UPS responds very well. One of the basic command is just a 0x0d character. However, when I send the same command using arduino, the UPS fails to respond. I tested the output of arduino by connecting its DB9 connector to the PC, and found that it sends all commands correctly without any illegal character. The settings on the PC terminal are 2400 baud with data size 8, parity none, handshake off. With these settings, the PC communicates with UPS and arduino well. However, arduino itself when connected directly to the UPS, fails to receive any output from the UPS.

Here is the software code programmed in the arduino:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7); // RX, TX
void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("Starting!");

  mySerial.begin(2400);
  mySerial.write(0x0d);

  delay(1000);
  if (mySerial.isListening()) {
   Serial.println("Port One is listening!");
  }
}

void loop() // run over and over
{
  while (mySerial.available() <= 0) {
    mySerial.write(0x0d);
    Serial.println("Sent");
    delay(5000);
  }

  if (mySerial.available())
  {
    Serial.write(mySerial.read());
  }
  if (Serial.available())
    mySerial.write(Serial.read());

  if (mySerial.overflow()) {
    Serial.println("Overflow ...");
  }
}

I think the output of MAX3232 has some voltage issues which are not detected by UPS but are detected by PC. I am now planning to make a RS232 monitor cable to see if communication is ok. It is at RS232 connector pin assignment

Could you change this: while (mySerial.available() <= 0) {
into this: while (mySerial.available() == 0) {

The RS232 voltage levels are important, and the RX and TX always get mixed up.

Do you use a terminal program to communicate with the UPS device from the PC ? You could use that to make the PC behave like the UPS device.
So you have the serial monitor of the Arduino IDE and a terminal program that you use to behave like the UPS device. Both connected to the Arduino.
Could you try to make the Arduino send an 'A'. If that works, try the 0x0D. Try to send something from the PC and see if the Arduino receives that.

When that is working, connect the Arduino to the UPS.

Yeah my issue was the rx and tx being mixed up. Is the port on the UPS female? what about the converter you are using? if they are both female, which was my case, you will probably need a cable the crosses the rx and tx lines; a *null modem cable".

I haven't had to send anything to the balance though, so I am only trying to read from the balance.

I used this sketch to test if the serial device was talking back. I have a leonardo which uses Serial1 for the pin 2, and 3 rx tx, and serial for the USB. I loaded the sketch and typed in the serial console and it would echo back when working.

void setup()
{
//Initialize Serial and wait for port to open:
  Serial.begin(9600); // start USB Serial connection
  Serial1.begin(2400);// start RS232 balance connection
  while (!Serial) {
    ; // wait for Serial port to connect via USB. Needed for Leonardo only
    }
}

void loop() {
  char c;
  char d;
  // echo all received characters to test the communication.
  if (Serial.available() > 0) {
    c = Serial.read();
    Serial1.print(c);    // use character for readable text
    //Serial.print(c);
  }
  if (Serial1.available() > 0) {
    d = Serial1.read();
    Serial.print(d);    // use character for readable text
    //Serial.print(c);
  }
}

well finally I got the success ... I attached the pin14 and pin13 of Max3232 to pin3 and pin2 of DB9 respectively ... previously they were other way round ... thats the reason the arduino was communicating well with the PC but not with the UPS device ...

all the circuit diagrams listed on the internet are actually designed to communicate Arduino with PC. I was following: avrprogrammers.com -. My mistake was that the pin connections from Arduino to DB9 were that for PC.

Another problem is that the UPS sends 164 byte data while Arduino is unable to read data beyond 64 bytes ... i think arduino needs some adjustments in the buffer size ...

Thank you everybody for help ..

docosama:
...Arduino is unable to read data beyond 64 bytes...

Incorrect.

Coding Badly, at least tell how to be able to read 164 bytes.

So we have 164 bytes at 2400 baud.
That is about 240 bytes per second. The 164 bytes would roughly take 0.7 seconds to transfer.

The Serial library has an internal software buffer, that is true. But during 0.7 seconds the Arduino can read the bytes from that buffer and store them in an array.

It is all about the Serial.available() function. As soon as a byte is available, read it.

I tried increased the Serial buffer to 128 bytes (method described by http://www.hobbytronics.co.uk/arduino-serial-buffer-size) but unable to read data beyond 64 bytes from the UPS device. It sends all details in 96 bytes with one command. Do you know any other method by which read serial buffer can be increased.

Post your sketch. Please use
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags.

(@Erdin, the post above is why I did not waste my time with a "long" answer. ;))

here is the code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 7); // RX, TX
int sensorValue = 0;
char query[8] = {81 ,80, 73, 71, 83, 183, 169, 13};

void setup()  
{
  int i, c;
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("Start");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(2400);
 // mySerial.write(0x0d);
  
  delay(2000);
  mySerial.write(0x0d);
  delay(2000);
  if (mySerial.available())
  {
    while (c != 13) {
      c = mySerial.read();
      Serial.write(c);
    }
    Serial.println();
  }

}

void loop() // run over and over
{
  int i;
  
  while (mySerial.available() <= 0) {
   for (i=0; i<8; i=i+1) 
        mySerial.write(query[i]);
    delay(5000);
  } 
  
  if (mySerial.available())
  {
    Serial.println(mySerial.read());
  }
  
  if (mySerial.overflow()) {
    Serial.println("Overflow ...");
  }  
   delay(10000);
   
}

I'm sorry docosama, but your sketch needs to be rewritten from scratch. I don't want to do that right now.

Start by sending 0x0D and copy the incoming data to show it on the serial monitor.
I think, that is the best way to get a result.
For a timeout, you can use millis();

It is normal to have a number of test sketches while developing something.

Do you have a better idea ?

whats wrong with the sketch ?

When data from query variable is sent to the UPS, the incoming data is:

231.0 50.4 231.0 50.4 0000 0000 000 423 26.76 05 094 0459 -- Overflow ...

The actual data from UPS consists of 96 bytes and arduino is unable to read beyond 64 bytes ..

docosama:
whats wrong with the sketch ?

I'm sorry to say, but it is a lot. The next problems is about half of the problems:

  • After sending 0x0d, you wait 2 seconds. The buffer gets full in those 2 seconds. You have to read incoming data as soon as it is available.
  • Because the buffer gets full, the value 13 ( which is CarriageReturn, '\r') is not detected.
  • In the function loop() you transmit something if nothing is available. I think that is not a good software layout.
  • You test available for "<=". That is not possible.
  • You wait 5 seconds after sending the query, but you should read incoming data as soon they are available.
  • You use an 'if' statement to read data and copy them to the serial monitor. So only one character is copied, instead of a string.

in the loop(), you can see the command (in query) sent ... if I remove the delay completely, still the arduino receives just 64 bytes ...

If I wait for 2 seconds, I receive the exact data what I am expecting from the UPS in the setup() area ... so even without delay, the response is same ...