Go Down

Topic: Wire + Serial + Rotary Encoder crashes serial communication (Read 866 times) previous topic - next topic

Fergo

Hey everyone,

I have a board with 3 PCF8574 for expanding Arduino ports, which I access through Wire protocol. I also have a rotary encoder connected to pins 2 and 4 (not the expanded ones). The project is working fine, but when I move the rotary encoder, some time after, my Serial connection simply crashes. I have to close the Serial Monitor and open it again for it to work. The weird part is that if I don't use the Wire interface or don't use the rotary encoder, everything works fine. When both are working together, it also works, but after 5 seconds messing with the rotary encoder, the serial connection crashes.

Anyone has an idea on what is going on? The source code is quite large, that's why I didn't posted it, but if you want, I'll be happy to provide.

Regards,
Fergo.

PaulS

Quote
my Serial connection simply crashes.

This is highly unlikely. "My Arduino crashes, ending serial communications" is much more likely.

Quote
but if you want, I'll be happy to provide.

You only need to do that if you want help solving the problem.



Hey everyone,

I have a board with 3 PCF8574 for expanding Arduino ports, which I access through Wire protocol. I also have a rotary encoder connected to pins 2 and 4 (not the expanded ones). The project is working fine, but when I move the rotary encoder, some time after, my Serial connection simply crashes. I have to close the Serial Monitor and open it again for it to work. The weird part is that if I don't use the Wire interface or don't use the rotary encoder, everything works fine. When both are working together, it also works, but after 5 seconds messing with the rotary encoder, the serial connection crashes.

What is the last thing that gets printed? Ohhh wait, we need to see the code for that information to make sense. Then... I don't know. When you close and open the serial monitor, you reset the Arduino... so it starts fresh.
How did you implement the encoder readings?


Anyone has an idea on what is going on? The source code is quite large, that's why I didn't posted it, but if you want, I'll be happy to provide.

Regards,
Fergo.


Two people might have already found the problem if you posted the code...
Eu não sou o teu criado. Se respondo no fórum é para ajudar todos mediante a minha disponibilidade e disposição. Responder por mensagem pessoal iria contra o propósito do fórum e por isso evito-o.
Se realmente pretendes que eu te ajude por mensagem pessoal, então podemos chegar a um acordo e contrato onde me pagas pela ajuda que eu fornecer e poderás então definir os termos de confidencialidade do meu serviço. De forma contrária toda e qualquer ajuda que eu der tem de ser visível a todos os participantes do fórum (será boa ideia, veres o significado da palavra fórum).
Nota também que eu não me responsabilizo por parvoíces escritas neste espaço pelo que se vais seguir algo dito por mim, entende que o farás por tua conta e risco.

Dito isto, mensagens pessoais só se forem pessoais, ou seja, se já interagimos de alguma forma no passado ou se me pretendes convidar para uma churrascada com cerveja (paga por ti, obviamente).

rich9000

Same problem here is code. Its from the examples page here http://arduino.cc/playground/Main/RotaryEncoders

#define encoder0PinA  2
#define encoder0PinB  7

volatile unsigned int encoder0Pos = 0;

void setup() {


  pinMode(encoder0PinA, INPUT);
  digitalWrite(encoder0PinA, HIGH);       // turn on pullup resistor
  pinMode(encoder0PinB, INPUT);
  digitalWrite(encoder0PinB, HIGH);       // turn on pullup resistor

  attachInterrupt(0, doEncoder, CHANGE);  // encoder pin on interrupt 0 - pin 2
  Serial.begin (9600);


}

void loop(){
// do some stuff here
}

void doEncoder() {
  /* If pinA and pinB are both high or both low, it is spinning
   * forward. If they're different, it's going backward.
   */

  if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
    encoder0Pos++;
  } else {
    encoder0Pos--;
  }

  Serial.println (encoder0Pos, DEC);
}

I've also changed the interrupt to RISING and did a if digitalRead(encoder0PinB) == HIGH with the same results.

It goes good for a little bit, 5-20 seconds then freezes.

If sorry if I am not supposed to resurrect this old thread.









PaulS

Quote
void doEncoder() {
 /* If pinA and pinB are both high or both low, it is spinning
  * forward. If they're different, it's going backward.
  */

 if (digitalRead(encoder0PinA) == digitalRead(encoder0PinB)) {
   encoder0Pos++;
 } else {
   encoder0Pos--;
 }

 Serial.println (encoder0Pos, DEC);
}

Really not a good idea in an interrupt handler...

rich9000

Yep

I put the print in the main loop and all is good.

Thanks

Go Up