I am a little lost. I tried using the diode and resistors from runaway_pancake. Still not working. I am not understanding how to use the TTL. It is a simople pinout for the scale. I changed the code around.
#include <SoftwareSerial.h>
SoftwareSerial scaleSerial(8,9); // RX, TX - adjust the pin numbers as needed
String incomingLine = "";
void setup() {
Serial.begin(2400); // Set baud rate for the Serial Monitor
scaleSerial.begin(2400);
Serial.println("Setup complete. Waiting for incoming data...");
}
void loop() {
if (scaleSerial.available()) {
char incomingByte = scaleSerial.read();
if (incomingByte == '\r' || incomingByte == '\n') {
Serial.println("Received End of Line. Processing...");
processCustomFormat();
} else {
incomingLine += incomingByte;
}
}
// Your main code here, without delay
}
void processCustomFormat() {
if (incomingLine.length() >= 15) {
Serial.println("Processing Custom Format...");
String header = incomingLine.substring(0, 2);
String separator = incomingLine.substring(2, 3);
String polaritySign = incomingLine.substring(3, 4);
String weightData = incomingLine.substring(4, 12);
String unitOfMeasure = incomingLine.substring(12, 15);
Serial.println("Hello, Print Part of Program!");
Serial.print("Header: ");
Serial.println(header);
Serial.print("Separator: ");
Serial.println(separator);
Serial.print("Polarity Sign: ");
Serial.println(polaritySign);
Serial.print("Weight Data: ");
Serial.println(weightData);
Serial.print("Unit of Measure: ");
Serial.println(unitOfMeasure);
Serial.println();
} else {
Serial.println("Incomplete or invalid line. Discarding...");
}
// Clear the accumulated line for the next iteration
incomingLine = "";
}
I get the message "Setup complete, waint for incoming data" , so the program is at least reading. Obviously have no incoming data.