Go Down

Topic: ERROR (Read 316 times) previous topic - next topic

latee

I am not too knowledgeable about string...i want to recieve data,sending by the pc,and if the start of the data is d it will store to char num,????plz help me!!1
Code: [Select]
while (Serial1.available()>0){
      d=Serial1.read();
      if (d=='a'){String.toCharArray(num, 11);}
     

PaulS

What, exactly, are you trying to get into num? You've read ONE character from the serial port. You do not have a String instance. Even if you didn't, you haven't populated it with data from the serial port.

Nick Gammon

How to use this forum


* Post all your code please.
* Make a meaningful subject description (not just "ERROR").
* Don't use all caps in the subject.
* If you got an error, what is it?

pYro_65

Did you see the posts in your last thread: http://arduino.cc/forum/index.php/topic,150807.0.html

Quote
if the start of the data is d


there is only 1 character, and yes it is d but you check weather it is 'a'

String.toCharArray(num, 11);

String is not a variable, this line is not valid.

latee

i am wrong to my question...i am trying to store data from pc to arduino store it in a num...if the start is 'a ' the following number will be store to num...
Code: [Select]
while (Serial1.available()>0){
      d=Serial1.read();
      if (d=='a'){String.toCharArray(num, 11);}
     

pYro_65

String.toCharArray(num, 11);

That is wrong, stop using it, delete it.

'd' has only read one character, which 'following number' do you expect to store in num.

You are looping as long as there is data:

Code: [Select]
Serial1.available() > 0

But you do not do anything with it unless it is 'a'

and there is no end '}' on your loop.

latee

wat must be my code????

Go Up