M5 Red only comes with 1 Port B and I would to use 2 Port B units without the hub which added to the overall formfactor. The two units I need are the Limit Switch unit (U145) and the Vibrator unit (U059) and, fortunately, they are hooked up to a different GPIO pin on Port B. The Limit Switch unit is on GPIO 36 (Input, Whit) while the Vibrator unit is on GPIO 26 (In/Out, Yellow).

Theoretically speaking, if I split a grove cable into 2, I should be able to connect both units to Port B at the same time. I have done this a couple times for other projects to save space, but I do worry the vibrator might draw too much power from the same cable and eventually cause the switch to stop working properly.

It works beautifully.



Programing the vibrator is super fun. I had in my mind the “pew pew pew” sound, and this is what I ended up with. I have not played with the frequency and resolution yet.
[Note to myself] The ESP32 can generate a PWM signal with a frequency of up to 40 MHz. It is currently set to 10000. If the PWM resolution is “n” bits, the timer counts from 0 to 2n-1 before it resets. For example, if we configure the timer with a frequency of 1 Hz and a resolution of 8 bits, the timer will take 1 second to count from 0 to 255 (28-1). In the case of a frequency of 1 Hz and a resolution of 16 bits, the timer will still take 1 second, but it will count from 0 to 65,535 (216-1). The resolution is currently set to 10.
//Vibration
for (int ii = 0; ii < 6; ii++) {
ledcWrite(ledChannel, 512 - ii*40);
delay(40 + ii*10);
}
ledcWrite(ledChannel, 0); // set buzz off