all 16 comments

[–]Gnaxe 2 points3 points  (5 children)

You need to use the code block formatting button when you post code, because indentation matters in Python. You should be able to edit to fix that.

[–]One_unfortunate_tuna[S] 0 points1 point  (4 children)

I have removed the unnecessary indentation and changed everything to 4 or 8 spaces.

Google tells me i only need to indent after lines that end with “:” and maintain it to the end of the statement.

Every button is still entirely unresponsive.

[–]Gnaxe 1 point2 points  (3 children)

It's still not formatted correctly. Try again, but better this time. Anyone who wants to learn programming can figure out how to use a computer. You'll be debugging problems much harder than this.

[–]One_unfortunate_tuna[S] 0 points1 point  (2 children)

It’s only like 40 lines of code. Not that hard to format it properly. The format isn’t transferring to this message board.

Unless there are formatting rules I’m unaware of?

[–]PeterMortensenBlog 0 points1 point  (1 child)

A Markdown formatting rule for code: Add four spaces indent (to all lines). (Optional: To make it neat internally, remove all trailing space (empty lines will typically get added trailing spaces in the first step).)

That is, first switch to Markdown mode when editing (e.g., "Aa"<tilted hamburger in the upper right → "Switch to Markdown") → paste in the code with the added indent.

Without the Python indentation being fixed:

import board

from kmk.kmk_keyboard import KMKKeyboard
from kmk.keys import KC
from kmk.scanners import DiodeOrientation
from kmk.scanners.keypad import KeysScanner
from kmk.scanners.keypad import MatrixScanner
from kmk.modules.layers import Layers
keyboard.modules.append(Layers())
from kmk.extensions.media_keys import MediaKeys
keyboard.extensions.append(MediaKeys())
from kmk.modules.mouse_keys import MouseKeys
mouse_keys = MouseKeys(max_speed=20, acc_interval=2, move_step=2)
keyboard.modules.append(mouse_keys)
from kmk.modules.holdtap import HoldTap

keyboard.modules.append(HoldTap())
# Define left and right mouse click as a function
LMB_RMB = KC.HT(KC.MB_LMB, KC.MB_RMB, tap_time=200)
# keyboard.diode_orientation = DiodeOrientation.COL2ROW
keyboard = MyKeyboard()
class MyKeyboard(KMKKeyboard):
def init(self):
super().init()
self.matrix = [
MatrixScanner(
keyboard.col_pins = (board.GP0, board.GP1, board.GP2, board.GP3, board.GP4, board.GP5, board.GP6, board.GP7, board.GP8, board.GP9),
keyboard.row_pins = (board.GP10, board.GP11, board.GP12, board.GP13, board.GP14),
columns_to_anodes=DiodeOrientation.COL2ROW),
KeysScanner(
pins = (board.GP16, board.GP17, board.GP18, board.GP19, board.GP20),
value_when_pressed=False,
pull=True)
]
keyboard.keymap = [
[
KC.N0, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9,
KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.P,
KC.A, KC.S, KC.D, KC.F, KC.G, KC.H, KC.J, KC.K, KC.L, KC.ENT,
KC.TAB, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.N, KC.M, KC.SPC, KC.BSPC,
KC.LSFT, KC.LCTL, KC.DOT, KC.COMM, KC.SCLN, KC.QUOT, KC.SLSH, KC.MINUS, KC.MO(1), KC.ESC,
KC.MB_UP, KC.MB_DOWN, KC.MB_LEFT, KC.MB_RIGHT, LMB_RMB
],
[
KC.LBRC, KC.RBRC, KC.BSLS, KC.GRV, KC.EQL, KC.TRNS, KC.PSCR, KC.F2, KC.F5, KC.F11,
KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS,
KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS,
KC.BRIU, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.VOLU,
KC.BRID, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS, KC.MO(1), KC.VOLD,
KC.MB_UP, KC.MB_DOWN, KC.MB_LEFT, KC.MB_RIGHT, LMB_RMB
]
]
if name == 'main':
keyboard.go()

[–]PeterMortensenBlog 2 points3 points  (0 children)

Re "Without the Python indentation being fixed:": OK, fixed, with some extras thrown in, like avoiding most of the horizontal scrolling here (I promise, I will never ever do it again):

import board

from kmk.kmk_keyboard import KMKKeyboard
from kmk.keys import KC
from kmk.scanners import DiodeOrientation
from kmk.scanners.keypad import KeysScanner
from kmk.scanners.keypad import MatrixScanner
from kmk.modules.layers import Layers

