MyWhoosh Virtual Shifting With ESP8266

by gt.grade.alloy in Circuits > Microcontrollers

161 Views, 3 Favorites, 0 Comments

MyWhoosh Virtual Shifting With ESP8266

A02.jpg

Virtual Shifting, as introduced in Version 4 of MyWhoosh under the name MyShift, is a feature that enables you to simulate gear changes during your indoor cycling sessions. This means that you can experience the sensation of shifting gears without physically moving the bike's gears.


How does it work?

- Your trainer automatically adjusts the resistance to mimic the feel of changing gears.

- You can shift virtually using the MyWhoosh app or interface, regardless of the trainer's actual gear setup.

- This feature is accessible to all users across any device and does not require a single-cog trainer setup.


Benefits:

- Adds realism to your indoor rides by simulating different gear settings.

- Simplifies the shifting process since manual gear changes are unnecessary.

- Enhances training variability and experience without additional equipment.


In summary, Virtual Shifting with MyWhoosh makes indoor cycling more immersive and convenient by simulating gear changes electronically, providing a more authentic riding experience.


Using the keyboard or touchscreen for shifting during intense or mountainous rides can be inconvenient and distracting for several reasons:


1. **Focus:** Shifting gears while riding, especially on mountainous routes, requires full attention on the road or trail.


2. **Ease of Access:** Handlebar-mounted gear shifters allow for quick and intuitive gear changes without interrupting your riding rhythm. Keyboard or touchscreen controls are less accessible and require you to stop or alter your riding position, which is impractical during challenging terrain.


3. **Efficiency:** Physical gear shifters on the handlebars provide faster and more precise gear changes. Relying on external devices can introduce delays or miscommunications, hindering your ability to respond promptly to varying terrains.


4. **Riding Experience:** Traditional gearing ensures a smoother riding experience. Using the gear change buttons on a smart trainer or app is designed mainly for convenience or maintenance, not for frequent, real-time gear changes during intense riding.


In summary, sticking to handlebar gear shifters enhances safety, responsiveness, and comfort, especially on demanding routes where quick gear adjustments are essential. External controls are better suited for casual or flat-road riding, or for adjusting resistance during rest periods.

Supplies

To successfully complete the project, you'll need the following components and tools:


1. Hardware:

- ESP8266 NodeMCU module

- USB cable (Micro USB) to connect the NodeMCU to your Windows PC

- Two push-buttons

- Two resistors (commonly 10kΩ for pull-down or pull-up resistors)

- Connecting wires (jumper wires)


2. Software:

- Windows PC with MyWhoosh software installed

- Python 3 installed on your Windows PC

- Arduino IDE installed on your Windows PC

- ESP8266 board package added to Arduino IDE via Board Manager


3. Additional Items:

- Breadboard (optional, for connecting buttons and resistors if you prefer)


Make sure your Windows PC's USB port is working properly and has the necessary permissions to access the NodeMCU.

Installing ESP8266 NodeMCU in Arduino IDE

ArduinoIDE02.png
ArduinoIDE04.png
ArduinoIDE05.png

1. Open the Arduino IDE.

2. Go to **File > Preferences**.

3. In the **Additional Boards Manager URLs** field, paste the following URL:


https://arduino.esp8266.com/stable/package_esp8266com_index.json


4. Click **OK** to close the Preferences window.

5. Navigate to **Tools > Board > Boards Manager**.

6. In the Boards Manager, search for **ESP8266** by **ESP8266 Community**.

7. Click **Install** to install the ESP8266 package.

Configuring the NodeMCU

8. After installation, go to **Tools > Board** and select your specific **NodeMCU** model.

9. Connect your NodeMCU to your computer via USB.

10. Select the correct **COM port** under **Tools > Port**.

Uploading the Program

ArduinoIDE06.png

11. Open a new sketch in Arduino IDE and paste your code:


void setup() {
Serial.begin(115200);
pinMode(D1, INPUT_PULLUP); // Push-button on D1 (upshift)
pinMode(D2, INPUT_PULLUP); // Push-button on D2 (downshift)
}

void loop() {
if (digitalRead(D1) == LOW) { // "i" send
Serial.write('i');
delay(100);
while (digitalRead(D1) == LOW); // Wait until release
}
if (digitalRead(D2) == LOW) { // "k" send
Serial.write('k');
delay(100);
while (digitalRead(D2) == LOW);
}
}

