Why ignore? Why shouldn't I be able to give my own opinion about it? That's my point of view, if you think it should be related, you are free to explain it and I will listen to you and do everything to check it. I took every advice serious until now and thought about it, what do you expect? Sorry if u have the feeling of me ignoring your advices but if I'm sure that it's not related, because I tested it why shouldn't I write it?
About the I²C and why I think it's not the problem: I know it may not be a good solution and MAY damage the boards pins, but if I cut the connection between the arduinos (Due still runs then) I have the same problems. If I would've problems with my I²C connection I would never ask here for help, because I would test level shifters first, but that's not my concern.
Additional fact: When I'm in this hanging or bugging state and I just touch the USB Port of the Arduino with a USB cable or probably any grounded cable the Arduino starts working again.
EDIT: Yes, connecting the USB port of the Due to ground solves the problem. I actually don't know why but that's fact. A wire from my power supply's ground to the usb port should do the trick. Thanks everybody, even if I may have made some ppl grumpy, sry for that ^^
Code, here you go, all variables used in the interrupts are volatile:
For detection which way the encoder was turned (Once had a more compact code, but didn't work all the time, this one works):
attachInterrupt(encoder0PinA, updateEncoder, CHANGE);
attachInterrupt(encoder0PinB, updateEncoder, CHANGE);
void updateEncoder() {
switch (pos) {
case 0:
if (!(digitalRead(encoder0PinA) == state1Vorher && digitalRead(encoder0PinB) == state2Vorher)) {
if (digitalRead(encoder0PinA) == LOW && digitalRead(encoder0PinB) == HIGH) {
pos = 1;
state1Vorher = digitalRead(encoder0PinA);
state2Vorher = digitalRead(encoder0PinB);
} else if (digitalRead(encoder0PinA) == HIGH && digitalRead(encoder0PinB) == LOW) {
pos = -1;
state1Vorher = digitalRead(encoder0PinA);
state2Vorher = digitalRead(encoder0PinB);
}
}
break;
case 1:
if (!(digitalRead(encoder0PinA) == state1Vorher && digitalRead(encoder0PinB) == state2Vorher)) {
if (digitalRead(encoder0PinA) == LOW && digitalRead(encoder0PinB) == LOW) {
pos = 2;
state1Vorher = digitalRead(encoder0PinA);
state2Vorher = digitalRead(encoder0PinB);
}
}
break;
case 2:
if (!(digitalRead(encoder0PinA) == state1Vorher && digitalRead(encoder0PinB) == state2Vorher)) {
if (digitalRead(encoder0PinA) == HIGH && digitalRead(encoder0PinB) == LOW) {
pos = 3;
state1Vorher = digitalRead(encoder0PinA);
state2Vorher = digitalRead(encoder0PinB);
}
}
break;
case 3:
if (!(digitalRead(encoder0PinA) == state1Vorher && digitalRead(encoder0PinB) == state2Vorher)) {
if (digitalRead(encoder0PinA) == HIGH && digitalRead(encoder0PinB) == HIGH) {
pos = 0;
state1Vorher = digitalRead(encoder0PinA);
state2Vorher = digitalRead(encoder0PinB);
tempsoll++;
}
}
break;
case -1:
if (!(digitalRead(encoder0PinA) == state1Vorher && digitalRead(encoder0PinB) == state2Vorher)) {
if (digitalRead(encoder0PinA) == LOW && digitalRead(encoder0PinB) == LOW) {
pos = -2;
state1Vorher = digitalRead(encoder0PinA);
state2Vorher = digitalRead(encoder0PinB);
}
}
break;
case -2:
if (!(digitalRead(encoder0PinA) == state1Vorher && digitalRead(encoder0PinB) == state2Vorher)) {
if (digitalRead(encoder0PinA) == LOW && digitalRead(encoder0PinB) == HIGH) {
pos = -3;
state1Vorher = digitalRead(encoder0PinA);
state2Vorher = digitalRead(encoder0PinB);
}
}
break;
case -3:
if (!(digitalRead(encoder0PinA) == state1Vorher && digitalRead(encoder0PinB) == state2Vorher)) {
if (digitalRead(encoder0PinA) == HIGH && digitalRead(encoder0PinB) == HIGH) {
pos = 0;
state1Vorher = digitalRead(encoder0PinA);
state2Vorher = digitalRead(encoder0PinB);
tempsoll--;
}
}
break;
}
}
}
And for the Encoder Switch:
attachInterrupt(encoderSwitchPin, encoderSwitch, FALLING);
void encoderSwitch() {
if (encSwitchCounter.done() && startCounter > 3000) {
encSwitchCounter.reset();
aktiv = !aktiv; //That's the switch between the monitoring and the set state I mentioned
aktivchecked = false;
checkfailure(); //Recheck if temp is out of tolerance
istre(); //Redraw the temperature to screen
}
}