Batch weighing system

Hi,

I am attempting to build myself a batch weighing system which uses an RS-232 shield and servo shield

OK, is there a question?

Hi,

I am attempting to build myself a batch weighing system which uses a servo motor controlled though an H-shield and RS-232 shield to communicate with my digital scale. I have been able to communicate with the scale, receiving and printing to screen the weight on the scale (in an ASCII word). I now want to go to the next step and be able to store that weight to use it as my set-point for identical batches. I don’t really have anything structured at this point, just bits and pieces of code I have been playing with from other examples. I am only a newby to this level of programming, so your advise will be invaluable.

Thanks in advance.

Still don't see a question. See the "how to use the forum" stickies for information on how to ask an effective question. It is hard to give advice when we don't know what, specifically, that you are having trouble with. A basic C++ tutorial might help you get going.

My question is within my post. I want to know the best way to store a weight from the scale to the arduino to use it as a set-point for further batches.

uuum…read the serial data and store that into a variable.

Not sure if I follow you but I think of it like this:

initialize variable for weight

Connect to scale

Send command to get weight from scale

wait for reply

store the weight into the above variable

…do something else next…

Thanks for being patient with me guys... How do you declare a serial variable??

I will be manually sending the serial value from my scale once my target is reached.

A "serial variable" doesn't sound like what aslak said.

Serial data is a series of characters. '1', '2', '.', '3' might be used to represent 12.3 grams. To store that in a variable, you would normally parse the characters to convert to a number. Is that what you are having problems with?

Can you share your code that talks to the scale? Remember to use code tags, like the "how to use this forum" post explains.

MorganS:
A "serial variable" doesn't sound like what aslak said.

Serial data is a series of characters. '1', '2', '.', '3' might be used to represent 12.3 grams. To store that in a variable, you would normally parse the characters to convert to a number. Is that what you are having problems with?

Can you share your code that talks to the scale? Remember to use code tags, like the "how to use this forum" post explains.

Hi Morgan,

Thanks for the reply. My scale does output a word of data in ASCII representing the target weight, but that is where I have come to a screeching halt. I have been doing some research, but due to my lack of experience have not put very much into code. That's where hopefully you guys can assist me. I will try and post the code that writes the target weight to the PC.

Thanks.

Hi Morgan,

Following is the code that talks to the scale, so that when I press a button on the scale it sends the weight currently on the scale to the PC.

int  scaleValue;

void setup() {
  
  Serial.begin(19200);

}

void loop() {
  
 if (Serial.available() > 0) {
   
  scaleValue = Serial.read();

  Serial.print(scaleValue);

  delay(5);

 }
}

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How do you have the scale and the arduino and PC connected together?
All I see is ONE serial I/O setup.
What do you see on the monitor?

What model arduino are you using?

Tom.... :slight_smile:

TomGeorge:
Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How do you have the scale and the arduino and PC connected together?
All I see is ONE serial I/O setup.
What do you see on the monitor?

What model arduino are you using?

Tom… :slight_smile:

Hi Tom,

The scale is connected to my freetronic eleven (uno compatible) board via an RS-232 shield (DFrobot) and an H-shield (freetronic shield) for the control of a servo motor. I am only in the early stages of the project, but wanted to get the serial interface sorted out first. When I have a weight on my scale and press the scale print button, it sends the weight to the monitor screen in ascii code. When I translate the ascii code, it is the weight shown on the scale display.

I hope this helps, Thanks Rob.

Hi,
The RS232 shield TX/Rx pair is connected to the 328 controller Tx/Rx pair which is also connected to the USB interface Tx/Rx pair.

Can you show how three ports can all share the same RS232 pair?
Usually its Tx to Rx, Rx to Tx, but you have an extra pair!!!

Can you load this blank code and tell me what comes up on the monitor when you press the button?

void setup() {


}

void loop() {
 
}

RS232Shield.jpg

Also why do you need a H-bridge for a servo?
Thanks… Tom… :slight_smile:

TomGeorge:
Hi,
The RS232 shield TX/Rx pair is connected to the 328 controller Tx/Rx pair which is also connected to the USB interface Tx/Rx pair.

Can you show how three ports can all share the same RS232 pair?
Usually its Tx to Rx, Rx to Tx, but you have an extra pair!!!

Can you load this blank code and tell me what comes up on the monitor when you press the button?

void setup() {

}

void loop() {

}



![RS232Shield.jpg|637x438](upload://u6Q7NXO5YpJJZLCgq38lXRbBmqb.jpeg)
Thanks.. Tom... :)

Hi Tom,

When that blank code is loaded, nothing appears on the monitor when the scale button is pressed.

Hi,
Okay no problem, just confused about how RS232 ports are connected in your setup.
Why do you need a H-bridge to control a servo?

Tom.... :slight_smile:

TomGeorge:
Hi,
Okay no problem, just confused about how RS232 ports are connected in your setup.
Why do you need a H-bridge to control a servo?

Tom.... :slight_smile:

I was using the H-bridge to control the servo motor which in theory (in my head) will dispense the powder on to the scale to the preset weight. I also had the H-bridge sitting around from another project.

I found the below code in the “serial input basics tutorial” and with some tweaking could be the basis for the serial side of my project. When running the code, my serial input from the scale can be seen on the serial monitor, but does that mean that the data is also retained in the Arduino memory and if so, can it be confirmed?? Or does the code not send the data to memory??

Thanks in advance.

const byte numChars = 16;
char receivedChars[numChars]; // an array to store the received data

boolean newData = false;

void setup() {
 Serial.begin(19200);
 Serial.println("<Scale is ready>");
}

void loop() {
 recvWithEndMarker();
 showNewData();
}

void recvWithEndMarker() {
 static byte ndx = 0;
 char endMarker = '\n';
 char rc;
 
 // if (Serial.available() > 0) {
           while (Serial.available() > 0 && newData == false) {
 rc = Serial.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() {
 if (newData == true) {
 Serial.print("Scale Target Value ... ");
 Serial.println(receivedChars);
 newData = false;
 }
}

Aus_sparky:
Thanks for the reply. My scale does output a word of data in ASCII representing the target weight, but that is where I have come to a screeching halt.

What do you mean, a "word" of data? And what is a "target weight"?

Instead of trying to describe the output, show us the output. Use copy-and-paste.

Aus_sparky:
I found the below code in the “serial input basics tutorial” and with some tweaking could be the basis for the serial side of my project. When running the code, my serial input from the scale can be seen on the serial monitor, but does that mean that the data is also retained in the Arduino memory and if so, can it be confirmed?? Or does the code not send the data to memory??

Thanks in advance.

const byte numChars = 16;

char receivedChars[numChars]; // an array to store the received data

boolean newData = false;

void setup() {
Serial.begin(19200);
Serial.println("");
}

void loop() {
recvWithEndMarker();
showNewData();
}

void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = ‘\n’;
char rc;

// if (Serial.available() > 0) {
          while (Serial.available() > 0 && newData == false) {
rc = Serial.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() {
if (newData == true) {
Serial.print("Scale Target Value … ");
Serial.println(receivedChars);
newData = false;
}
}

Yes, this code does store the data in memory, at least until you print it to the screen and reset newData. After that point, the storage area is free for the next block of data to arrive, so it can’t be trusted to hold anything.

So, before printing and after newData is true, you have all the data in that string variable. The next challenge is to find the actual number you want in the string and then to extract that into another variable.

Aus_sparky, roughly where do you live?
I may be able to help you out if we're close enough. Melb SE.

You sound like a bit of 'over the shoulder' guidance will push you along with fundamentals.