Prerequisites
If not already done so already, install Arduino software and make basic connections, as described in page for MRMS ESP32: Arduino, IMU, eFuse, BT, WiFi, CAN Bus (mrm-esp32).
Task
We will use GPIO again, as in LED example, but this time as input. It will sense if its voltage is 0 V (logical 0) or 3.3 V (logical 1).
Connection
Starting from the basic connection, let's add a
ML-R switch 2x (mrm-switch). The picture shows 5 V power supply to mrm-esp32, although it is not necessary for this example.
3.3 V supply can be made using a Dupont cable with 0.1" plugs. If You have more switches more of them, an adapter will be handy, like ML-R Distribution Pins 3x Passive (mrm-distrib-c).
Program
The program is quite simple
:
void setup() {
pinMode(2, OUTPUT);
pinMode(25, INPUT);
}
void loop() {
digitalWrite(2, digitalRead(25));
}
We set GPIO 2 to be output (mrm-esp32 on-board LED) and 25 to be input (switch). Switch connects GPIO 25 to 3.3 V when pressed and to 0 V when not. Therefore, the LED will be off till we press the button.
Limitations
Some pins are not available for input or output. Check this list.