Pages: [1]   Go Down
Author Topic: problems with serial comunication  (Read 869 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8913
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First mistake I noticed:
Code:
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:
  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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.



 
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8913
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Your code says:
Code:
  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)".
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 =.

« Last Edit: March 30, 2013, 04:21:03 pm by bramsky » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still not solved

the new code after some changes http://pastebin.com/RqeMLGA2
« Last Edit: March 30, 2013, 05:06:01 pm by bramsky » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8913
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Still not solved

You still have not fixed the "if(Serial.available() == 1)" mistake.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: March 30, 2013, 07:07:56 pm by bramsky » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8913
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: