Timeline for Problem to convert rotary encoder output to angle
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 24, 2018 at 17:34 | comment | added | Bkukuk62 | How could this code be modified to use an indexed encoder to reset the counter to 0 every time it hit the index. I would like to use this to track a rotating mast for direction finding. | |
| Jan 21, 2017 at 20:38 | comment | added | James Waldby - jwpat7 |
Declare a flag, eg volatile byte cchange;, and set it true in the ISR. In loop(), say if (cchange) { cchange=false; printstuff(); } ¶ Re double counts, the ISR shown is slow, which can mess up counting. If your ISR were to catch all the edges and treat them correctly, eg via a state machine like in my answer to question 32572, bouncing would cancel out.
|
|
| Jan 21, 2017 at 17:07 | comment | added | floppy380 | @jwpat7 How can I implement that setting flag and outputting from void? I also experience two outputs at some single encoder ticks. Can that be because of bouncing? | |
| Jan 20, 2017 at 17:29 | comment | added | James Waldby - jwpat7 |
Serial.println() can cause problems when used within an ISR. Set a flag instead, and print from loop()
|
|
| Jan 20, 2017 at 17:13 | answer | added | James Waldby - jwpat7 | timeline score: 1 | |
| Jan 20, 2017 at 16:59 | answer | added | frarugi87 | timeline score: 1 | |
| Jan 20, 2017 at 15:23 | comment | added | Gerben | if it's 30ppr then every count is 12 degrees. So multiply the number by 12. The do a modulo 360 (` x = x % 360`), so you only get values from 0 to 360. But not that you can only know the angle difference from when the sketch first started. So you have to set the disk to the zero position before turning on the Arduino. | |
| Jan 20, 2017 at 14:43 | review | First posts | |||
| Jan 21, 2017 at 3:47 | |||||
| Jan 20, 2017 at 14:39 | history | asked | floppy380 | CC BY-SA 3.0 |