element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Project Videos
  • Challenges & Projects
  • element14 presents
  • Project Videos
  • More
  • Cancel
Project Videos
Documents DIY Shapeoko CNC Pendant -- Episode 420
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Project Videos to participate - click to join for free!
Related
Recommended
Engagement
  • Author Author: tariq.ahmad
  • Date Created: 11 Nov 2019 10:04 PM Date Created
  • Last Updated Last Updated: 15 Nov 2019 8:24 AM
  • Views 11198 views
  • Likes 10 likes
  • Comments 81 comments

DIY Shapeoko CNC Pendant -- Episode 420

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

One of the great joys of being able to design with electronics is the ability to make your own custom tools. DJ recently picked up a CNC router and in order to make his life a wee bit easier, he’s designed and built a pendant that will allow him to more comfortably, and accurately set up his parts in the machine. Follow along as he tinkers his way to new gadget that, hopefully, will be of use or inspiration for fellow makers and CNC enthusiasts.

Bill of Material:

Product Name Manufacturer Quantity Buy Kit
Panel Mount Push Button Grayhill 7 Buy Now
5mm LED Multicomp 7 Buy Now
680R Resistor Multicomp Pro 7 Buy Now
3D Filament Verbatim 1 Buy Now
Rotary Encoder Bourns 1 Buy Now

 

Additional Parts:

 

Product Name
Teensy LC
Attachments:
Resources_DIY Shapeoko CNC Pendant.zip
image
DIY Shapeoko CNC Pendant

element14 Presents  |  DJ Harrigan's VCP Profile  |  Project Videos

  • shapeoko
  • carbide 3d
  • digital fabrication
  • fusion 360
  • cnc
  • 3D Printing
  • cad
  • usb hid
  • element14 presents
  • xxl
  • rotary encoder
  • microcontroller
  • multicomp
  • dj
  • cam
  • bourn
  • arduino
  • router
  • dj harrington
  • friday_release
  • woodworking
  • e14presents_djharrigan
  • Share
  • History
  • More
  • Cancel
Actions
  • Share
  • More
  • Cancel
  • Sign in to reply

Top Comments

  • rogo
    rogo over 5 years ago +2
    The project is very nice but a cabling scheme would not be refused!
  • thomasvdd
    thomasvdd over 5 years ago +1
    Awesome project! I'm definitely building this, it solves exactly the annoyance I encounter when milling. Could you share the file for the front plate which includes the text?
  • DAB
    DAB over 5 years ago +1
    Nice build. DAB
