I am using all the components used on this project and the same code but can’t get my system to work. Some advice would be much appreciated.
My current setup in short:
I am using a PCB mounted Mega 2560 to communicate to my FX120-I digital balance. If I connect my PC to my Arduino via the RS232-TTL converter and do serial communication on my command line I can see my Arduino is sending the Q command and my screen updated when I send weight data to the Arduino.
The same goes for my scale and PC via a usb to rs232 converter. If I send the Q command to my scale from the command line my scale send the weight data back to my command line.
However as soon as I connect the scale to the Arduino via the RS232-TTL converter nothing happens. As soon as I force my scale to send data the Arduino can receive it. I force my scale by pushing the print button. Just also just worked on some RS232-TTL converters. I tried MAX3232, MAX232 and MAX 202. The only ones I got to receive data, only if I force my scale is the MAX3232 ones. However, all of them could communicate with my PC.
The code where I query the weight and read the weight:
Funny you should post a link to that youtube vid, because it has a link to the project code repository on GitHub. I did some digging in that GitHub repo and found the sketch he/she was using. In that sketch I found this function, which may be of great use to you:
// method to read a value from the serially attached KERN scale
int readScale(float *returnValue) {
if (debug > 39) Serial.println("read scale");
if (BALANCE_TYPE == 1) {
Serial1.write("w");
Serial1.flush();
delay(300);
if (Serial1.available()) {
// while (!(Serial1.available() > 0)) {};
// if (1) {
bool negative = false;
bool stable = false;
String scaleOutput = Serial1.readStringUntil('\n');
if (debug > 19) Serial.println(scaleOutput);
if ((scaleOutput.indexOf('.') == 8) || scaleOutput.indexOf('.') == 9) { // comma separator at pos 9 indicates good string [ for gn, 8 for g]
if (scaleOutput.indexOf('-') != -1) {
negative = true;
}
if (scaleOutput.indexOf("g") != -1) {
stable = true;
}
String valueString = scaleOutput.substring(2, 12);
valueString.trim();
//Serial.print("Valuestring: ");
//Serial.println(valueString);
float value = valueString.toFloat();
if (negative) value = value * -1;
if (debug > 29) Serial.print("Float: ");
if (debug > 29) Serial.println(value, 3);
*returnValue = value;
if (stable) return 1;
return 0;
} else {
return -1;
}
} else {
if (debug > 39) Serial.println("no data from scale");
return -1;
}
} else { // A&D FX120i
Serial1.write("Q\r\n");
delay(50);
if (Serial1.available()) {
//Serial.println("data available");
bool negative = false;
bool stable = false;
String scaleOutput = Serial1.readStringUntil('\n');
if (debug > 29) {
Serial.print("SCALE OUTPUT:");
Serial.println(scaleOutput);
Serial.println(scaleOutput.indexOf("."));
}
if ((scaleOutput.indexOf(".") == 8) || (scaleOutput.indexOf('.') == 9)) {
if (scaleOutput.indexOf('ST') != -1) {
//Serial.println("stable");
stable = true;
}
if (scaleOutput.indexOf('-') != -1) {
negative = true;
}
String valueString = scaleOutput.substring(4, 12);
if (debug > 39) {
Serial.println(valueString);
}
float value = valueString.toFloat();
if (negative) value = value * -1;
if (debug > 29) Serial.print("Float: ");
if (debug > 29) Serial.println(value, 3);
*returnValue = value;
if (stable) return 1;
return 0;
} else {
return -1;
}
} else {
if (debug > 39) Serial.println("no data from scale");
return -1;
}
}
// wrong scale configuration
return -1;
}
...I've never used RS-232 with the Arduino, but I've "fought" RS-232 a few times so I know a little about it, and I know there are lots of tricky things about it.
If I connect my PC to my Arduino via the RS232-TTL converter and do serial communication on my command line I can see my Arduino is sending the Q command and my screen updated when I send weight data to the Arduino.
The same goes for my scale and PC via a usb to rs232 converter. If I send the Q command to my scale from the command line my scale send the weight data back to my command line.
However as soon as I connect the scale to the Arduino via the RS232-TTL converter nothing happens.
Sorry, I really don't understand what's working and what's not working....
Just also just worked on some RS232-TTL converters. I tried MAX3232, MAX232 and MAX 202. The only ones I got to receive data, only if I force my scale is the MAX3232 ones.
Usually the only tricky thing about the "electronics" is getting the positive & negative voltages (and receiving the positive & negative voltages). The MAX chips have the built-in charge pump DC-DC converters to handle that. Some "RS-232 converters" try to work without the positive & negative voltages... Sometimes they work and sometimes not.
The other tricky hardware thing is getting the DCE/DTE wiring correct and handshaking (if any) correct. i.e. You have to criss-cross the TX & RX connections, and sometimes the handshaking connections. At work, we have a couple of [u]LED RS-232 Testers[/u]. If the LEDs light-up the wrong color we plug-in a [u]Null Modem Adapter[/u] or a null-modem cable, which cris-crosses the connections. (Most of the time these are known-good RS-232 connections and we just need to make sure we've got the right cables/wiring.)
Then there are protocol settings... The baud rate, start bits, stop-bits, and parity all have to be correct. The balance seems to be well documented.
Of course, you have "full control" of your Arduino software (and hardware) but I don't know what you have to do to get all of those settings correct.
Power_Broker:
Funny you should post a link to that youtube vid, because it has a link to the project code repository on GitHub. I did some digging in that GitHub repo and found the sketch he/she was using. In that sketch I found this function, which may be of great use to you:
Broker Power, I am using exactly the same code and setup as the project on GitHub and still get the results explained in my post.
DVDdoug:
Sorry, I really don't understand what's working and what's not working....
Communication between the PC and the Arduino is working, Communication between the scale and the PC is 100%. Communication between the Arduino and Scale is not working.
Robin2:
Isn't this the same project as in your other Thread? And IIRC you had a 3rd Thread on the subject!
Why start a new Thread when there is useful info in your other Thread for people trying to help?
...R
My other two threads did not allow me to add posts in them and that is why I started the new one, but yes it is the same project.
smithchristof:
My other two threads did not allow me to add posts in them and that is why I started the new one, but yes it is the same project.
I think one of your Threads may be locked but the one in my link in Reply #3 is not. You could click Report to Moderator and ask to have this merged with the earlier one.
Power_Broker:
Based off of the code you posted, that is a blatant lie. That is, unless the code you are actually using is different than in your original post.
Post your entire code (the sketch you're actually using) and then maybe we can figure it out.
The entire first section of the code posted by you is for a different balance. The part I posted is the only section where communication with the scale happens. After that it is just manipulation of the data.
1.) Post your full schematic drawn using something like LTspice, Eagle PCB, or (as a last resort) Fritzing.
2.) Also, post your entire code. "But I already posted the relevant code" - no - all code is relevant.
3.) Post a printout of the results of your code (or simply state that nothing popped up in the Serial Monitor)