|
Post by Big Man Black T-Shirt(Patrick) on Jul 15, 2017 0:19:29 GMT
I've got a prototype working of a 6-button USB box for jogging the X, Y, and Z motors. It's using a Teensy 3.2, which is a Arduino compatible microcontroller. (I would have used a Arduino Pro micro but I already had the Teensy laying around so...)
If anyone is interested in building one let me know and I'll post my Arduino code. It should work the same in a actual Arduino but I can't confirm that 100%.
|
|
|
Post by Derek the Admin on Jul 15, 2017 4:36:58 GMT
Sure thing! That sounds cool and I'd love to see it. Any vids of it in action?
|
|
|
Post by Big Man Black T-Shirt(Patrick) on Jul 15, 2017 4:45:32 GMT
No, I wanted to see if any M-3 owners wanted info on how to do it before I made a video. For all I know these jog boxes are easy to make and everyone who wants one has already made one, you know? Just trying to gauge interest before I document the build.
|
|
|
Post by Big Man Black T-Shirt(Patrick) on Jul 15, 2017 5:02:14 GMT
#include <Bounce.h>
/* Create Bounce objects for each button. The Bounce object automatically deals with contact chatter or "bounce", and it makes detecting changes very simple.*/ Bounce button0 = Bounce(0, 10); // 10 = 10 ms debounce time which is appropriate for most Bounce button1 = Bounce(1, 10); // mechanical pushbuttons. If a button is too sensitive to rapid touch Bounce button2 = Bounce(2, 10); // you can increase this time. Bounce button3 = Bounce(3, 10); Bounce button4 = Bounce(4, 10); Bounce button5 = Bounce(5, 10); /* Bounce button6 = Bounce(6, 10); Bounce button7 = Bounce(7, 10); Bounce button8 = Bounce(8, 10); Bounce button9 = Bounce(9, 10); */
bool button0down = false; elapsedMillis button0elapsed; bool button1down = false; elapsedMillis button1elapsed; bool button2down = false; elapsedMillis button2elapsed; bool button3down = false; elapsedMillis button3elapsed; bool button4down = false; elapsedMillis button4elapsed; bool button5down = false; elapsedMillis button5elapsed;
void setup() { pinMode(0, INPUT_PULLUP); pinMode(1, INPUT_PULLUP); pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); pinMode(5, INPUT_PULLUP); /* pinMode(6, INPUT_PULLUP); pinMode(7, INPUT_PULLUP); pinMode(8, INPUT_PULLUP); pinMode(9, INPUT_PULLUP); */ Keyboard.begin(); }
void loop() { /* Update all the buttons. There should not be any long delays in loop(), so this runs repetitively at a rate faster than the buttons could be pressed and released.*/ button0.update(); button1.update(); button2.update(); button3.update(); button4.update(); button5.update(); /* button6.update(); button7.update(); button8.update(); button9.update(); */
// Check button 0 for "falling" edge and send Command-Left Arrow if true. if (button0.fallingEdge()) {
button0down = true; button0elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_GUI); // Mac "Command" key press and hold Keyboard.send_now();
Keyboard.set_key1(KEY_LEFT); // Press "Left Arrow" key Moves X- (LEFT) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key1(0); Keyboard.send_now(); }
if (button0.risingEdge()) { button0down = false; }
if (button0down && button0elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button0elapsed = 0; Keyboard.set_modifier(MODIFIERKEY_GUI); // Mac "Command" key press and hold Keyboard.send_now();
Keyboard.set_key1(KEY_LEFT); // Press "Left Arrow" key Moves X- (LEFT) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key1(0); Keyboard.send_now(); }
// Check button 1 for "falling" edge and send Command-Right Arrow if true. if (button1.fallingEdge()) {
button1down = true; button1elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_GUI); // Mac "Command" key press and hold Keyboard.send_now();
Keyboard.set_key2(KEY_RIGHT); // Press "Right Arrow" key Moves X+ (RIGHT) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key2(0); Keyboard.send_now(); }
if (button1.risingEdge()) { button1down = false; }
if (button1down && button1elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button1elapsed = 0; Keyboard.set_modifier(MODIFIERKEY_GUI); // Mac "Command" key press and hold Keyboard.send_now();
Keyboard.set_key2(KEY_RIGHT); // Press "Left Arrow" key Moves X+ (RIGHT) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key2(0); Keyboard.send_now(); }
// Check button 2 for "falling" edge and send Command-Down Arrow if true. if (button2.fallingEdge()) {
button2down = true; button2elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_GUI); // Mac "Command" key press and hold Keyboard.send_now();
Keyboard.set_key3(KEY_DOWN); // Press "Down Arrow" key Moves Y- (DOWN) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key3(0); Keyboard.send_now(); }
if (button2.risingEdge()) { button2down = false; }
if (button2down && button2elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button2elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_GUI); // Mac "Command" key press and hold Keyboard.send_now();
Keyboard.set_key3(KEY_DOWN); // Press "Down Arrow" key Moves Y- (DOWN) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key3(0); Keyboard.send_now(); }
// Check button 3 for "falling" edge and send Command-Up Arrow if true. if (button3.fallingEdge()) {
button3down = true; button3elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_GUI); // Mac "Command" key press and hold Keyboard.send_now();
Keyboard.set_key4(KEY_UP); // Press "Up Arrow" key Moves Y+ (UP) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key4(0); Keyboard.send_now(); }
if (button3.risingEdge()) { button3down = false; }
if (button3down && button3elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button3elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_GUI); // Mac "Command" key press and hold Keyboard.send_now();
Keyboard.set_key4(KEY_UP); // Press "Up Arrow" key Moves Y+ (UP) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key4(0); Keyboard.send_now(); }
// Check button 4 for "falling" edge and send Shift-Command-Down Arrow if true. if (button4.fallingEdge()) {
button4down = true; button4elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_SHIFT); // Press and hold "Shift" Keyboard.send_now();
Keyboard.set_modifier(MODIFIERKEY_SHIFT | MODIFIERKEY_GUI); // Press Mac "Command" while still holding "Shift" Keyboard.send_now();
Keyboard.set_key5(KEY_DOWN); // Press "Down Arrow" key Moves Z- (DOWN) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key5(0); Keyboard.send_now(); }
if (button4.risingEdge()) { button4down = false; }
if (button4down && button4elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button4elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_SHIFT); // Press and hold "Shift" Keyboard.send_now();
Keyboard.set_modifier(MODIFIERKEY_SHIFT | MODIFIERKEY_GUI); // Press Mac "Command" while still holding "Shift" Keyboard.send_now();
Keyboard.set_key5(KEY_DOWN); // Press "Down Arrow" key Moves Z- (DOWN) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key5(0); Keyboard.send_now(); }
// Check button 5 for "falling" edge and send Shift-Command-Up Arrow if true. if (button5.fallingEdge()) {
button5down = true; button5elapsed = 0;
Keyboard.set_modifier(MODIFIERKEY_SHIFT); // Press and hold "Shift" Keyboard.send_now();
Keyboard.set_modifier(MODIFIERKEY_SHIFT | MODIFIERKEY_GUI); // Press Mac "Command" while still holding "Shift" Keyboard.send_now();
Keyboard.set_key6(KEY_UP); // Press "Up Arrow" key Moves Z+ (UP) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key6(0); Keyboard.send_now(); } if (button5.risingEdge()) { button5down = false; }
if (button5down && button5elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button5elapsed = 0; Keyboard.set_modifier(MODIFIERKEY_SHIFT); // Press and hold "Shift" Keyboard.send_now();
Keyboard.set_modifier(MODIFIERKEY_SHIFT | MODIFIERKEY_GUI); // Press Mac "Command" while still holding "Shift" Keyboard.send_now();
Keyboard.set_key6(KEY_UP); // Press "Up Arrow" key Moves Z+ (UP) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_modifier(0); Keyboard.set_key6(0); Keyboard.send_now(); }
}
There's the code that I have working on my Mac and UGS Platform. I don't know if the Windows version of UGS Platform or Grbl Panel requires the Shift+Windows key to be pressed along with the Arrow keys, but if it does then the MODIFIERKEY_GUI is the Windows key (and the Command key on a Mac).
If there's interest in this project I'll do a video and more details, if not, then here's the code. Paul at PJRC.com (and owner/creator of Teensy) answered all my questions and pointed me in the right direction. I couldn't have done this without his help. Thanks Paul!
|
|
|
Post by Derek the Admin on Jul 15, 2017 13:56:59 GMT
Very nice.
Thanks for sharing this.
|
|
|
Post by Big Man Black T-Shirt(Patrick) on Jul 15, 2017 23:35:58 GMT
Updated video showing X, Y, and Z all working with GRBL v0.9j and UGS v1.0.9.
|
|
|
Post by activereality on Jul 16, 2017 14:03:36 GMT
BGBT, Awesome Thank you!. I really like the idea of having an easy to use set-up just to jog the machine around and get it close to where i want it. I plan on looking over this and seeing what I can prep for the King. Thanks again! Aaron
|
|
|
Post by Derek the Admin on Jul 17, 2017 21:15:22 GMT
When you said you couldn't do a Z jog in grbl 0.9.... just curious. I am tied down to my desk at the moment, but won't keyboard 7 and keybord 1 jog Z in UGS classic using grbl 0.9? Just wondering.
|
|
|
Post by Big Man Black T-Shirt(Patrick) on Jul 18, 2017 0:46:43 GMT
Probably, I just never looked into it because I use UGS Platform.
I just checked it, UGS v1.0.9 uses 3 for Down and 9 for UP on the Z axis.
I'll post the correct code for UGS in a minute.
|
|
|
Post by Big Man Black T-Shirt(Patrick) on Jul 18, 2017 1:34:02 GMT
OK, here's the code for UGS 1.0.9, I also changed the button numbers on the Teensy to coincide with the Keyboard.set_key lines of code, to make it easier to follow. (button1 is Keyboard.set_key1, button2 is Keyboard.set_key2, etc., etc.)
UGS v1.0.9 does not require either the GUI key or the Shift key, so I removed those lines from this code to keep it simple.
I have this working with UGS v1.0.9 and the previously posted code works with UGS Platform v2.
Some tweaking of both the "Bounce button1 = Bounce(1, 10)" setting at the beginning of the code and the "button1down && button1elapsed > 160" settings may be needed on your setup to cut out any bounce your switches are having. Unfortunately, these settings also affect the jog speed and smoothness so experiment and let me know what you find to be the best settings for both switch bounce and jog speed/movement!
#include <Bounce.h>
/* Create Bounce objects for each button. The Bounce object automatically deals with contact chatter or "bounce", and it makes detecting changes very simple.*/
Bounce button1 = Bounce(1, 10); // 10 = 10 ms debounce time which is appropriate for most Bounce button2 = Bounce(2, 10); // mechanical pushbuttons. If a button is too sensitive to rapid touch Bounce button3 = Bounce(3, 10); // you can increase this time. Bounce button4 = Bounce(4, 10); Bounce button5 = Bounce(5, 10); Bounce button6 = Bounce(6, 10);
bool button1down = false; elapsedMillis button1elapsed; bool button2down = false; elapsedMillis button2elapsed; bool button3down = false; elapsedMillis button3elapsed; bool button4down = false; elapsedMillis button4elapsed; bool button5down = false; elapsedMillis button5elapsed; bool button6down = false; elapsedMillis button6elapsed;
void setup() { pinMode(1, INPUT_PULLUP); pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); pinMode(4, INPUT_PULLUP); pinMode(5, INPUT_PULLUP); pinMode(6, INPUT_PULLUP); Keyboard.begin(); }
void loop() { /* Update all the buttons. There should not be any long delays in loop(), so this runs repetitively at a rate faster than the buttons could be pressed and released.*/ button1.update(); button2.update(); button3.update(); button4.update(); button5.update(); button6.update();
// X- Movement
// Check button 1 for "falling" edge and send Left Arrow key if true. if (button1.fallingEdge()) {
button1down = true; button1elapsed = 0;
Keyboard.set_key1(KEY_LEFT); // Press "Left Arrow" key Moves X- (LEFT) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key1(0); Keyboard.send_now(); }
if (button1.risingEdge()) { button1down = false; }
if (button1down && button1elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button1elapsed = 0;
Keyboard.set_key1(KEY_LEFT); // Press "Left Arrow" key Moves X- (LEFT) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key1(0); Keyboard.send_now(); }
// X+ Movement
// Check button 2 for "falling" edge and send Right Arrow key if true. if (button2.fallingEdge()) {
button2down = true; button2elapsed = 0;
Keyboard.set_key2(KEY_RIGHT); // Press "Right Arrow" key Moves X+ (RIGHT) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key2(0); Keyboard.send_now(); }
if (button2.risingEdge()) { button2down = false; }
if (button2down && button2elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button2elapsed = 0;
Keyboard.set_key2(KEY_RIGHT); // Press "Right Arrow" key Moves X+ (RIGHT) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key2(0); Keyboard.send_now(); }
// Y- Movement
// Check button 3 for "falling" edge and send Down Arrow key if true. if (button3.fallingEdge()) {
button3down = true; button3elapsed = 0;
Keyboard.set_key3(KEY_DOWN); // Press "Down Arrow" key Moves Y- (DOWN) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key3(0); Keyboard.send_now(); }
if (button3.risingEdge()) { button3down = false; }
if (button3down && button3elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button3elapsed = 0;
Keyboard.set_key3(KEY_DOWN); // Press "Down Arrow" key Moves Y- (DOWN) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key3(0); Keyboard.send_now(); }
// Y+ Movement
// Check button 4 for "falling" edge and send Up Arrow key if true. if (button4.fallingEdge()) {
button4down = true; button4elapsed = 0;
Keyboard.set_key4(KEY_UP); // Press "Up Arrow" key Moves Y+ (UP) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key4(0); Keyboard.send_now(); }
if (button4.risingEdge()) { button4down = false; }
if (button4down && button4elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button4elapsed = 0;
Keyboard.set_key4(KEY_UP); // Press "Up Arrow" key Moves Y+ (UP) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key4(0); Keyboard.send_now(); }
// Z- Movement
// Check button 5 for "falling" edge and send Keypad 3 if true. if (button5.fallingEdge()) {
button5down = true; button5elapsed = 0;
Keyboard.set_key5(KEYPAD_3); // Press "3" on keypad Moves Z- (DOWN) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key5(0); Keyboard.send_now(); }
if (button5.risingEdge()) { button5down = false; }
if (button5down && button5elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button5elapsed = 0;
Keyboard.set_key5(KEYPAD_3); // Press "3" on keypad Moves Z- (DOWN) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key5(0); Keyboard.send_now(); }
// Z+ Movement
// Check button 6 for "falling" edge and send Keypad 9 if true. if (button6.fallingEdge()) {
button6down = true; button6elapsed = 0;
Keyboard.set_key6(KEYPAD_9); // Press "9" on keypad Moves Z+ (UP) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key6(0); Keyboard.send_now(); } if (button6.risingEdge()) { button6down = false; }
if (button6down && button6elapsed > 160) { // 100 is noisy, PJRC said 500, which was too slow, increase it if it bounces again, though button6elapsed = 0;
Keyboard.set_key6(KEYPAD_9); // Press "9" on keypad Moves Z+ (UP) Keyboard.send_now();
// release all the keys at the same instant Keyboard.set_key6(0); Keyboard.send_now(); }
}
|
|
|
Post by Big Man Black T-Shirt(Patrick) on Jul 18, 2017 2:10:05 GMT
FWIW, I just updated the above video to show all axes working.
|
|
|
Post by Big Man Black T-Shirt(Patrick) on Jul 18, 2017 2:12:42 GMT
|
|
|
Post by breslinmr on Jul 18, 2017 2:15:35 GMT
Holy mother off Jesus may as well be wrote in Chinese to me lol π Far to many words for meπ³π³. Think I'm gona need a miricle setting up this machine π©
There's gona be a lot off post from me in the very near future π
|
|
|
Post by Big Man Black T-Shirt(Patrick) on Jul 18, 2017 8:47:43 GMT
To be accurate, this isn't needed in order for you to setup or use your M-3. This is if you wanted to build a little USB box to control jogging. You can just use the computer's keyboard which is what I bet most people do. This is just for those of us nerds who want to tinker some more!
|
|
|
Post by Derek the Admin on Jul 18, 2017 12:13:33 GMT
Very nice work. I like it.
|
|