The Project: To indicate whether a weight on the scale is over or under 8 Oz.
The basic plan is to hook up a scale to an Arduino uno and use an LED to indicate if it is above or below the ideal weight.
My current setup is a Tor Rey L-Pc 40L scale (TORREY L-PC SERIES USER MANUAL Pdf Download | ManualsLib) which has an RS-232 port. I have connected the RS232 port to a MAX 232 Converter.
I have taken the rx line and connected to pin0 on aruduino uno and the V+ is connected to 3.3 and gnd to gnd.
Sorry, but Arduino UNO has pins 0 and 1 already taken by the USB connection to your PC. You cannot use those pins for more than what they are designed for.
Look into using software serial for your scale communications.
Paul
Use the Tx line of the RS232 and feed it to the Rx pin on the controller.
The "ear" of the RS232 doesn't talk....
To be sure, post a drawing. Use code tags, not artworks, when posting code in the future.
Take a deeper look how mySerial.read works, what it delivers. The output You show looks like a type mismatch.
Screenshot images of code are not the optimal way to post code. Read the forum guidelines. Post your code in code tags. Use the IDE autoformat tool (ctrl-t or Tools, Auto Format) to indent the code for readability before posting code.
Thanks paul!
I tried putting the Tx line into pin 10 on the arduino and changed my code to say " SoftwareSerial mySerial(10,11)". I got a similar response in my serial terminal. Is that what you meant for software serial? Thanks
First you need to read the data into a variable. Easiest would be to read into a string and then use atof()* to convert the string into a number that you can use in calculations. The serial input basics tutorial that I linked will help with reading the string. I will work on an example for you.
edit: Corrected atoi to atof to return a float instead of an int.
Code to read the scale and return a number (float data type) that can be used for calculations using methods from the serial input basics tutorial and software serial. Untested.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,-1); // -1 if not using TX to save a pin
const byte numChars = 16;
char receivedChars[numChars]; // an array to store the received data
boolean newData = false;
float number = 0;
void setup()
{
Serial.begin(115200);
Serial.println("<Arduino is ready>");
mySerial.begin(9600);
}
void loop()
{
recvWithEndMarker();
if (newData)
{
showNewData();
number = atof(receivedChars);
Serial.print("the number is = ");
Serial.println(number);
newData = false;
}
}
void recvWithEndMarker()
{
static byte ndx = 0;
char endMarker = '\r'; // 0x0d carriage return
char rc;
while (mySerial.available() > 0 && newData == false)
{
rc = mySerial.read();
if (rc != endMarker)
{
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars)
{
ndx = numChars - 1;
}
}
else
{
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData()
{
Serial.print("This just in ... ");
Serial.println(receivedChars);
}