Onebutton homing

how to add grbl home button this project ```
Please can someone help me I like to experiment with arduino I made a small code to work with Onebutton GRBL link but pc UGS works fine but Onebutton doesn't work
thank you
best regords

<
#include <SoftwareSerial.h>
#include "OneButton.h"

// Setup a new OneButton on pin A1.  
OneButton button1(A1, true);



// setup code here, to run once:
void setup() {
  // Setup the Serial port. see http://arduino.cc/en/Serial/IfSerial
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println("$X");
  


  // link the button 1 functions.
  button1.attachClick(click1);
  
  

} // setup


// main code here, to run repeatedly: 
void loop() {
  // keep watching the push buttons:
  button1.tick();
  

  // You can implement other code in here or just wait a while 
 // delay(10);
} // loop





// ----- button 1 callback functions

// This function will be called when the button1 was pressed 1 time (and no 2. button press followed).

void sendWait(char * s)
{
  bool found = false;
  while (Serial.read() > 0); // read any previous junk
  
  Serial.println(s);

  while (!found)
  {
    while(Serial.available() < 2);
    if (Serial.read() == 'o' && Serial.peek() == 'k') found = true;
  }
}


void click1()

{
  
 sendWait("G0 Y0 X0 ");
 sendWait("G0 Y-10 ");
 sendWait("G0 x-30 ");
 sendWait("G0 x30 ");
 sendWait("G0 x0 ");
 sendWait("G0 y-15 ");
 sendWait("G0 x-50 ");
 sendWait("G0 x50 ");
 sendWait("G0 y-15 ");
 sendWait("G0 x50 ");
 sendWait("G0 x0 ");
 sendWait("G0 xy0 ");
 


} // click1


// This function will be called when the button1 was pressed 2 times in a short timeframe.
void doubleclick1() {
  Serial.println("M5");
} // doubleclick1


// This function will be called once, when the button1 is pressed for a long time.
void longPressStart1() {
  Serial.println("Button 1 longPress start");
} // longPressStart1


// This function will be called often, while the button1 is pressed for a long time.
void longPress1() {
  Serial.println("Button 1 longPress...");
} // longPress1


// This function will be called once, when the button1 is released after beeing pressed for a long time.
void longPressStop1() {
  Serial.println("Button 1 longPress stop");
} // longPressStop1

type or paste code here

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

thank you very much

where avilable this topic sir please

Thank you for adding the code tags

What do you expect the sketch that you posted to do ?

thank you for reply sir
my sketch work with grbl fixed code reapet action
so work without PC, UGS
thank you
best regords

As far as I can see, when you click the button the click1() function runs and sends a series of commands via Serial. Before each command is sent the sketch waits for "ok" to be received on Serial

I cannot test it with GRBL but it works for me with input from the Serial monitor of the "ok"

Is that what the sketch should do ?
Have you tried printing what is received to ensure that you are getting the "ok" messages ?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.