Hello,
I am trying to read out the weight displayed on a Mettler PB1502 balance. Maybe there is somebody out there who is a bit more experienced in doing that or has experience running RS232 compatible devices on Arduino.
The balance is set to the following parameters: baud 9600, DataBits 8, Parity None, Handshake OFF and is connected to the Arduino Leonardo board using a RS232 cable and the following "Shield": SparkFun RS232 Shifter - SMD - PRT-00449 - SparkFun Electronics.
In another forum I found that Arduino only supports DataBits 8, StopBits1, Parity None, FlowControl None - I don't know weather this is correct or weather it is possible to modify these settings on the Arduino.
In addition the balance's manual points out Pins 7 and 8 as CTS and RTD for the Handshake. Due to the fact that these pins are not connected on the Shield and because of the fact that they are turned off in the balance this should not matter.
When running the code below, the Rx LED on the Shield is blinking -> so there is something sent to the balance - problem is that there is no response. I only receive "-1"; the Tx LED is not blinking. When removing the comment from "// if (Serial1.available() > 0) {" there is nothing received.
Any help would be awesome,
Thanks!
int Read_Data = 0; // read values from balance
void setup() {
//Initialize Serial and wait for port to open:
Serial.begin(9600); // start USB Serial connection
Serial1.begin(9600);// start RS232 balance connection
while (!Serial) {
; // wait for Serial port to connect via USB. Needed for Leonardo only
}
}
void loop() {
/*
Commands (Mettler manual)
--> Command SI Send the current net weight value, irrespective of balance stability.
--> Responses S_S_<WeightValue>_<Unit> Stable weight value in unit actually set under host unit (page 17).
*/
//send command to balance to read weight
Serial1.print(0x53); //S
Serial1.print(0x49); //I
Serial1.print(0x0d); //CR
Serial1.print(0x0a); //LF
// if (Serial1.available() > 0) {
Read_Data = Serial1.read();
Serial.println(Read_Data, DEC);
// }
delay(200);
}
With regard to level shifting, this board does not have a MAX232 or equivalent, so it does not comply with the classical RS232 spec (0 = Space = +12V, 1 = Mark = -12V). Instead, its input will accept RS232 voltages on the input and shift them (-12V [mark] –> VCC, +12V [space] –> GND). For its output, it merely inverts the signal (VCC->GND, GND->VCC) so you must be using a newer UART that will tolerate this.
In other words, you will very likely be able to receive from the scale but you may not be able to send to the scale.
Do you have access to a USB to RS-232 converter so you can run tests from a PC?
The output (to the balance RX) of that Sparkfun RS232 Shifter switches between Vcc (5V) and a voltage below zero (created with the serial TX output of the Mettler balance). It is a smart circuit, but it is not according the classical specs as Coding Badly wrote.
Do you have a PC with a serial port ? Try to connect that, and see if you are able to see the respons by the Mettler balance.
If the Mettler balance is set for no handshake, you are fine if both the Arduino and the balance are set to 9600,N,8,1.
That is the default for the Arduino. They can be changed if you need to.
I would suggest to keep the wait for the serial port. But you have to open the serial monitor of the Arduino IDE to let the sketch continue after the wait.
You have to check the Serial1.available() for the balance data. So please remove those comments in the loop() function.
Your sketch is not working as expected. You send "SI" 5 times a second, and test for a single received character. So the balance is going haywire. Could you send "SI" at the bottom of setup(), and get the received characters in loop() ?
Perhaps like this:
delay( 2000);
//send command to balance to read weight
Serial1.print("SI\r\n");
first of all thanks for the hints. So if I understood correctly, there might be an issue with the 5V from the Arduino and the (probably) 12V from the balance?
I hooked up the balance to a PC COM Port and used Hyperterminal with the following setup: 9600, 8, N, 1, Xon/Xoff
After pressing "OK" the balance weight is displayed continuously:
S S 0.00 g
S S 0.00 g
S S 0.00 g
S D 0.03 g (here I started pressing on the balance)
S D 3.51 g
S D 54.36 g
S D 94.07 g
S D 135.44 g
S D 175.23 g
S D 209.86 g
...
According to the Hyperterminal result, the "send command" is not necessary and I can simply listen to the broadcast from the balance.
In addition I also changed the code as recommended - removed the comments - but this did not work.
void loop() {
/*
Commands (Mettler manual)
--> Command SI Send the current net weight value, irrespective of balance stability.
--> Responses S_S_<WeightValue>_<Unit> Stable weight value in unit actually set under host unit (page 17).
*/
//send command to balance to read weight
Serial1.print("SI\r\n");
Serial.print("SI\r\n"); // will just display the sent command in the serial monitor
delay(500);
if (Serial1.available() > 0) {
Read_Data = Serial1.read();
Serial.println(Read_Data, DEC);
}
delay(2000);
}
Maybe a little more explanation what I want to do with the program:
The program will switch a feeder on/off once a preset weight is reached (therefore the weight-reading has to be very fast).
That's also the reason why I cannot put the "send command" in the setup() because the weight shall be read continuously when the sketch is running later.
You send "SI" and read only one character.
Do you need to send "SI" at all ?
If you don't, you could just echo all characters to the serial monitor.
void loop() {
char c;
// echo all received characters to test the communication.
if (Serial1.available() > 0) {
c = Serial1.read();
Serial.print( c); // use character for readable text
}
}
You could run that test. You could also test it with the computer serial port. That is perhaps easier to check the wiring.
But you should buy a normal RS232-to-ttl-level converter. At least to have one at hand.
Hi,
sorry, forgot to write that the PC works with all the 3 settings for handshake - so "None" is also working.
I tried the new code but no luck with it.
After a long time of absence, and some quite disappointing tests with the RS232 TTL converter I give it another try. I set the balance to send mode so that it is transmitting the weight over the RS232 continuously. I tested it with the Hypertherminal on a PC and received the data.
Now to the Arduino. I have a converter with 8 out/inputs (Vcc, Rx, Tx, Gnd, T2I, R2O, R2I, T2O). I connected the Vcc, Rx, Tx and Gnd to the Arduino Lenoard (Tx, Rx Pins 0&1) and used the code from the post above send the data to the Serial Monitor. Result: nothing, except that the MAX3232 on the converter board is getting really hot. I also exchanged the Rx, Tx cables but same result.
It is getting hot with and without the balance connected - seams as if there is something wrong with the TTL board. I tried to read out something different but I could not find a device that has the same RS232 port for the connection.
darkwaiter:
It is getting hot with and without the balance connected - seams as if there is something wrong with the TTL board.
That's the way I'm leaning. But I'm otherwise out of ideas.
I suggest asking here... General Electronics ...if a warm MAX2323 is normal. If you do decide to post a question in General Electronics please mention and include a link to this thread.
I am trying to control a powder filler while reading the serial output from a metler balance. I am having trouble reading the balance output on the arduio leonardo via a max3232 converter, but am able to read it fine on my computer in putty (similar to hyper terminal).
Were you able to get things working? any help would be appreciated.
and I don't really understand what they did, but I have gone through the checks the user is talking about and all have passed as his did except the balance connection.
Anyway someone could explain like I am five whats going on in that thread