I am using a sensor RS232 and send to arduino to display.
The problem is, while the sensor is working, it loading data and after stoped, it show the data in my display.
I am want show in real time, but it is not working.
String readStringSerial()
{
int i=0;
String conteudo = "";
char caractere;
while (Serial1.available() >0)
{
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
Serial1.read();
}
caractere = Serial1.read();
Serial.print (caractere);
if (caractere != '\r')
{
conteudo.concat(caractere);
}
if (caractere == '\r')
{
return conteudo;
}
delay(1);
}
}
void setup()
{
now = time(NULL);
pinMode(12, OUTPUT);
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
Serial.begin(9600);
Serial1.begin(1200);
delay(200);
}
void loop()
{
String dataString = "", dataString2 = "";
if (Serial1.available() >0)
{
received = readStringSerial();
if (received[0] == '+')
{
int Hundred = (received[1] - '0') * 100;
int Ten = (received[2] - '0') * 10;
int Unity = (received[3] - '0');
result = Hundred + Ten + Unity;
sample = result;
i++;
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > interval)
{
previousMillis = currentMillis;
if (sample > velomaxd)
{ sprintf(buffer, "%03d", sample);
Serial1.print(String("SetDisplay") + (buffer) + (";\r")); //display
}
if (sample <= velomaxd)
{ sprintf(buffer, "%03d", sample);
Serial1.print(String("SetDisplay") + (buffer) + (";\r")); //display
}
}
sample = 0;
Serial.println("Interno: "+ dataString);
Serial.println(i);
}
}
}
I am reading a doppler sensor RS232.
The object moves and the sensor sends velocity data to TX while the object are moving in front of the sensor.
The problem is:
Arduino not send the data to my display while the sensor is reading ( while the object is aproaching).
I need that, in real time while sensor is reading, send velocity data to Arduino, that receive this data and send to my display.
Try the code in the link I gave you in Reply #2. The second example will probably do most of what you want.
While it is unlikely to be the immediate cause of the problem it is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
Robin2:
Try the code in the link I gave you in Reply #2. The second example will probably do most of what you want.
While it is unlikely to be the immediate cause of the problem it is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
...R
Hey.
I have tested this code.
The result is the same.
It prints after the sensor stops sending data.
When I read the RX of the sensor. Every 0.5 seconds, it send the velocity of object and carry to the next line until the object exit the detection field.
Using the Serial.
When I read the serial using Arduino. While the object is moving, nothing is showed. But when the object exit the detection field, the sensor stops sending data. The Arduino write all data in Serial.
I've simulated using my hand, but let imagine when the object is a car with distance of 5 meters.
While the sensor write in his TX with the instant velocity every 0,5 seconds. The Arduino wait the car pass the sensor to read all instant velocitys.
What exactly is the loop variable ( i ) used for?
What exactly is the readStringSerial() function variable ( i ) used for?
When is variable ( velomaxd ) ever not 0
When is variable ( interval ) ever not 0
When was received[3] ever declared? // edit you used received[3] so when was received[4] declared?
Sorry, but I don't know what your video is trying to show.
The datasheet that you linked to says
Speed data is output serially in mph as three ASCII digits in the following format:
nnn\n\r
where:
nnn : The three digit ASCIII speed digits in mph
\n\r : A new line followed by a carriage return character
The second example in my tutorial should receive that data and print each item as it is received without needing any changes to the program.
As written my example uses the \n as the end-marker and it will treat the \r as the first character of the next message.
As I said earlier, if that is not suitable you will need to explain in detail what you want to happen that is different.
Slumpert:
What exactly is the loop variable ( i ) used for?
What exactly is the readStringSerial() function variable ( i ) used for?
When is variable ( velomaxd ) ever not 0
When is variable ( interval ) ever not 0
When was received[3] ever declared? // edit you used received[3] so when was received[4] declared?
Hey man.
Some variable was created for tests.
Sorry Robin.
In that video. On the left is Arduino Serial Out and on the Right the Serial Out of the sensor.
When a object moves in front of the sensor, the sensor write in its TX every 0,5 seconds the instant velocity of the object.
When I read this sensor of Arduino, Arduino dosen't read and write every 0,5 seconds in Serial. Arduino waits the sensor stops reading then it writes all data in the Serial.
Arduino read all data in Serial1(sensor) and write once in Serial.
Saulo_GPU:
When I read this sensor of Arduino, Arduino dosen't read and write every 0,5 seconds in Serial. Arduino waits the sensor stops reading then it writes all data in the Serial.
Arduino read all data in Serial1(sensor) and write once in Serial.
Post the program that displays the behaviour you have just described and post (as text) an example of the output from that program.
...R
PS. I don't think another video is worthwhile. Apart from anything else the text was too small to read.