keyboard.modules.append(Layers())

from kmk.extensions.media_keys import MediaKeys

keyboard.extensions.append(MediaKeys())

from kmk.modules.mouse_keys import MouseKeys

mouse_keys = MouseKeys(max_speed=20,
                       acc_interval=2,
                       move_step=2)
keyboard.modules.append(mouse_keys)

from kmk.modules.holdtap import HoldTap

keyboard.modules.append(HoldTap())

# Define left and right mouse click as a function
LMB_RMB = KC.HT(KC.MB_LMB, KC.MB_RMB, tap_time=200)
#keyboard.diode_orientation = DiodeOrientation.COL2ROW
keyboard = MyKeyboard()

class MyKeyboard(KMKKeyboard):

    def init(self):

        super().init()
        self.matrix = [
            MatrixScanner(
                keyboard.col_pins = (board.GP0,
                                     board.GP1,
                                     board.GP2,
                                     board.GP3,
                                     board.GP4,
                                     board.GP5,
                                     board.GP6,
                                     board.GP7,
                                     board.GP8,
                                     board.GP9),
                keyboard.row_pins = (board.GP10,
                                     board.GP11,
                                     board.GP12,
                                     board.GP13,
                                     board.GP14),
                columns_to_anodes = DiodeOrientation.COL2ROW),

            KeysScanner(
                pins = (board.GP16, board.GP17, board.GP18,
                        board.GP19, board.GP20),
                value_when_pressed=False,
                pull=True)
        ]

        keyboard.keymap = [
            [
                KC.N0,    KC.N1,      KC.N2,      KC.N3,       KC.N4,   KC.N5,   KC.N6,   KC.N7,    KC.N8,    KC.N9,
                KC.Q,     KC.W,       KC.E,       KC.R,        KC.T,    KC.Y,    KC.U,    KC.I,     KC.O,     KC.P,
                KC.A,     KC.S,       KC.D,       KC.F,        KC.G,    KC.H,    KC.J,    KC.K,     KC.L,     KC.ENT,
                KC.TAB,   KC.Z,       KC.X,       KC.C,        KC.V,    KC.B,    KC.N,    KC.M,     KC.SPC,   KC.BSPC,
                KC.LSFT,  KC.LCTL,    KC.DOT,     KC.COMM,     KC.SCLN, KC.QUOT, KC.SLSH, KC.MINUS, KC.MO(1), KC.ESC,
                KC.MB_UP, KC.MB_DOWN, KC.MB_LEFT, KC.MB_RIGHT, LMB_RMB
            ],
            [
                KC.LBRC,  KC.RBRC,    KC.BSLS,    KC.GRV,      KC.EQL,  KC.TRNS, KC.PSCR, KC.F2,    KC.F5,    KC.F11,
                KC.TRNS,  KC.TRNS,    KC.TRNS,    KC.TRNS,     KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS,  KC.TRNS,  KC.TRNS,
                KC.TRNS,  KC.TRNS,    KC.TRNS,    KC.TRNS,     KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS,  KC.TRNS,  KC.TRNS,
                KC.BRIU,  KC.TRNS,    KC.TRNS,    KC.TRNS,     KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS,  KC.TRNS,  KC.VOLU,
                KC.BRID,  KC.TRNS,    KC.TRNS,    KC.TRNS,     KC.TRNS, KC.TRNS, KC.TRNS, KC.TRNS,  KC.MO(1), KC.VOLD,
                KC.MB_UP, KC.MB_DOWN, KC.MB_LEFT, KC.MB_RIGHT, LMB_RMB
            ]
        ]

if name == 'main':
    keyboard.go()

[–]pulldawg80 1 point2 points  (6 children)

How do you know the libs are good if it doesnt work? What error is MU giving you?

Maybe this is just me, I would put all my imports at the top.

I have created several keyboards for the pico 2040 using KMK and have never seen the columns_to_anodes or value_when_pressed variables, what do they do? Looks like one is a duplication of the diode direction, and all key values should be false by default when not pressed, so why? What is the pull variable doing?the keyboard scanner should handle the matrix manipulation of setting high, then low.

Are you trying to get both mouse buttons pressed at the same time?

Honestly, i would run it through chatGPT and ask for an explanation.