Install Python 3 on Your Windows PC

installer.png

To install Python 3 on your Windows PC with the recommended options, follow these steps:


1. Download Python:

- Go to the official Python website: https://www.python.org/downloads/

- Click on the latest Python 3 release to download the installer suitable for Windows.


2. Run the Installer:

- Locate the downloaded installer file (e.g., `python-3.x.x.exe`) and double-click to run it.


3. Customize Installation:

- On the first installer screen, check the box labeled **"Add Python 3.x to PATH"** at the bottom.

- Click **"Install Now"** for a standard install, or click **"Customize installation"** if you want to see more options.


4. Enable Admin Privileges:

- To run the installer with admin privileges, right-click the installer and select **"Run as administrator"**.

- During the installation, ensure the checkbox for **"Install for all users"** is selected if you want to install Python system-wide (this will prompt for admin rights).


5. Complete the Installation:

- Follow the prompts and wait for the installation to finish.

- Once installed, open Command Prompt and type `python --version` to verify that Python is added to PATH and installed correctly.


**Summary:**


- Download from https://www.python.org/downloads/

- Right-click installer and choose **"Run as administrator"**

- Check **"Add Python to PATH"** during installation

- Proceed with the installation

Install Pyserial and Pyautogui Libraries

To install the `pyserial` and `pyautogui` libraries in Python, follow these steps:


1. Open the Command Line Interface:

- `Win + R`, type `cmd`, and hit Enter.


2. Enter the following command and press Enter:


pip install pyserial pyautogui

"mywhoosh_shifter.py" Script

Enter the following code and save it as "mywhoosh_shifter.py":


import serial
import pyautogui

# Adjust: Check COM port (Windows: Device Manager → "COMx")
ser = serial.Serial('COM3', 115200) # z.B. COM3, COM4, etc.

print("MyWhoosh-Shifter active! Press STRG+C to quit.")

try:
while True:
key = ser.read().decode().strip() # Liest 'i' oder 'k'
if key == 'i':
pyautogui.press('i') # up
elif key == 'k':
pyautogui.press('k') # down
except KeyboardInterrupt:
ser.close()
print("\nShifter stopped.")


My system uses COM Port 3, please check the correct port on your computer and change the port in the "mywhoosh_shifter.py"

Check COM Port

To check and update the COM port used by your system in the "mywhoosh_shifter.py" script, follow these steps:


Verify the COM port on your computer:


1. Open the Device Manager:

`Windows + R`, type `devmgmt.msc`, and press Enter.

2. Expand the section labeled "Ports (COM & LPT)".

3. Look for an entry such as "USB Serial Device (COM3)" or similar.

Wiring Up the ESP8266

ESP8266.jpg

So far, everything regarding the software is complete. Next, the wires are connected to the ESP8266. In this example, pins D1 (GPIO5), D2 (GPIO4), and GND are used.

For the finished circuit, i recommend using 10kΩ pull-down resistors.

Step-by-step Summary of Your First Test Run

mywhoosh_shifter_py.png
test.png
A01.jpg

1. **Setup Connections:**

- For testing, connect the pins D1 and D2 directly to GND.

- You do not need resistors for this initial test.


2. **Running the Script:**

- Open a terminal or the appropriate editor.

- Run the "mywhoosh_shifter.py" script.


3. **Testing the Inputs:**

- Once the script is running, connect D1 to GND.

- Observe if the script detects the connection and generates the keyboard input "i".

- Then, disconnect D1 and connect D2 to GND.

- Confirm if the script generates the keyboard input "k".


4. **Expected Behavior:**

- When D1 is grounded, the script should output or send an "i" keystroke.

- When D2 is grounded, it should output or send a "k" keystroke.


**Tips:**

- Make sure your script is set up to send keystrokes correctly.

- Have a text document or an editor open focused on your target application to see the keystrokes.


If everything is set up correctly, this test verifies that your ESP8266 setup and script are working as intended to convert button presses into keyboard signals.


The successful test run confirms that the system is ready to proceed with testing the ESP8266 with MyWhoosh. Please ensure all connections are secure before starting the integration.


I enjoyed my MyWhoosh test ride overall. The only minor issue was that sometimes one click would shift the gears two steps up or down. However, it was satisfactory for my needs.