Hello people
Thought I would post some info of my Joystick. I know there is another Joystick thread, but this one has a few extra features.
Its the standard twist X, Y, Z joystick. But I have a push button next to the joystick that enables it.
The button on the top of the joystick resets the X,Y,Z origin. You press and hold it for 2 seconds (to stop accidental resets).
I won’t go too far into the joystick wiring. It’s been covered already, and it’s in my drawing.
Attached here is the wiring and code. In the Arduino code, you can change the value of the button delay (or remove it).
This is a tiny circuit on an 8 pin ATtiny85 processor (because I had some!).
These are great little IC’s, but the internal clock isn’t all that accurate. So, one of the pins has a multi-turn Pot on it that allows you to tune the clock until you get clean serial transmission.
There is a line in the code that is commented out. Uncomment that, and adjust the pot until the serial screen shows the G-code commands cleanly.
My CNC runs at 250000 baud. If your CNC is using a slower baud rate, then you may not need to fine tune the clock.
If you don’t pre-tune the circuit first, then when you press the button, Marlin will not understand the garbage text it received. It won’t hurt it, just not work.
You could just tune the pot until it does respond.
There are 3 buttons programmed here. Reset X,Y,Z origin, Home all and Home X.Y.
But, you can simply change the text in the serial command line and make them quite frankly… anything you want.
You can program ATtiny85 chips with a dedicated little programmer board (pennies off Ebay), or use an Arduino UNO with the ArduinoISP program loaded (that program is supplied with the Arduino IDE).
If you want to view the output of the ATtiny however, the serial port of the UNO will not work, and you will need a second one to enable that option (it’s in my drawing).
ATtiny85 chips are also pennies. I got 5 for less than a £1 each from RS a while back.
Of course, you could just use an Arduino Nano, Pro Mini etc. I just wanted a very small footprint.
And this can quite literally be used for any kind of ‘G-CODE’ button and with a bigger Arduino board, you could have far more buttons.
You will need to enable the second serial port in Configuration.h.
G-Code_Injector_v1.3.zip (958 Bytes)
// ATTiny85 Based Serial G-Code injector
// Steve Croot
// March 2020#include <SendOnlySoftwareSerial.h>
#define BUTTON_1 0 // Button 1 input (HOME XYZ)
#define BUTTON_2 1 // Button 2 input (HOME XY)
#define BUTTON_3 2 // Button 3 input (RESET ORIGIN)
#define OscTrim 3 // Crystal trim potSendOnlySoftwareSerial MarlinSerial (4); // Serial TX pin
unsigned long CurrentMillis; // Timer elements for delayed button press
unsigned long ButtonMillis;
int ButtonDelay=2000; // Button delay in milliseconds. Adjust to suit or 0 for off.void setup() { //--------------------------------------------------------------------------------------
MarlinSerial.begin(250000);
pinMode(BUTTON_1, INPUT);
pinMode(BUTTON_2, INPUT);
pinMode(BUTTON_3, INPUT);}
void loop() { //----------------------------------------------------------------------------------------
CurrentMillis=millis();
int val = analogRead(OscTrim); // Obtain the adjustment value
OSCCAL = val/4; // Adjust the oscillator//MarlinSerial.print("OSCCAL = ");MarlinSerial.println(OSCCAL, HEX);delay(200); // Uncomment this line to help tune the crystal (DO NOT LEAVE ACTIVE ONCE TUNED!)
if (digitalRead (BUTTON_1) == HIGH){ // Button 1 command (Home all)
do{
if (millis()-CurrentMillis>ButtonDelay){
MarlinSerial.println(“G28 X Y Z”);
do{delay(2);}while(digitalRead (BUTTON_1) == HIGH);
}
} while(digitalRead (BUTTON_1) == HIGH);
}if (digitalRead (BUTTON_2) == HIGH){ // Button 2 command (Home X Y)
do{
if (millis()-CurrentMillis>ButtonDelay){
MarlinSerial.println(“G28 X Y”);
do{delay(2);}while(digitalRead (BUTTON_2) == HIGH);
}
} while(digitalRead (BUTTON_2) == HIGH);
}if (digitalRead (BUTTON_3) == HIGH){ // Button 3 command (Reset origin)
do{
if (millis()-CurrentMillis>ButtonDelay){
MarlinSerial.println(“G92 X0 Y0 Z0”);
do{delay(2);}while(digitalRead (BUTTON_3) == HIGH);
}
} while(digitalRead (BUTTON_3) == HIGH);
}} //---------------------------------------------------------------------------------------------------------