Go Down

Topic: problems with serial comunication (Read 933 times) previous topic - next topic

bramsky

I am "plagued" by a strange behaviour of my arduino:

the problem consist of the arduino resetting itself after exectuing the if serial availible ==1 (see code). I alredy removed the reset trace so i guess it is software. Maybay firmware, My code orked on an arduino uno r1. But for some reason it wont on my new r3.

http://pastebin.com/rqTAf33Z --> the code

any help/suggestions ?

johnwasser

First mistake I noticed:
Code: [Select]

int numers[]= {0,0,0,0}; // remembering last 4 numbers

  convert(numers[1],1);
  convert(numers[2],2);
  convert(numers[3],3);
  convert(numers[4],4);


Arrays start at index 0.  That means numers[4] is off the end of your array.

Change that to:
Code: [Select]

  convert(numers[0],1);
  convert(numers[1],2);
  convert(numers[2],3);
  convert(numers[3],4);


Also look for similar errors elsewhere in the code.  If you make a mistake once it is not unusual to make the same mistake again.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

bramsky

Yeah, indeed a stupid mistake i made. i knew that they where 0 based but didn't noticed that i typed them wrong, It was the only place it was wrong i checked it

I corrected the mistake but still the same.



 

johnwasser

Change "boolean debug = true;" to "const boolean debug = true;" to find two more mistakes.

Your code says:
Code: [Select]

  if(Serial.available() == 1) {
    Byte = Serial.read();
  }


Since you are looking for a count of exactly 1 you will stop processing input if more than one character has arrived.  You probably should use "if(Serial.available())" (meaning "if(Serial.available() != 0)") or "if(Serial.available() > 0)" or "if(Serial.available() >= 1)".
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

bramsky

#4
Mar 30, 2013, 10:15 pm Last Edit: Mar 30, 2013, 10:21 pm by bramsky Reason: 1
that serial.avalable is intentionaly with one the idea is that the bytes are processed one byte at a time. thing is it only stops processing at that time. But because it is in the main loop it will always be run then the buffer is freed and the coresponding if is ran

That boolean change to constant is not constructive : ofcourse it gives me errors const = constant so not able to changethe value and thats exactly what i want to be able to do.

edit: Got the hint == instaid of =.


bramsky

#5
Mar 30, 2013, 10:50 pm Last Edit: Mar 30, 2013, 11:06 pm by bramsky Reason: 1
Still not solved

the new code after some changes http://pastebin.com/RqeMLGA2

johnwasser


Still not solved


You still have not fixed the "if(Serial.available() == 1)" mistake.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

bramsky

#7
Mar 31, 2013, 12:59 am Last Edit: Mar 31, 2013, 01:07 am by bramsky Reason: 1
i did chek last version of code  http://pastebin.com/GqRZ5m4V (pasted the wrong version)

I can tell you that thisis not the problem i have a piece of code that uses the exact same statement ( the one with ==1) at that one works perfect on the same arduino.

edit: removed typos

johnwasser


I can tell you that this is not the problem i have a piece of code that uses the exact same statement ( the one with ==1) at that one works perfect on the same arduino.


I'd be interested in seeing the working code.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

bramsky

here is the working code it is one i wrote myself. it is not fully finished but the serial com is. Some ascii art is included :-p

http://pastebin.com/NwL2ixpk

Go Up