[{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch2\u003eBackground\u003c/h2\u003e\n\u003cp\u003eI have an older laptop that has a trackpad, but it is not clickable. You have to use the buttons below it. It is quite awkward in general, more so for drag and drop operations. Let's build some alternative mouse buttons to help. With this project you can move the mouse with your usual hand and click with your other hand. This guide covers USB HID Mouse, Debounce, and NeoKeys.\u003c/p\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch2\u003eHardware\u003c/h2\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cstrong\u003eFeather RP2040\u003c/strong\u003e: A powerful microcontroller board featuring the RP2040 chip. \u003ca href=\"https://www.adafruit.com/product/4884\"\u003eRP2040 Feather\u003c/a\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eNeoKey 1x4\u003c/strong\u003e: A small breakout board with four mechanical key switches, each with a NeoPixel LED. \u003ca href=\"https://www.adafruit.com/product/4980\"\u003eNeoKey 1x4\u003c/a\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eUSB Cable\u003c/strong\u003e: To connect the Feather RP2040 to your computer.\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eSTEMMA QT Cable:\u003c/strong\u003e To connect the NeoKey 1x4 to the Feather. \u003ca href=\"https://www.adafruit.com/product/4210\"\u003eSEMMA QT Cable\u003c/a\u003e\n\u003c/li\u003e\n\u003cli\u003eKey Switches: Many to choose from. You will need 4.\u003c/li\u003e\n\u003cli\u003eKey Caps: Your pick. You will need 4.\u003c/li\u003e\n\u003c/ol\u003e\n\u003ch2\u003eSetup\u003c/h2\u003e\n\u003col\u003e\n\u003cli\u003ePlug the key switches into the NeoKey 1x4. See \u003ca href=\"https://learn.adafruit.com/neokey-1x4-qt-i2c\"\u003eNeoKey 1x4 Guide\u003c/a\u003e for instructions.\u003c/li\u003e\n\u003cli\u003eConnect the NeoKey 1x4 to the RP2040 Feather using the STEMMA QT cable.\u003c/li\u003e\n\u003cli\u003eConnect the RP2040 Feather to your computer using the USB cable.\u003c/li\u003e\n\u003cli\u003eInstall a recent version of CircuitPython: See \u003ca href=\"https://circuitpython.org/board/adafruit_feather_rp2040/\"\u003ecircuitpython.org\u003c/a\u003e for details.\u003c/li\u003e\n\u003c/ol\u003e\n      \n\n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n  \n        \u003ch2\u003eSoftware\u003c/h2\u003e\n\u003cp\u003eUse `circup` to install the following:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003eadafruit-circuitpython-neokey\u003c/li\u003e\n\u003cli\u003eadafruit-circuitpython-debouncer\u003c/li\u003e\n\u003cli\u003eadafruit-circuitpython-hid\u003c/li\u003e\n\u003c/ol\u003e\n      \n\n\n\n\n\n\n\n\n\n\n","metadata":{}},{"element_type":"code","content":"# code.py\nimport app","metadata":{"language":"python","linenums":false}},{"element_type":"code","content":"# SPDX-FileCopyrightText: Copyright (c) 2023 Randall Bohn (dexter)\n#\n# SPDX-License-Identifier: MIT\n\n# app.py\nimport board\nfrom adafruit_neokey.neokey1x4 import NeoKey1x4\nfrom adafruit_debouncer import Debouncer\nfrom adafruit_hid.mouse import Mouse\nimport usb_hid\n\n# %% setup\ni2c = board.I2C()\nneokey = NeoKey1x4(i2c)\n# colors for keys\nIDLE=0xFF3399\nACTIVE=0xFF3333\nfor x in range(3):\n\tneokey.pixels[x] = IDLE\nneokey.pixels[3] = 0\n\n# Mouse Buttons\n# 1 is the 'primary' button, 2 is the 'secondary', 3 is the 'middle'.\n# Left Hand Mouse: [2] [3] [1]\n# Right Hand Mouse: [1] [3] [2]\nmb1 = Debouncer(lambda: not neokey[0])\nmb3 = Debouncer(lambda: not neokey[1])\nmb2 = Debouncer(lambda: not neokey[2])\nmouse = Mouse(usb_hid.devices)\n\nwhile True:\n    mb1.update()\n    mb2.update()\n    mb3.update()\n\n    if mb1.fell:\n        mouse.press(Mouse.LEFT_BUTTON)\n        neokey.pixels[0]=ACTIVE\n    if mb1.rose:\n        mouse.release(Mouse.LEFT_BUTTON)\n        neokey.pixels[0]=IDLE\n    if mb3.fell:\n        mouse.press(Mouse.MIDDLE_BUTTON)\n        neokey.pixels[1]=ACTIVE\n    if mb3.rose:\n        mouse.release(Mouse.MIDDLE_BUTTON)\n        neokey.pixels[1]=IDLE\n    if mb2.fell:\n        mouse.press(Mouse.RIGHT_BUTTON)\n        neokey.pixels[2]=ACTIVE\n    if mb2.rose:\n        mouse.release(Mouse.RIGHT_BUTTON)\n        neokey.pixels[2]=IDLE","metadata":{"language":"python","linenums":false}},{"element_type":"text","content":"\n  \n  \n  \n  \n  \n  \n        \u003col\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eSetup\u003c/strong\u003e: Initializes the I2C connection, the NeoKey1x4, and sets up initial colors for the keys.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eMouse Button Configuration\u003c/strong\u003e: Uses the \u003ccode\u003eDebouncer\u003c/code\u003e class for each button to accurately detect press and release actions without false triggering due to \"bouncing\" of the switch.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eMain Loop\u003c/strong\u003e:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eContinuously checks the state of each button.\u003c/li\u003e\n\u003cli\u003eIf a button is pressed (\u003ccode\u003efell\u003c/code\u003e), it sends a corresponding mouse press command and changes the NeoPixel color to \u003ccode\u003eACTIVE\u003c/code\u003e.\u003c/li\u003e\n\u003cli\u003eWhen the button is released (\u003ccode\u003erose\u003c/code\u003e), it sends a mouse release command and resets the NeoPixel color to \u003ccode\u003eIDLE\u003c/code\u003e.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003cli\u003e\n\u003cp\u003e\u003cstrong\u003eButton Mapping\u003c/strong\u003e:\u003c/p\u003e\n\u003cul\u003e\n\u003cli\u003eThe first button (index 0) acts as the left mouse button.\u003c/li\u003e\n\u003cli\u003eThe second button (index 1) acts as the middle mouse button.\u003c/li\u003e\n\u003cli\u003eThe third button (index 2) acts as the right mouse button.\u003c/li\u003e\n\u003cli\u003eThe fourth button (index 3) doesn't have an assigned action and remains unlit.\u003c/li\u003e\n\u003c/ul\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n      \n\n\n\n\n\n","metadata":{}},{"element_type":"text","content":"\n        \u003ch2\u003eNext Steps\u003c/h2\u003e\n\u003cp\u003eHere are some ideas for extending the project:\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\n\u003cstrong\u003eCustomizable Button Functions\u003c/strong\u003e\u003cspan\u003e: Add the ability to customize what each button does, such as implementing double-clicks, drag-and-drop actions, or even programmable macros.\u003c/span\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003cspan\u003e\u003cstrong\u003eWireless Capability\u003c/strong\u003e: Explore adding wireless functionality using Bluetooth or Wi-Fi, turning it into a portable, wireless device.\u003c/span\u003e\u003c/li\u003e\n\u003cli\u003e\u003cspan\u003e\u003cstrong\u003eUser Interface for Settings\u003c/strong\u003e: Develop a small graphical user interface (GUI) that can run on a connected computer, allowing users to easily change settings like button mappings and LED colors.\u003c/span\u003e\u003c/li\u003e\n\u003cli\u003e\u003cspan\u003e\u003cstrong\u003eSound Feedback\u003c/strong\u003e: Integrate sound feedback for button presses using a small speaker or buzzer, which could be especially helpful for users with visual impairments.\u003c/span\u003e\u003c/li\u003e\n\u003cli\u003e\u003cspan\u003e\u003cstrong\u003eBattery Power\u003c/strong\u003e: Add a battery and charging circuit to make the device fully portable.\u003c/span\u003e\u003c/li\u003e\n\u003cli\u003e\u003cspan\u003e\u003cstrong\u003eErgonomic Design\u003c/strong\u003e: Design a custom 3D-printed case that is ergonomically shaped for comfort during extended use.\u003c/span\u003e\u003c/li\u003e\n\u003cli\u003e\n\u003cstrong\u003eKey\u003c/strong\u003e 4: Find a use for the fourth key.\u003c/li\u003e\n\u003c/ol\u003e\n      ","metadata":{}},{"element_type":"markdown","content":"\u003ch2\u003eTesting\u003c/h2\u003e\n\n\u003cp\u003eTesting and troubleshooting are crucial steps in any electronics project. Here are some tips for effectively testing and troubleshooting your mouse button project:\u003c/p\u003e\n\n\u003col\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eIncremental Testing\u003c/strong\u003e: Test each component separately before integrating them. First, ensure that the NeoKey 1x4 is responding to button presses, then test the mouse click functionalities.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eVisual Feedback\u003c/strong\u003e: Use the NeoPixels on the NeoKey 1x4 to provide visual feedback for button presses. This can help you quickly determine if the buttons are functioning correctly.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eConsole Debugging\u003c/strong\u003e: Utilize print statements in your CircuitPython code to output debugging information to the serial console. This can help you track the state of your program and button presses.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eCheck Connections\u003c/strong\u003e: Ensure all wiring connections are secure. Loose or incorrect connections are common issues in hardware projects.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003ePower Supply\u003c/strong\u003e: Verify that your RP2040 Feather is receiving adequate power and that the power supply is stable.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eUpdate Firmware and Libraries\u003c/strong\u003e: Ensure that the Feather's firmware and all libraries (NeoKey, Debouncer, HID) are up-to-date, as older versions might have bugs or compatibility issues.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eCode Review\u003c/strong\u003e: Double-check your code for logical errors or misconfigurations, especially in the button mapping and debouncing logic.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eExternal Testing Tools\u003c/strong\u003e: Consider using tools like a multimeter to check for continuity and correct voltages in the circuit.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eSeek Community Help\u003c/strong\u003e: If you're stuck, consider asking for help from online communities like Adafruit Discord.\u003c/p\u003e\u003c/li\u003e\n\u003cli\u003e\u003cp\u003e\u003cstrong\u003eDocument Issues and Solutions\u003c/strong\u003e: Keep a record of the issues you encounter and how you resolve them. This documentation can be invaluable for future projects or for others who might work on similar projects.\u003c/p\u003e\u003c/li\u003e\n\u003c/ol\u003e\n\n\u003cp\u003eRemember, troubleshooting can be a learning experience. Stay patient and methodical, and you'll likely find a solution to any issue you encounter. 🛠️🔍🎉\u003c/p\u003e\n","metadata":{"markdown":"## Testing\n\nTesting and troubleshooting are crucial steps in any electronics project. Here are some tips for effectively testing and troubleshooting your mouse button project:\n\n1. **Incremental Testing**: Test each component separately before integrating them. First, ensure that the NeoKey 1x4 is responding to button presses, then test the mouse click functionalities.\n\n2. **Visual Feedback**: Use the NeoPixels on the NeoKey 1x4 to provide visual feedback for button presses. This can help you quickly determine if the buttons are functioning correctly.\n\n3. **Console Debugging**: Utilize print statements in your CircuitPython code to output debugging information to the serial console. This can help you track the state of your program and button presses.\n\n4. **Check Connections**: Ensure all wiring connections are secure. Loose or incorrect connections are common issues in hardware projects.\n\n5. **Power Supply**: Verify that your RP2040 Feather is receiving adequate power and that the power supply is stable.\n\n6. **Update Firmware and Libraries**: Ensure that the Feather's firmware and all libraries (NeoKey, Debouncer, HID) are up-to-date, as older versions might have bugs or compatibility issues.\n\n7. **Code Review**: Double-check your code for logical errors or misconfigurations, especially in the button mapping and debouncing logic.\n\n8. **External Testing Tools**: Consider using tools like a multimeter to check for continuity and correct voltages in the circuit.\n\n9. **Seek Community Help**: If you're stuck, consider asking for help from online communities like Adafruit Discord.\n\n10. **Document Issues and Solutions**: Keep a record of the issues you encounter and how you resolve them. This documentation can be invaluable for future projects or for others who might work on similar projects.\n\nRemember, troubleshooting can be a learning experience. Stay patient and methodical, and you'll likely find a solution to any issue you encounter. 🛠️🔍🎉"}},{"element_type":"text","content":"\n  \n        \u003ch2\u003eCredits\u003c/h2\u003e\n\u003cp\u003eI referred to various guides on this project. I had to check the adafruit_hid source code for details on using the Mouse. \u003ca href=\"https://chat.openai.com/share/72f8d8e4-49c1-4967-b5e2-31e12a6b9d61\"\u003eProtoEngineer \u003c/a\u003ewrote the Next Steps and Testing sections.\u003c/p\u003e\n      \n","metadata":{}}]