author

bowlerhatman

31
Inbox View Profile
3Instructables84,945Views26Comments

Tell us about yourself!

Achievements

10K+ Views Earned a bronze medal
  • Easy Arduino Menus for Rotary Encoders

    Thanks so much for the help, and there's no offence taken at all, I agree that my comment should be enough to help anyone who experiences this issue. Thanks again!

    View Instructable »
  • Easy Arduino Menus for Rotary Encoders

    Hi Simon, thanks for your speedy response! I confess, I can't see a discussion of portability in your other 'ible, other than that you mention it? As far as I can see though, 2 and 3 are interrupts on the Leonardo as well. I do see that they occupy the two least significant bits on PORTD, rather than the 3rd and 4th. Can you expand a little on this:...static int pinA = 2; // Our first hardware interrupt pin is digital pin 2static int pinB = 3; // Our second hardware interrupt pin is digital pin 3attachInterrupt(0,PinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below) attachInterrupt(1,PinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Inter…

    see more »

    Hi Simon, thanks for your speedy response! I confess, I can't see a discussion of portability in your other 'ible, other than that you mention it? As far as I can see though, 2 and 3 are interrupts on the Leonardo as well. I do see that they occupy the two least significant bits on PORTD, rather than the 3rd and 4th. Can you expand a little on this:...static int pinA = 2; // Our first hardware interrupt pin is digital pin 2static int pinB = 3; // Our second hardware interrupt pin is digital pin 3attachInterrupt(0,PinA,RISING); // set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below) attachInterrupt(1,PinB,RISING); // set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)reading == B00001100 && aFlag (and the other three instances)...I'm a little confused about why digital pins 2 and 3 are declared for the encoder pins, but then pins 0 and 1 are attached as the interrupt, but then the 3rd and 4th bits on PORTD are polled? My wiring is attached. The Leonardo is represented by that connector, but the pins numbers match up. I have adjusted buttonPin to 1 to suit my connections.I have tried adjusting the PIND section to:reading = PIND & 0x3and shifting the two polled bits down by two, thus:reading == B00000011 && aFlag (and so on)But still have no joy.I've got the encoder, wired as is, running successfully with this library: https://www.pjrc.com/teensy/td_libs_Encoder.htmlSo I'm confident that the wiring is not the issue, but I'm clearly missing something else. Beyond the port assignments, I can't see anything in the code that should vary much from 'duino to 'duino?Thank you for your help,Frazer

    Hi again Simon, thanks! This is helpful I think, and is starting to clear some things up. I changed the interrupt mode to CHANGE, and the isrs to the below code and it's now working as described.___________void PinA(){ cli(); //stop interrupts happening before we read pin values reading = PIND & 0x3; // read all eight pin values then strip away all but pinA and pinB's values if(reading == B00000011 && aFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge encoderPos --; //decrement the encoder's position count bFlag = 0; //reset flags for the next turn aFlag = 0; //reset flags for the next turn } else if (reading == B00000010) bFlag = 1; //signal that we're expecting pinB to signal the transition to det…

    see more »

    Hi again Simon, thanks! This is helpful I think, and is starting to clear some things up. I changed the interrupt mode to CHANGE, and the isrs to the below code and it's now working as described.___________void PinA(){ cli(); //stop interrupts happening before we read pin values reading = PIND & 0x3; // read all eight pin values then strip away all but pinA and pinB's values if(reading == B00000011 && aFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge encoderPos --; //decrement the encoder's position count bFlag = 0; //reset flags for the next turn aFlag = 0; //reset flags for the next turn } else if (reading == B00000010) bFlag = 1; //signal that we're expecting pinB to signal the transition to detent from free rotation sei(); //restart interrupts}//Rotary encoder interrupt service routine for the other encoder pinvoid PinB(){ cli(); //stop interrupts happening before we read pin values reading = PIND & 0x3; //read all eight pin values then strip away all but pinA and pinB's values if (reading == B00000011 && bFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge encoderPos ++; //increment the encoder's position count bFlag = 0; //reset flags for the next turn aFlag = 0; //reset flags for the next turn } else if (reading == B00000010) aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation sei(); //restart interrupts}___________I think one thing that threw me is that the Arduino website give this advice "attachInterrupt(digitalPinToInterrupt(pin), ISR, mode) (recommended)attachInterrupt(interrupt, ISR, mode) (not recommended)attachInterrupt(pin, ISR, mode) (Not recommended. Additionally, this syntax only works on Arduino SAMD Boards, Uno WiFi Rev2, Due, and 101.)"It's not immediately clear from the comments in the code that your syntax is #2 in that list, and for someone rusty like myself, given that the other two options both suggest attaching by pin number rather than int number, it looked like the numbers were off. I see what's happening now, but might I suggest using the recommended syntax for clarity?Those comments aside, it's now working perfectly, thank you for all your help! It's greatly appreciated.Many thanks,Frazer

    View Instructable »
  • Easy Arduino Menus for Rotary Encoders

    Hi there, I'm trying to get your code working, but can't. There are a few things that I can see need improvement, for instance, when you attach the interrupts, the pin numbers you use don't correspond to the encoder pins, and you also use syntax that seems deprecated. I think the recommended syntax is attachInterrupt(digitalPinToInterrupt(pin), ISR, mode).Having fixed that though, the code still doesn't behave as you describe, but I'm having a hard time figuring out why. Firstly, when I start it up, rotating the encoder doesn't scroll through the menu options, I get no serial output. If I press the button, I get:Button closedMode selected: 1Mode 10Button openedRotating the encoder then still doesn't give any output. Combinations of holding the button and rotating, or giving multiple press…

    see more »

    Hi there, I'm trying to get your code working, but can't. There are a few things that I can see need improvement, for instance, when you attach the interrupts, the pin numbers you use don't correspond to the encoder pins, and you also use syntax that seems deprecated. I think the recommended syntax is attachInterrupt(digitalPinToInterrupt(pin), ISR, mode).Having fixed that though, the code still doesn't behave as you describe, but I'm having a hard time figuring out why. Firstly, when I start it up, rotating the encoder doesn't scroll through the menu options, I get no serial output. If I press the button, I get:Button closedMode selected: 1Mode 10Button openedRotating the encoder then still doesn't give any output. Combinations of holding the button and rotating, or giving multiple presses and rotating, seem to yield almost random results. Other than the attach interrupt syntax, and making sure the pin assignments are correct, I haven't changed your code at all. Do you have any advice that could help me get this working? From your description of the function, it does exactly what I need!Thanks,Fraz

    View Instructable »