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
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.
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.
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().
@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.
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.
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.