RS323 to TTL Converter + Photon

Hi, I’m working on retrieving data from a load cell which has an RS232 output currently I am sending it to a converter with a max3232 chipset link to board. I have the load cell in a slave configuration and am sending ASCII commands from the Photon at (9600 baud). ‘R’ is read. I am sending a read command every 2 sec and am getting no response from the load cell. I am left thinking that the issue is either with the converter or my code.

#include "Particle.h"

// Constants
const unsigned long SEND_INTERVAL_MS = 4000;
const size_t READ_BUF_SIZE = 8;

// Forward declarations
void processBuffer();

// Global variables
int counter = 0;
char printSignal = 'P';
char readSignal = 'R';
char tareSignal = 'T';
char zeroSignal = 'Z';
char grossSignal = 'G';
char signals [] = {printSignal, readSignal, tareSignal, zeroSignal, grossSignal};
	String tempMessage = "trash data";
unsigned long lastSend = 0;

char readBuf[READ_BUF_SIZE];
size_t readBufOffset = 0;

void setup() {

	USBSerial1.begin();
	Serial1.begin(9600);
}

void loop() {
	if (counter > 5) { counter = 0;}
	if (millis() - lastSend >= SEND_INTERVAL_MS) {
		lastSend = millis();
		Serial1.printlnf("%d", signals[1]);
		/*USBSerial1.printlnf("Sent to Arduiuno: %d", signals[1]);*/
		/*USBSerial1.printlnf("bytes available: %d", 	Serial1.availableForWrite());*/
		counter++;
		/*Particle.publish("googleDocs", "{\"my-name\":\"" + tempMessage + "\"}", 60, PRIVATE);*/
	}

	// Read data from serial
	while(Serial1.available()) {
		USBSerial1.println("Serial1 Detected!");
		if (readBufOffset < READ_BUF_SIZE) {
			char c = Serial1.read();
			if (c != '\n') {
				// Add character to buffer

				readBuf[readBufOffset++] = c;
			}
			else {
				// End of line character found, process line
				readBuf[readBufOffset] = 0;
				processBuffer();
				readBufOffset = 0;
			}
		}
		else {
			USBSerial1.println("readBuf overflow, emptying buffer");
			readBufOffset = 0;
		}
	}

}

void processBuffer() {
	USBSerial1.printlnf("Received from Arduino: %s", readBuf);
}


void serialEvent()
{
  char c = Serial1.read();
	USBSerial1.print("serialEvent: ");
  USBSerial1.println(c);
}

The original code I am working from is arduino+photon code laid out here

Are you supposed to send 52\r\n?
Since that is what Serial1.printlnf("%d", signals[1]) would do.
Maybe try Serial1.write(signals[1]) instead.

No, luck with Serial1.write(signals[1])

I’ve attached basically all the info which came with the load cell on the format of the ASCII commands it is supposed to be able to receive.

Have you got a type or datasheet of the load cell?

You may also check the RS232-TTL module first via a TX-RX-loopback to see if you can actually send and receive date correctly before getting to the load cell.

Can you be more specific about the > TX-RX-loopback? I would like to verify that it is working properly.

The load cell is an Optima OP-310 which is being sent to an Optima OP-900A SL indicator which has the RS232 output. I have not had much luck finding documentation online. Pretty much the only manual I have is the cryptic one they sent with the kit.

The other piece of information is that I currently have the Optima indicator in command request mode which is in a slave configuration with the Photon. There is another option to have the indicator send out a continuous stream of data to the photon (I assume in master configuration). I have not had luck with either.

Hi @samsonthebrave

First off that board appears to require a 5V supply so I hope your have it hooked up that way.

Then I would remove the connection to scale and just short together pins 2 and 3 on the DB9 RS-232 connector on the board and try sending ASCII strings from your code and see if you get them back. If you can do that, you should be able to talk to the scale.

great suggestions

That's what I meant with the TX-RX-loopback.
Your Photon is Serial1.print()ing out via TX which will loop back via the bridge to its own RX pin to be Serial1.read().

1 Like

@bko @ScruffR after shorting TX-RX on the DB9 connector I was able to get the signal I sent from the photon (glad to know that the converter is working!) looks like it’s something on the indicator end.

1 Like

Hi @samsonthebrave

OK, so that is good news.

I would see if there is any doc for the scale around the other RS-232 signals like CTS and DTR. You may have to tie some of these off in order to convince the thing it is OK to send data.

Do CTS and DTR always correspond with specific DB9 pins? I ask because the indicator only has GND, RX, and TX (aka pins 2,3,5) coming out.

Let me answer my own question. The transmission can be controlled through software flow control, but only to pause and resume the transmission.

Have you set command mode C18 to 3 and baudrate C19 to 3 (9600) too?
Have you tried to communicate with the scales on a PC RS232 port?

The manual doesn’t state anything about how the commands need to look. Whether they need a <CR><LF> or similar thing to terminate the command or not.

I just emailed the supplier and the response I got was:

You have to set your computer side to 8 data bits 1 stop bit no parity no handshake. 9600 baud.

in this case, what does a stop bit need to look like in terms of char? This seems to be the only piece I haven't explicitly tried.

I have not tried it with a PC RS232 port. I have made sure that C18 and C19 are set to 3.

The stop bit is part of the protocol and is not part of a char.
It’s just a predefined logical level for a predefined time after the last data/parity bit and these settings are the default on Particle devices anyway.

Hi, I made a similar solution for a customer and it work fine. I used a RS232 to TTL coverter but before I tested the communication protocol using putty in mi computer and publish the data in the particle console and made a second test for the comunication from my PC to the load cell.

The converter I used is this http://www.evoltapc.cl/catalog/product_info.php/products_id/1172.