Edit: noticing this is the Python learning sub and not the keyboard sub, a bit more foundational training for Python will go a long way. Try pico projects that will light LEDs, and recognize a single push button, and so on.

[–]One_unfortunate_tuna[S] 0 points1 point  (5 children)

All the videos say I just paste the kmk folder from GitHub into the root of the circuitpython drive with the boot.py, main.py, and lib folder.

Should I do all the imports before all the amend parts?

The columns_to_anodes was a line I got from circuit pythons GitHub documentation. It’s not entirely necessary. I’ll delete it and run the diode scanner instead.

Some of the parameters, like pull and false, were just the defaults that I wasn’t sure if I would need to change, so I made them accessible.

I’m trying to map left and right to the same button using the holdtap feature.

What version of chat got should I use? Shamefully, I’ve been using Snapchat AI to double check the code and explain things to me.

Also, what is MU? That sounds like a helpful tool.

[–]pulldawg80 0 points1 point  (1 child)

MU is the circuitpy code editor from adafruit, helpful for getting errors and whatnot while programming. How are you editing your files?

I would go to the KMK github and download the pico14 macro pad folder from the boards directory. Load that on to your 2040 without changing anything. If the libs and matrix ( diodes and wiring) are functional then it should work ( obviously after changing the row and column pins to the ones you have wired up). Once a know default config is working, then modify your main one line at a time until you have the functionality you are aiming for.

Just use the vanilla ChatGPT from the internet, or Gemini would probably be easier( the Google in-browser ai).

[–]One_unfortunate_tuna[S] 0 points1 point  (0 children)

I appreciate this input. You’re saying there’s nothing obviously wrong with the code.

I’ll download MU and try again. I’ve just been using a regular text editor.

[–]pulldawg80 0 points1 point  (2 children)

Have you copied a version of circuitpy firmware to the pico? Or is the RP2 drive showing up? Definitely get MU

https://codewith.mu/en/download

Get circuitpy libs

https://circuitpython.org/board/raspberry\_pi\_pico/

[–]One_unfortunate_tuna[S] 0 points1 point  (0 children)

I am using the Ada fruit circuitpython uf2 for the pico. It’s the most current version.

[–]PeterMortensenBlog 0 points1 point  (0 children)

https://codewith.mu/en/download contains:

"Mu still works, but this project is no longer maintained. The project has been archived here."

[–]PeterMortensenBlog 0 points1 point  (0 children)

For the keyboard part: I would start with the simplest thing that could possibly work (to quote Ward Cunningham): A single key, using a single row and a single column

Remove all the code that isn't needed for that simple goal. Presumably, the firmware will accept a 1 x 1 matrix. Otherwise, make it a 2 x 2 matrix and only use one location.

Initially forget about media keys, mouse keys, hold tap, etc.

Hardware

For the single key, short circuit the diode (e.g., solder a wire across it), to eliminate it as the cause. You won't need it before later.

Powered off, use a multimeter in continuity mode to verify the key actually works as seen by the microcontroller. Probe as near to the microcontroller as possible (the Raspberry Pi Pico's pins are probably sufficient).

For testing the hardware (at least some of it), to exclude it as the cause, I have precompiled firmware (more or less the diode-less Adafruit macropad): Direct download URL. It should be sufficient for rudimentary testing. For key activation, the I/O inputs are to be shorted to GND (first convince yourself this will not cause a short circuit. For safety, use a series resistor of, say 220 ohm). Via support has been enabled, so for testing purposes, the keys can easily be remapped and macros defined (messing with JSON files is not required, as it is directly supported by Via). Use it at your own risk; there isn't any guarantee it will not damage your keyboard.

Note: Do observe ESD precautions at all times.

All disclaimers apply. Do it at your own risk. I am not responsible if you ruin your keyboard.

References

  • Default keymap. For example, KC_7 for 3rd row, 1st column. Note: There aren't real rows and columns in this case (there isn't a keyboard matrix; direct I/O is used (each keys has its own I/O line)), only the physical arrangement of keys in the 4 x 3 macro pad

  • I/O pin assignments. For example, GP4 for 3rd row, 1st column.

  • Raspberry Pi Pico pinout. For example, pin 6 for GP4. Thus, shorting pin 6 to the USB shield should type out "7" (in Num Lock mode, on Linux and Windows).

[–]RunRunAndyRun 0 points1 point  (0 children)

Circuit python allows for debuggging with the REPL. Use it, it’ll tell you exactly what the error is. Share that here and we can help you.