Go Down

Topic: how to get weight form Weight Scale and ek 300i (Read 3512 times) previous topic - next topic

l2eserved

Aug 10, 2017, 10:47 am Last Edit: Aug 10, 2017, 11:16 am by l2eserved
Hello, I am use arduino mega 2560 for get weight form Weight Scale by rs232 to ttl
I try all buad rate but Can't read data
i use
rx = 14 > tx rs232 to ttl > and ek 310i
tx = 15 > rx rs232 to ttl > and ek 310i
rs232 vcc > 5V

https://www.manualslib.com/products/AAndd-Ek-300i-3015221.html

this is manual weight scale

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial weightSerial(14, 15);


void setup() {
weightSerial.begin(9600);
Serial.begin(9600);

while (!Serial){
  ;
}
 Serial.print("Wait");
}

void loop() {
 
  if (weightSerial.available()) {
   Serial.println(weightSerial.read());
   delay(2000);
  }
  if (Serial.available()) {
   Serial.println(weightSerial.read());
    delay(2000);
  }

}



MAX3232 RS232 to TTL / Female Serial TTL / serial module / Brush board MAX3232 chip
RS232 to TTL / Female Serial TTL / serial module / Brush board MAX3232 chip line to send Dupont
The products are widely used in radio modification, cell phones Brush, XBOX360 Brush, GPS, vehicle inspection, DVD Brush, hard disk repair, set-top box upgrades.
Can be used to program the microcontroller type:
STC microcontroller
STM32 MCU
NXP microcontroller
Renesas MCU
NEC MCU
Communications chip: Domestic MAX3232
Operating voltage: 3.3V-5.5V
Interface: TX RX VCC GND

Sorry i am bad english. Please forgive my stupidity.









Robin2

Post a link to the datasheet or user manual for the scales.


Don't post pictures of code - they are unreadable and they can't be copied to a text editor. Just copy and paste the code as text and use the code button </>
Code: [Select]
so it looks like this. See How to use the Forum



Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

l2eserved

Sorry brother.

https://www.manualslib.com/products/AAndd-Ek-300i-3015221.html

this is manual weight scale

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial weightSerial(14, 15);


void setup() {
weightSerial.begin(9600);
Serial.begin(9600);

while (!Serial){
  ;
}
 Serial.print("Wait");
}

void loop() {
 
  if (weightSerial.available()) {
   Serial.println(weightSerial.read());
   delay(2000);
  }
  if (Serial.available()) {
   Serial.println(weightSerial.read());
    delay(2000);
  }

}

Robin2

It was a real PITA to get a PDF of that manual.  Anyway ...

It says at the start of Section 9 "Transmission form   Asynchronous, bi-directional, half-duplex" and I am not sure what is the implication of "half-duplex".

If the second example in my Serial Input Basics does not work at 9600 baud then you will need to research what needs to change to deal with half-duplex.

I am assuming 9600 baud is the default as I can't see how you change the baud rate on the scale.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

l2eserved

#4
Aug 11, 2017, 04:35 am Last Edit: Aug 11, 2017, 01:04 pm by l2eserved
Thank you brother.
I was Try the second example.
but no data send to my arduino,I look at rx led on arduino board. LED does not blink .
Is it possible If it is about IC of rs232?
I use Max3232 in now,And will it be possible if I use IC Max232cpe?

Code: [Select]
#include <SoftwareSerial.h>
SoftwareSerial weightSerial(14, 15);
const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
char a;
void setup() {
weightSerial.begin(2400);
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}



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



void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
   
    while (weightSerial.available() > 0 && newData == false) {
        rc = weightSerial.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("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}


void w() {
if (Serial.available()){
   a = Serial.read();
weightSerial.print(a);
Serial.println(a);
}
}


l2eserved

#5
Aug 11, 2017, 04:42 am Last Edit: Aug 11, 2017, 04:47 am by l2eserved
I ask webmaster of weight Scale. Him told me "buad rate is 2400" and pin of rs232c in scale is db9 use pin 2 3 5 And do not need to send data to get weight. Scale will send weight data regularly.
rx = 2
tx = 3
5v = 5

Robin2

Have you tried my second example at 2400 baud?  What happened?

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

l2eserved

#7
Aug 11, 2017, 11:29 am Last Edit: Aug 11, 2017, 01:01 pm by l2eserved
I was try second example at 2400 baud.
and so sorry  rx led on arduino board. LED does not blink .

Whandall

Why do you run SoftwareSerial on HardwareSerial pins?

rx led on arduino board. LED does not blink .
The RX led only blinks for receives on Serial.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

l2eserved

Oh sorry ,Please forgive my stupidity.
Thanks you for teaching me.
I will try in tomorow.
Current time is 09:53pm in thailand.
thanks you again and again

Robin2

I was try second example at 2400 baud.
Please don't post pictures of code as it can't be read and it can't be copied to a text editor.

Just copy and paste code and error messages as text and use the code button </>
Code: [Select]
so your code looks like this and is easy to copy to a text editor. See How to use the Forum

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

l2eserved

#11
Aug 25, 2017, 07:04 pm Last Edit: Aug 25, 2017, 07:12 pm by l2eserved
i try code
Code: [Select]


const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;
char a;
void setup() {
Serial1.begin(2400);
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}



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



void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;
   
    while (Serial1.available() > 0 && newData == false) {
        rc = Serial1.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("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}


}



out put is -1

Robin2

i try code

out put is -1
What is this line supposed to do?
Code: [Select]
w();
I don't think that code will compile?


And when you say "out put is -1" do you mean that it shows "This just in ...  -1"

If not, please post all of the output from the program, including the <Arduino is ready> part.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

l2eserved

#13
Aug 26, 2017, 08:39 am Last Edit: Aug 26, 2017, 08:45 am by l2eserved
w(); is i try serial print  serial of rs232 with out serial available >0
When I post I delete this code but I forgot delete w();
out put have a <Arduino is ready>  not This just in ... I thik output is -1 form w();
Code: [Select]

void w(){
int a;

a = Serial1.read();

Serial.print(a);

delay(1000);

}


and I was try another code form other website but I don't remember where website of this code.
output is 8bit FFFFFFFF

Robin2

#14
Aug 26, 2017, 08:53 am Last Edit: Aug 26, 2017, 08:54 am by Robin2
w(); is i try serial print  serial of rs232 with out serial available >0
The code you posted in Reply #11 did not have the code for your w() function.

If you want my help post the complete program in your next Reply.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up