hi as you can see in the code i am trying to print a text in the serial monitor which is "b1/2e" but when try another text which is "c1/2e" i notice a space printed before "c" .
void loop() {
NOTE:i will be reseted to 0 every loop
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
if ( Serial.available()!=0)
{
str=Serial.read();
Serial.println(str);
my_data[i]=str;
i++;
if(str=='e')
{
l=1;
}
// Nombre de points
else if(str=='/')
{
coordonnees[i-1]=str;
nbr_slash++;
// Serial.println(nbr_slash);
}
// transformation en decimal
else if(str=='b'){}
else { coordonnees[i-1]=str-'0';}
}
}
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
then i tried to check the return of Serial.available() of each individual character
as you can see here even if nothing is going on serial input still Serial.available() returns 1
actually the Serial.available who is causing the space to appear because the array will be shifted by 1 any help why is this happening?
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
void loop() {
if ( Serial.available() >0 )
{
Serial.print(Serial.available());
str=Serial.read();
Serial.println(str);
my_data[i]=str;
i++;
if(str=='e')
{
l=1;
}
// Nombre de points
else if(str=='/')
{
coordonnees[i-1]=str;
nbr_slash++;
// Serial.println(nbr_slash);
}
// transformation en decimal
else if(str=='b'){}
else { coordonnees[i-1]=str-'0';}
}
}
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Use the edit function to put your code in code tags <|>. Read the post on how to get the most out of this forum which Is the top of every section
Or a space or newline printed after the "e"?
Do you terminate each input by "Enter"?
no i entered the full text at once
it is not a answer for question "Do you terminate your input by "Enter"?"
It works fine for me when I set the Serial Monitor line ending to "No line ending":
b
1
/
2
e
c
1
/
2
e
I had to guess at the variables you didn't declare but it compiles without warnings:
char str;
char my_data[80];
int i = 0;
int nbr_slash = 0;
int l;
int coordonnees[80];
void setup()
{
Serial.begin(115200);
delay(200);
}
void loop()
{
if (Serial.available() != 0)
{
str = Serial.read();
Serial.println(str);
my_data[i] = str;
i++;
if (str == 'e')
{
l = 1;
}
// Nombre de points
else if (str == '/')
{
coordonnees[i - 1] = str;
nbr_slash++;
// Serial.println(nbr_slash);
}
// transformation en decimal
else if (str == 'b')
{
}
else
{
coordonnees[i - 1] = str - '0';
}
}
}
when i write "b1/2e" press enter then write "c1/2e"
Is the extra character on the end of the first entry or the start of the second entry ?
Print ">" before each character and "<" after it and you will be able to tell
What is Line ending set to in the Serial monitor ?
it works i was setting up the line ending on New line i change it to No line ending .thanks
thank you all guys for your help
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.