Parents
  • thomasvdd
    thomasvdd over 5 years ago

    I have made the project and can confirm that the original code runs just fine.

    The behavior you described is how it is intended to function, as you can see from the code:

     

    When pressing one of the speed buttons, the activespeed variable is being changed.

     

      if (buttonFast.fallingEdge()) {

        activeSpeed = SPD_FAST;

      }

     

    The next time the loop() executes, the if statement triggers and presses a key (KEY_4)

     

    if (activeSpeed != lastSpeed){

        digitalWrite(lastSpeedLED, LOW);

        switch(activeSpeed){

          case SPD_FAST:

            Keyboard.press(KEY_4);

            Keyboard.release(KEY_4);

            digitalWrite(PIN_LED_FAST, HIGH);

            lastSpeedLED = PIN_LED_FAST;

          break;

     

    When pressing one of the X, Y, Z buttons, the activeAxis variable is being changed.

    (uncomment the serial print to verify if your button works)

     

      if (buttonX.fallingEdge()) {

        activeAxis = X_AXIS;

        //Serial.println("X");

      }

     

    HOWEVER, the corresponding button (KEY_RIGHT) is ONLY being pressed when the encoder is turned.
    Pressing the X, Y or Z button only will NOT press any keyboard key.

     

      if (abs(newScrollPos - lastScrollPos) >= 4) { // there are roughly four presses detected from each rotation to the next detent

        if (newScrollPos - lastScrollPos > -1){ // positive increase

          switch(activeAxis){

          case X_AXIS:

            Keyboard.press(KEY_RIGHT);

            Keyboard.release(KEY_RIGHT);

          break;

     

    In conclusion: if your CNC doesn't move, your rotary encoder is probably badly connected.

    Check the connections from encoder to teensy (also the middle ground pin). If that fails, I would buy a new encoder and try again.

     

    Hope this helped

    Thomas

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Hello Thomas, thank you so much for helping me out with this, it's driving me nuts.   I bought 2 encoders, so I'll try changing them out today.  I checked the impedance on the encoder, and it changed as I rotated it, so I assumed it was working.  I used the three sided pins of the encoder, outer pin goes to pin 9 on the controller, the center pin is to ground, and the other outer pin is connected to pin 10 on the controller.   I opened the serial monitor and uncommitted the serial print line and each time I press the X,Y,X buttons it shows on the output of the serial monitor screen.  Should it repeat the X,Y,Z on the screen if I turn the encoder?   I'm still learning how to program, so this is way above my understanding.  Is there any way to see if the controller is actually sending the commands, like KEY_RIGHT?  I really need to get this working, so I really appreciate your help.  I just can't figure out what I'm doing wrong.  I have tried it on Easel, and Universal Gcode Sender, and my CNC doesn't move, but it moves if I use the up,down,left,right on my keyboard.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    Alright, good that we know the key pressing parts is working.

    I meant a picture of the connections to the Teensy, to see how you soldered it.

    Normally the encoder middle pin should be connected to ground, since the microcontroller has pullups enabled.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Look OK?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    Wiring looks good too.

    Try adding a println here:

     

    long newScrollPos = encoderScroll.read();

    Serial.println(newScrollPos );

     

    The number should increase every time you turn the encoder.

    As an additional check, also add these lines (will trigger if the encoder gives a pulse):

     

    if (digitalRead(PIN_ENC_A) == LOW){

        Serial.println("ENC A TRIGGERED");

      }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    You can also try soldering it to 2 other pins.

    Change the used pin numbers in the code:

     

    #define PIN_ENC_A     9

    #define PIN_ENC_B     10

     

    And add these two lines in setup:

     

    void setup() {

         pinMode(PIN_ENC_A, INPUT_PULLUP);

         pinMode(PIN_ENC_B, INPUT_PULLUP);

         ...

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    As a last suggestion for today:

    The code should also work jf you add a switch between pin 9 and ground or pin 10 and ground. This should give the same result as using an encoder (but less practical of course). By trying this we can rule out a faulty encoder.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Interesting.  I included this in the program

    long newScrollPos = encoderScroll.read();

      Serial.println(newScrollPos );

      if (digitalRead(PIN_ENC_A) == LOW){

    Serial.println("ENC A TRIGGERED");

    if (digitalRead(PIN_ENC_B) == HIGH){

    Serial.println("ENC B TRIGGERED");

     

     

    Here are the results.  when I'm not turning thr encoder, it keeps putting out 00000000000000

    image

    And I included this where it should be outputting the left, right, up, down

     

    Serial.println("NEW_NEW");

     

    but "NEW_NEW" never showed up in the serial monitor.  For some reason, it's not going past this line

     

    if (abs(newScrollPos - lastScrollPos) >= 4) { // there are roughly four presses detected from each rotation to the next detent

        if (newScrollPos - lastScrollPos > -1){ // positive increase

          switch(activeAxis){

     

    Any more ideas??  Thanks Dave...........

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    I changed to pins 22 and 23, but get the same results as before.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    I don't see a change when I ground pins 9 and 10 to ground.  I see the change if I turn the encoder, but not by grounding the pins??

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    So the number never changes from 0 to 1 or higher?

    Try to connect two buttons instead of the rotary encoder and check the output of this code again:

    1 button between pin 9 and ground, 1 button between pin 10 and ground.

     

    long newScrollPos = encoderScroll.read();

      Serial.println(newScrollPos );

     

    Do you have a part number of that rotary encoder?

    I am suspecting that you are not using an encoder, but a potentiometer (variable resistor).

    Can you turn the shaft more than 360 degrees or does it have limits? A rotary encoder should be able to continously turn.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Hi Thomas, any other ideas?   to me it looks like for some reason the program is never getting to this part:  I tried understanding the logic, but it's way above my head.

    long newScrollPos = encoderScroll.read();

     

      if (abs(newScrollPos - lastScrollPos) >= 4) { // there are roughly four presses detected from each rotation to the next detent

        if (newScrollPos - lastScrollPos > -1){ // positive increase

          switch(activeAxis){

          case X_AXISr:

            Keyboard.press(KEY_RIGHT);

            Keyboard.release(KEY_RIGHT);

          break;

          case Y_AXISr:

            Keyboard.press(KEY_UP);

            Keyboard.release(KEY_UP);

          break;

          case Z_AXISr:

            Keyboard.press(KEY_PAGE_UP);

            Keyboard.release(KEY_PAGE_UP);

          }

        } else {

          switch(activeAxis){

          case X_AXISr:

            Keyboard.press(KEY_LEFT);

            Keyboard.release(KEY_LEFT);

          break;

          case Y_AXISr:

            Keyboard.press(KEY_DOWN);

            Keyboard.release(KEY_DOWN);

          break;

          case Z_AXISr:

            Keyboard.press(KEY_PAGE_DOWN);

            Keyboard.release(KEY_PAGE_DOWN);

          }

        }

        lastScrollPos = newScrollPos;

      }

     

      if (activeAxis != lastAxis){

        digitalWrite(lastAxisLED, LOW);

        switch(activeAxis){

          case X_AXISr:

            digitalWrite(PIN_LED_X, HIGH);

            lastAxisLED = PIN_LED_X;

          break;

          case Y_AXISr:

            digitalWrite(PIN_LED_Y, HIGH);

            lastAxisLED = PIN_LED_Y;

          break;

          case Z_AXISr:

            digitalWrite(PIN_LED_Z, HIGH);

            lastAxisLED = PIN_LED_Z;

          break;

        }

        lastAxis = activeAxis;

      }

     

     

      if (activeSpeed != lastSpeed){

        digitalWrite(lastSpeedLED, LOW);

        switch(activeSpeed){

          case SPD_FAST:

            Keyboard.press(KEY_4);

            Keyboard.release(KEY_4);

            digitalWrite(PIN_LED_FAST, HIGH);

            lastSpeedLED = PIN_LED_FAST;

          break;

          case SPD_1MM:

            Keyboard.press(KEY_3);

            Keyboard.release(KEY_3);

            digitalWrite(PIN_LED_1MM, HIGH);

            lastSpeedLED = PIN_LED_1MM;

          break;

          case SPD_01MM:

            Keyboard.press(KEY_2);

            Keyboard.release(KEY_2);

            digitalWrite(PIN_LED_01MM, HIGH);

            lastSpeedLED = PIN_LED_01MM;

          break;

          case SPD_001MM:

            Keyboard.press(KEY_1);

            Keyboard.release(KEY_1);

            digitalWrite(PIN_LED_001MM, HIGH);

            lastSpeedLED = PIN_LED_001MM;

          break;

        }

        lastSpeed = activeSpeed;

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Hi Thomas, any other ideas?   to me it looks like for some reason the program is never getting to this part:  I tried understanding the logic, but it's way above my head.

    long newScrollPos = encoderScroll.read();

     

      if (abs(newScrollPos - lastScrollPos) >= 4) { // there are roughly four presses detected from each rotation to the next detent

        if (newScrollPos - lastScrollPos > -1){ // positive increase

          switch(activeAxis){

          case X_AXISr:

            Keyboard.press(KEY_RIGHT);

            Keyboard.release(KEY_RIGHT);

          break;

          case Y_AXISr:

            Keyboard.press(KEY_UP);

            Keyboard.release(KEY_UP);

          break;

          case Z_AXISr:

            Keyboard.press(KEY_PAGE_UP);

            Keyboard.release(KEY_PAGE_UP);

          }

        } else {

          switch(activeAxis){

          case X_AXISr:

            Keyboard.press(KEY_LEFT);

            Keyboard.release(KEY_LEFT);

          break;

          case Y_AXISr:

            Keyboard.press(KEY_DOWN);

            Keyboard.release(KEY_DOWN);

          break;

          case Z_AXISr:

            Keyboard.press(KEY_PAGE_DOWN);

            Keyboard.release(KEY_PAGE_DOWN);

          }

        }

        lastScrollPos = newScrollPos;

      }

     

      if (activeAxis != lastAxis){

        digitalWrite(lastAxisLED, LOW);

        switch(activeAxis){

          case X_AXISr:

            digitalWrite(PIN_LED_X, HIGH);

            lastAxisLED = PIN_LED_X;

          break;

          case Y_AXISr:

            digitalWrite(PIN_LED_Y, HIGH);

            lastAxisLED = PIN_LED_Y;

          break;

          case Z_AXISr:

            digitalWrite(PIN_LED_Z, HIGH);

            lastAxisLED = PIN_LED_Z;

          break;

        }

        lastAxis = activeAxis;

      }

     

     

      if (activeSpeed != lastSpeed){

        digitalWrite(lastSpeedLED, LOW);

        switch(activeSpeed){

          case SPD_FAST:

            Keyboard.press(KEY_4);

            Keyboard.release(KEY_4);

            digitalWrite(PIN_LED_FAST, HIGH);

            lastSpeedLED = PIN_LED_FAST;

          break;

          case SPD_1MM:

            Keyboard.press(KEY_3);

            Keyboard.release(KEY_3);

            digitalWrite(PIN_LED_1MM, HIGH);

            lastSpeedLED = PIN_LED_1MM;

          break;

          case SPD_01MM:

            Keyboard.press(KEY_2);

            Keyboard.release(KEY_2);

            digitalWrite(PIN_LED_01MM, HIGH);

            lastSpeedLED = PIN_LED_01MM;

          break;

          case SPD_001MM:

            Keyboard.press(KEY_1);

            Keyboard.release(KEY_1);

            digitalWrite(PIN_LED_001MM, HIGH);

            lastSpeedLED = PIN_LED_001MM;

          break;

        }

        lastSpeed = activeSpeed;

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    See my previous post:

     

     

    So the number never changes from 0 to 1 or higher?

    Try to connect two buttons instead of the rotary encoder and check the output of this code again:

    1 button between pin 9 and ground, 1 button between pin 10 and ground.

     

    long newScrollPos = encoderScroll.read();

      Serial.println(newScrollPos );

     

    Do you have a part number of that rotary encoder?

    I am suspecting that you are not using an encoder, but a potentiometer (variable resistor).

    Can you turn the shaft more than 360 degrees or does it have limits? A rotary encoder should be able to continously turn.

     

     

    • Helpful Yes | NoLike (0)Reply
    • Actions
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    OK, connected the two buttons and add the code.  It sends out a continuous series of zeros to the right.  Nothing changes if I ground pins 9 or 10.  I used the same encoder as the one in the project from Element14  Attached are the specs.

     

    Just seems like it's not reaching the keyboard commands.  It's a brand new teensy, but I guess it could be bad, but even changing the pin assignments I get the same results.  In the program, should the  //Serial.begin(9600);  not be commented out?  I did change it, but got the same results.   ???

     

     

    for (int ii = 2; ii < 11; ii++) pinMode(ii, INPUT_PULLUP);

      for (int ii = 14; ii < 21; ii++) pinMode(ii, OUTPUT);

      digitalWrite(PIN_LED_X, HIGH);

      digitalWrite(PIN_LED_FAST, HIGH);

      //Serial.begin(9600);

     

     

    imageimage

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    The Serial.begin(9600); is needed for the serial monitor, just leave it uncommented.

     

    Since nor the buttons, nor the encoder trigger the encoderScroll.read(); function, I suspect you might be using the wrong library.

    This is the one I am using: https://github.com/PaulStoffregen/Encoder

     

    Normally, Arduino stores the libraries under Document/libraries/

    Remove all existing encoder libraries from this folder (if any) and replace with the one from the link above.

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Nope, still no change??

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    I'm running out of ideas...

     

    Include those lines and upload of picture of the serial monitor when turning the encoder:

     

      if (digitalRead(PIN_ENC_A) == LOW){

         Serial.println("ENC A LOW TRIGGERED");
      }

      if (digitalRead(PIN_ENC_A) == HIGH){

         Serial.println("ENC A HIGH TRIGGERED");
      }

      if (digitalRead(PIN_ENC_B) == LOW){

         Serial.println("ENC B LOW TRIGGERED");
      }

      if (digitalRead(PIN_ENC_B) == HIGH){

         Serial.println("ENC B HIGH TRIGGERED");
      }

     

    Also, in File>Preferences, enable these settings:

    image

    Share a screenshot of the output.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Don't give up on me LOL

     

    OK, I put the text after this:

    long newScrollPos = encoderScroll.read();

     

    I don't see what checking the two boxes did?

    Here are the screen shots, it changed based on turning the encoder.  But, it was always printing something even when I wasn't pushing a button or turning the encoder??

     

    imageimageimage

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Hi Thomas, could the pin configuration between the Teensy 3.2 and LC cause the issue?

     

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    When did you get the

    "ENC A HIGH TRIGGERED" and
    "ENC B HIGH TRIGGERED" ?

    If that happens when the encoder is turned, the encoder is connected correctly.

    In that case, the problem lies with the encoder library.

     

    I would like to see the output of this window when compiling and uploading. All of it image

     

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • thomasvdd
    thomasvdd over 5 years ago in reply to wildmack

    Don't think so, I already checked the differences and none are major dealbreakers.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • wildmack
    wildmack over 5 years ago in reply to thomasvdd

    Hi Thomas, I can't figure out how to copy and paste that data, is there a trick to it?  Dave........................

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube