# Using limit switches to automate/calibrate motors in uc2-rest

**URL:** <https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94>\
**Category:** Development and Collaboration\
**Tags:** uc2-esp\
**Created:** [January 22, 2025, 10:31am UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94 "2025-01-22T10:31:06Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [January 22, 2025, 10:31am UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/1 "2025-01-22T10:31:06Z")

</div>

Would anyone have any experience on using a cnc shield v3 with esp32 board and using a limit switch? Seems like motors are nice but with limit/end switches calibration could be a lot easier. There seem dedicated ports on the cnc shield for these switches (which makes sense), did anyone ever try these and integrate them into uc2-rest?

Many thanks

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [January 22, 2025, 5:30pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/2 "2025-01-22T17:30:23Z")

</div>

Hey Tom, thanks for reaching out again. Indeed there is a function that is called home which can move the motor in a certain direction with an unstop with certain polarity which is then reversing the direction when it reaches the end stop and then stopping when it’s free again footstep I’m walking right now but there is a documentation in the firmware. You should look for home\_act this is possible for access one two three. There’s a funny back in the fastl stepper motor library which may cause random direction changes when call for the first time, but in principle it should work

---

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [February 3, 2025, 3:02pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/3 "2025-02-03T15:02:12Z")

</div>

Thanks! I found the code, motor starts homing! But how should I wire the end switch on a CNC shield v3? I am trying this:

 ![image](https://global.discourse-cdn.com/free1/uploads/openuc2/original/1X/1da2ff27582036071d920f431e42f97254583fd4.jpeg)  
but then nothing happens for both x+ or x-. (or any other axis?), do I need to change something in the software to flash the esp32 board? I am using the UC2 ESP32 Flashing Tool.

Many thanks for the help!

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [February 3, 2025, 3:22pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/4 "2025-02-03T15:22:09Z")

</div>

Oh, interesting. I’ve never tried the CNC shield - actually it’S the other firmware  
 ![image](https://global.discourse-cdn.com/free1/uploads/openuc2/original/1X/afbb6dceaf18ec23fa12ca377c9166943a980bb5.jpeg)

```cpp
          const int PIN_DEF_END_X = GPIO_NUM_13;
          const int PIN_DEF_END_Y = GPIO_NUM_5;
          const int PIN_DEF_END_Z = GPIO_NUM_23; 

```

If those are the ones from the endstops, it should be ok. You would need to use pull-ups since the internal ones behave weirdly if I’m not mistaking

---

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [March 3, 2025, 9:57am UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/5 "2025-03-03T09:57:30Z")

</div>

Hello again, I finally had some time to test.  
So the gpio pins from the cnc shield to the esp32 correspond to the arduino equivalent used in the code, so that should be okay. I am using a pull-up configuration but can’t seem to get it working.

Using ESP32.home.home\_x(speed=500) start homing, but does not respond to any of the ports. I tried both 3 way and 2 way switches, the common connected to ground, and the NO connected to a 10k resistor which is connected to the cnc shield 5V and before the resistor to X+ (which should be connected to the gpio pin). I tried both X-, X+, Y- etc, but it does not respond. I also tried connecting to X+ and GND through the switch but that also does not respond. Am I missing something?

Many thanks again for the assistance.

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [March 3, 2025, 11:40am UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/6 "2025-03-03T11:40:01Z")

</div>

can you try this page [openUC2 WebSERIAL Demonstration](https://youseetoo.github.io/indexWebSerialTest.html) and paste the following line (after connecting to the board):  
`{"task":"/digitalin_get"}`

By changing the pins and polling the result, you should see a variation in its response from 0…1

I must admit that the firmware available through [openUC2 WebSERIAL Demonstration](https://youseetoo.github.io/indexWebSerialTest.html) for the WEMOS is already fairly old. I could initiate a rebuild - should work without major complications, but i haven’T used this PCB for a while now. We only use our UC2v3 PCBs provided by @christiankuttke

---

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [March 3, 2025, 12:56pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/7 "2025-03-03T12:56:03Z")

</div>

Thank you for the speedy response I understand that you use the uc2v3 boards.

Using the command prints:

> {“task”:“/digitalin\_get”}  
> ++  
> {  
> “qid”: 0,  
> “success”: 1  
> }

–  
It prints the same output if I press the limit switch for all inputs. Does this listen to all gpio pins? I don’t think I fully understand, what it is supposed to do, shouldn’t this print specific information per GPIO pin?

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [March 3, 2025, 2:31pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/8 "2025-03-03T14:31:30Z")

</div>

There is a new firmware based on the latest development for the WEMOS pinout .Can you check waht {“task”: “/state\_get”} and the digital\_in gives?

Thanks!

> <https://github.com/youseetoo/youseetoo.github.io/blob/main/static/firmware_build/esp32_UC2_WEMOS.bin>

Flash it via [youseetoo.github.io](http://youseetoo.github.io) =\> WEMOS … Thanks

---

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [March 3, 2025, 2:52pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/9 "2025-03-03T14:52:01Z")

</div>

Thanks for making these changes so fast!

But this is now the output after reflashing:

> {“task”: “/state\_get”}  
> ++{“error”:“Serial input is null”}–

> {“task”:“/digitalin\_get”}  
> ++{“error”:“Serial input is null”}–

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [March 3, 2025, 3:08pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/10 "2025-03-03T15:08:45Z")

</div>

What’s happening if you hit the button?

---

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [March 3, 2025, 3:20pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/11 "2025-03-03T15:20:37Z")

</div>

I think I have to change the " and not copy them from the forum. Otherwise it keeps giving me the serial input is null code.

> {“task”: “/state\_get”}  
> ++  
> {“state”:{“identifier\_name”:“UC2\_Feather”,“identifier\_id”:“V2.0”,“identifier\_date”:“Mar 3 202514:01:21”,“identifier\_author”:“BD”,“IDENTIFIER\_NAME”:“uc2-esp”,“configIsSet”:0,“pindef”:“UC2\_WEMOS”,“I2C\_SLAVE”:0},“qid”:0}  
> –

For the other command it gives me:

> {“task”:“/digitalin\_get”}  
> Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.

> Core 1 register dump:  
> PC : 0x400d4659 PS : 0x00060930 A0 : 0x800d26f8 A1 : 0x3ffd4970  
> A2 : 0x3ffb7ec0 A3 : 0x3f403054 A4 : 0x3f4043b5 A5 : 0x0000ff00  
> A6 : 0x3ffd2a10 A7 : 0x40404040 A8 : 0x800d4659 A9 : 0x3ffd4950  
> A10 : 0x00000000 A11 : 0x3f4043b5 A12 : 0x00060620 A13 : 0x3ff96355  
> A14 : 0x3ffb7ec0 A15 : 0x00000000 SAR : 0x0000001a EXCCAUSE: 0x0000001c  
> EXCVADDR: 0x00000014 LBEG : 0x400012c5 LEND : 0x400012d5 LCOUNT : 0xfffffff0  
> …

But I don’t see a difference between button presses (considering that it requests something from a memory location that is not there, it would be weird if it could find something?)

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [March 4, 2025, 2:59pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/12 "2025-03-04T14:59:58Z")

</div>

Can you try this?

```json
{"task": "/digitalin_get", "digitalinid":1}

```

---

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [March 5, 2025, 10:24am UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/13 "2025-03-05T10:24:09Z")

</div>

Tested for id 1 to 8, and for X-, X+ etc, but all the same output value of 0:

> ++  
> {“digitalin”:{“digitalinid”:1,“digitalinval”:0}}  
> –

Edit: I tested with a UC2 (I think V2) board, and homing works there, same setup. So I can switch to one of these boards if needed.

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [March 5, 2025, 12:18pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/14 "2025-03-05T12:18:26Z")

</div>

The pinconfig is the following:

```cpp
#pragma once
#include "Arduino.h"
#include "PinConfigDefault.h"
struct UC2_WEMOS : PinConfig // also used for cellSTORM wellplateformat
{
     /*#define MOTOR_CONTROLLER
     #define BLUETOOTH
     #define PSXCONTROLLER
     #define WIFI
     #define LED_CONTROLLER
     #define HOME_MOTOR
     #define LASER_CONTROLLER*/
     const char *pindefName = "UC2_WEMOS";
     // ESP32-WEMOS D1 R32
     int8_t MOTOR_A_DIR = GPIO_NUM_23; // Bridge from Endstop Z to Motor A (GPIO_NUM_23)
     int8_t MOTOR_X_DIR = GPIO_NUM_16;
     int8_t MOTOR_Y_DIR = GPIO_NUM_27;
     int8_t MOTOR_Z_DIR = GPIO_NUM_14;
     int8_t MOTOR_A_STEP = GPIO_NUM_5; // Bridge from Endstop Y to Motor A (GPIO_NUM_5)
     int8_t MOTOR_X_STEP = GPIO_NUM_26;
     int8_t MOTOR_Y_STEP = GPIO_NUM_25;
     int8_t MOTOR_Z_STEP = GPIO_NUM_17;
     int8_t MOTOR_ENABLE = GPIO_NUM_12;
     bool MOTOR_ENABLE_INVERTED = true;

     int8_t LASER_1 = GPIO_NUM_18; // WEMOS_D1_R32_SPINDLE_ENABLE_PIN
     int8_t LASER_2 = GPIO_NUM_19; // WEMOS_D1_R32_SPINDLEPWMPIN
     int8_t LASER_3 = GPIO_NUM_13; // WEMOS_D1_R32_X_LIMIT_PIN

     int8_t LED_PIN = GPIO_NUM_4;
     int8_t LED_COUNT = 64;

     const char *PSX_MAC = "1a:2b:3c:01:01:03";
     int8_t PSX_CONTROLLER_TYPE = 2;

     int8_t JOYSTICK_SPEED_MULTIPLIER = 5;
     int8_t JOYSTICK_SPEED_MULTIPLIER_Z = 3;

     const char *mSSID = "Blynk";
     const char *mPWD = "12345678";
     bool mAP = false;
};
const UC2_WEMOS pinConfig;

```

so that means its actually not activated 😃

I’ll do that now 😃

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [March 5, 2025, 12:30pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/15 "2025-03-05T12:30:52Z")

</div>

can you confirm it’s

```cpp
    // Additional Digital Input Pins
    int8_t DIGITAL_IN_1 = -1; // Disabled
    int8_t DIGITAL_IN_2 = GPIO_NUM_36; // VP on ESP32
    int8_t DIGITAL_IN_3 = GPIO_NUM_39; // VN on ESP32

```

on the ESP32 Wemos D1? You can trace the contacts with a multimeter I suppose

---

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [March 5, 2025, 12:50pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/16 "2025-03-05T12:50:24Z")

</div>

LimX is on GPIO\_NUM\_13  
LimY is on GPIO\_NUM\_5  
LimZ is on GPIO\_NUM\_23

gpio\_36 is analog and connected on the shield to scl and 39 to sda. Or do I not understand the question?

Yes now I understand VP is 36 and VN is 39 on the chip.

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [March 5, 2025, 1:14pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/17 "2025-03-05T13:14:07Z")

</div>

Ah, true. Thanks! I’ll bake this in and rebuild now. Give it 10 minutes and you can reflash

---

<div class="post-metadata">

**Author:** ![benedictdied](https://avatars.discourse-cdn.com/v4/letter/b/96bed5/32.png) [@benedictdied](https://openuc2.discourse.group/u/benedictdied)\
**Post date:** [March 5, 2025, 1:15pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/18 "2025-03-05T13:15:54Z")

</div>

> [@tomvh](#):
>
> LimX is on GPIO\_NUM\_13  
> LimY is on GPIO\_NUM\_5  
> LimZ is on GPIO\_NUM\_23

> **[Compile ESP32 Platformio UC2 WEMOS · Workflow runs · youseetoo/uc2-esp32](https://github.com/youseetoo/uc2-esp32/actions/workflows/build_pio_uc2_wemos.yml)**
>
> Contribute to youseetoo/uc2-esp32 development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![tomvh](https://avatars.discourse-cdn.com/v4/letter/t/a9adbd/32.png) [@tomvh](https://openuc2.discourse.group/u/tomvh)\
**Post date:** [March 5, 2025, 1:22pm UTC](https://openuc2.discourse.group/t/using-limit-switches-to-automate-calibrate-motors-in-uc2-rest/94/19 "2025-03-05T13:22:23Z")

</div>

Many thanks for the help, appreciated!
