Go Down

Topic: Arduino 328 board connected to a balance (Read 6873 times) previous topic - next topic

AWOL

Quote
void loop()
{

 char c = softSerial.read()& 0x7F;
 delay(1000);
 Serial.println(c);

}

The problem with the soft serial libraries is that they can't receive in the background (that's why "available" doesn't work), so putting that delay in doesn't help.
In other words, you can only receive if you're acually calling the "read" method, unlike the hardware receive method which buffers.
Can you take out the delay?
What does your interface circuit look like?
Can you post a link to the spec of the balance?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Labuschagne3

Hi

Thank tou very much for all your help.

Sorry for all the code, I'm new in the forums.

The balance is a Mettler Tolede Pm400 balance that I'm using.

I removed the delay and it made it a bit worse.

Any other ideas?

AWOL

#17
Jul 06, 2009, 09:03 pm Last Edit: Jul 06, 2009, 09:05 pm by AWOL Reason: 1
How is the balance connected to the Arduino?
Do you have level shifters/inverters?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Labuschagne3

I got the balance connected to the following serial board http://sodoityourself.com/max232-serial-level-converter/ then from the serial board to pin 2 and 3 of the arduino board and then from the ardunio board to the Computer with a usb Cable so I can do the uploads to the board.



GrooveFlotilla

Have you tried printing the received characters in hex, to see if there's any consistency or pattern?
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Labuschagne3


GrooveFlotilla

Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Labuschagne3

Hi When I add  Serial.println(c, HEX); i'm getting the following message.

In function 'void setup()':
error: 'c' was not declared in this scope

Labuschagne3

When I put it in the correct place :o) i'm getting the following when reading Serial

!?±±½?º½É±??jR

Labuschagne3

Hi sorry

I'm getting the following now, it is not squares anymore it is 0 now

Hello world!

0

0


GrooveFlotilla

#25
Jul 07, 2009, 11:23 am Last Edit: Jul 07, 2009, 11:25 am by GrooveFlotilla Reason: 1
That's not hex   :(

That looks like a serial line speed mismatch.
Have you got your serial monitor speed set to the same as the speed in the Arduino's "Serial.begin"?
Can you post your current sketch?

[later] OK, I read your revised post with the zeroes in it. That could be hex.  :D
Can you post your sketch anyway?
I'm still a little confused about the serial line handling.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Labuschagne3

Code: [Select]
//  15 April 2009

#include <SoftwareSerial.h>


//rx and tx pins
int rx_pin    =  2;
int tx_pin    =  3;


int startbyte;
int userInput[3];
int byte_1;
int byte_2;
int i;
int smoke_toggle = LOW;
int led_toggle = LOW;
int status = LOW;


SoftwareSerial softSerial =  SoftwareSerial(rx_pin, tx_pin);

void setup()
{
 // for software serial
 pinMode(rx_pin, INPUT);
 pinMode(tx_pin, OUTPUT);

 // set the data rate for the hardware serial port
 Serial.begin(9600);
 // set the data rate for the SoftwareSerial port
 softSerial.begin(9600);
 Serial.println("Hello world!");  

}

void loop()
{
 
 char c = softSerial.read()& 0x7F;
 delay(1000);
 Serial.println(c, HEX);
 
}  

GrooveFlotilla

That "delay" won't help because the soft serial library can receive when in "read".

Are you sure you've got Tx and Rx connected to the correct pins?
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Labuschagne3


GrooveFlotilla

If the read is always returning zeroes, that would seem to suggest that the Rx line is always low.
Some people are like Slinkies.

Not really good for anything, but they bring a smile to your face when pushed down the stairs.

Go Up