Skip to content

4x Switch Input module

Longus edited this page Nov 26, 2021 · 2 revisions

This module is designed to be very robust against noise and voltage spikes on (4) switch inputs. The signal enters through an optocoupler, goes through a little filtering and then through a Schmitt trigger. It has 3 terminals per switch (Signal, 5V and Gnd). This can be used with basic 2 terminal switches, 3 wire reprap style switches, Many types of 3 wire optical vane type switches and 3 wire, 5v NPN proximity switches.

Overview

The switches connect to a fully isolated optocoupler. A simple switch completes the circuit from pin 1 to pin 2. This connects the opto's LED to ground and activates the circuit. Simple contact switches can do this and active switches with NPN type circuits can also work. Here is a good guide to using and debugging switches with Grbl_ESP32.

Simple 2 Wire Contact switches

Connect one wire to ground and one to signal.

3 Wire Switches

3 wire switches are common with DIY 3D printers. They are low cost and easy to wire. The 3 wires are +, gnd, and signal. The + and ground allow the switch to have an LED to indicate the state. Many are wired with a red (+), black (gnd), white (signal) color scheme. This is how they are hooked up.

Proximity Switches

Proximity switches must be 3 wire 5V NPN type switches. Most are NPN types, but most are higher voltage with a range of 6V-30V. This module can only provide 5V. Most use the standard Blue (0V), Brown (+) and Black (Signal) wire colors. See the image for the wiring. (Twidec p/n LJ8A3-2-Z/BX-5V)

If you need a higher voltage, you need to supply that yourself. Just wire the positive side of that power to the sensor and connect the negative side to the input module ground terminal (center pin) along with the sensor's ground pin.

How terminal blocks map to the I/O numbers.

Example Machine Definitions

This module can be used on CNC I/O Module Sockets #1,#2,#3,& #4

Note: Socket #2 uses GPIO_NUM_2 for the first channel. GPIO_NUM_2 must be either left unconnected/floating, or driven Low, in order to enter the serial bootloader. If you are having trouble loading a program and you have this module installed in module socket #2, you must either remove the module or change the state of the switch on the first channel. You can also upload firmware via WiFi or remove the ESP32 from the main board during programming

Examples

// 4x Switch input module on CNC I/O module Socket #1
#define X_LIMIT_PIN             GPIO_NUM_33
#define Y_LIMIT_PIN             GPIO_NUM_32
#define Z_LIMIT_PIN             GPIO_NUM_35
#define X2_LIMIT_PIN            GPIO_NUM_34 // second x limit switch

#define DEFAULT_INVERT_LIMIT_PINS       0  // Sets the default for N.O. switches
// 4x Input Module in Socket #1
// https://github.com/Longus/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
#define X_LIMIT_PIN             GPIO_NUM_33
#define Y_LIMIT_PIN             GPIO_NUM_32
#define Z_LIMIT_PIN             GPIO_NUM_35
#define PROBE_PIN               GPIO_NUM_34

#define DEFAULT_INVERT_LIMIT_PINS       0
#define DEFAULT_INVERT_PROBE_PIN        0
// 4x Switch Input module  in socket #2
// // https://github.com/Longus/6-Pack_CNC_Controller/wiki/4x-Switch-Input-module
#define CONTROL_RESET_PIN           GPIO_NUM_2
#define CONTROL_FEED_HOLD_PIN       GPIO_NUM_25
#define CONTROL_CYCLE_START_PIN     GPIO_NUM_39
#define CONTROL_SAFETY_DOOR_PIN     GPIO_NUM_36

It cannot be used on CNC I/O Module Socket #5, because those are output only pins.

Possible Inputs

#define X_LIMIT_PIN   
#define Y_LIMIT_PIN     
#define Z_LIMIT_PIN   
#define A_LIMIT_PIN  
#define B_LIMIT_PIN
#define C_LIMIT_PIN

#define PROBE_PIN     

#define CONTROL_CYCLE_START
#define CONTROL_SAFETY_DOOR_PIN
#define CONTROL_RESET_PIN
#define CONTROL_FEED_HOLD_PIN

// advanced users only! See https://github.com/Longus/Grbl_Esp32/wiki/Macro-Button-Feature
#define MACRO_BUTTON_1_PIN
#define MACRO_BUTTON_2_PIN
#define MACRO_BUTTON_3_PIN
#define MACRO_BUTTON_4_PIN

Board Assembly

The boards for sale on Tindie need to have the terminal blocks and header soldered. Start by joining the tall terminal blocks to the short terminal blocks. They have tabs and grooves that link them. See the pictures above.

Settings

In the open state, the signal is low. In the closed state the signal is high. The setting for N.O switches would be...

  • $Limits/Invert=Off
  • $Probe/Invert=Off

If the signal are inverted from what you want adjust these settings.

For control pins, you need to set #define INVERT_CONTROL_PIN_MASK to match the switches you defined and the switch type (N.O. or N.C.) you are using. It is a 4 bit value with a default of B1111. The bit order is Cycle Start | Feed Hold | Reset | Safety Door.

For N.O switches set the bits to 0 like B0000.

For N.C switches set the bits to 1 like B1111.

The value of bits for switches you have not define does not matter.

You can put it in your machine definition file like this.

#ifdef INVERT_CONTROL_PIN_MASK
#    undef INVERT_CONTROL_PIN_MASK
#endif
#define INVERT_CONTROL_PIN_MASK B0001

You can set the defaults in your machine definition with...

#define DEFAULT_INVERT_LIMIT_PINS       0
#define DEFAULT_INVERT_PROBE_PIN        0

Source Files

Github Repo.

Clone this wiki locally