0

Objective: interface and Arduino MEGA to a Mettler Toledo SB32001 using the RS-232 communication protocol described in the manual.

Equipment Used:

Background:

I am using the SoftwareSerial library to try to communicate with the scale through MEGA pins 52 and 53. I have the level shifter connected to the scale using a through cable.

So far, I have tried to send the most basic command to the scale, and the command is both not executing, and not causing a status code to be send back (i.e. failure OR success). My Tx light on the level shifter flashes, but the Rx light never does.

Write string to screen:

D "String"

Because I have a through cable, I have tried switching the Tx and Rx pins in code. Neither has worked.

The from the scale has the following options I can set:

  • Baud Rate: 150, 300, 600, 1200, 2400, 4800, 9600
  • Parity: 7b-E, 7b-no, 8b-no, 7b-odd

Here is a minimal (non)working example of my code:

#include <SoftwareSerial.h>

const int pinTX = 53;
const int pinRX = 52;

scale = SoftwareSerial(53, 52);

void setup(){
    Serial.begin(9600);
    scale.begin(9600);
    delay(100);
}

void loop(){
    scale.println("D \"Hello!?\"");
    delay(100);

    while (scale.available()){
        Serial.print(scale.read());
    }
    Serial.println()
    delay(100);
}

What I need:

I need help figuring out where I should look next to solve this issue. I have tried switching the transmit and receive pins in software. I have tried using jumpers to switch the Tx and Rx pins in hardware. I have tried 7 and 8-bit settings with no parity. Nothing give me a signal back. Totally perplexed?

Is it my converter chip? Does anyone know of problems with this shifter? I know that it does not contain the industry standard MAX232

  • "I have tried switching the Tx and Rx pins in code" The drivers are unidirectional. – Ignacio Vazquez-Abrams Jul 28 '16 at 19:02
  • 1
    Did you remember to send the CRLF? – Ignacio Vazquez-Abrams Jul 28 '16 at 19:03
  • 4
    Why do people insist on trying to use SoftwareSerial on a Mega when the Mega has multiple hardware UART ports?!?! Unless you are wiring lots and lots of UART based things to your Mega there is absolutely no reason to ever use SoftwareSerial! – Majenko Jul 28 '16 at 22:42
  • 1
    Have you tried to connect your computer directly to the Scale serial port and use a terminal (putty for example) to send and received data to the scale? – Talk2 Jul 29 '16 at 1:11
  • 2
    Indeed, trying to make this work from an embedded system when you haven't first verified your understanding of its requirement by far simpler experiments from a PC is just wasting time. – Chris Stratton Jul 29 '16 at 4:38
2

The solution turned out to be a couple of things, some of which mentioned by others in the comments.

Problems that needed to be fixed:

  1. My level-shifter was a huge part of the problem. I switched to a MAX232-based chip and then I was a least able to get responses shorted lines 2 and 3 (Tx and Rx).

  2. I needed a cross-over cable. I had tried this while troubleshooting, but because that alone didn't fix the problem, I had not idea whether or not that was the problem, or just one of the problems.

  3. I needed to use the onboard UART (Serial1) rather than SoftwareSerial. The problem was that I needed to be able to set the protocol to 8 bits with no parity. This configuration parameter cannot be changed on SoftwareSerial, but is as simple as Serial1.begin(9600, SERIAL_8N2).

Thank you for the help, and hopefully my mistakes make the process easier for others.

  • 1
    Thats 8 bits, no parity and 2 stop bits. The last property is what distinguishes your mode from the usual one, 8N1. – TisteAndii Jul 29 '16 at 21:39
  • Did my comment get deleted (strange)? I had said that the SERIAL_8N2 configuration is straight from a code example I was using, and that I just went with it because I knew I needed 8-bits and it worked. The manual doesn't specify (or mention) stop bits, but it seemed to work. I get a lot of invalid command codes back from the scale (~70%), so I may try the SERIAL_8N1 configuration to see if that improves the response. Then again, my 'cross-over' cable is a bunch of breadboard jumpers jammed onto the pins to swtich Tx and Rx, so that faulty, unreliable connection could be the problem too. – Michael Molter Jul 30 '16 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.