Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5 (Ser

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
billfred
 
Posts: 12
Joined: Sun Apr 07, 2013 11:13 pm

Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5 (Ser

Post by billfred »

Preface: I do not consider myself a coder by any stretch. I stumbled blindly through getting a FIRST Robotics Competition robot running this spring (because the few students on my team this season were all mechanically-minded), but that's about it for anything past LEGO Mindstorms. Be prepared for rookie mistakes.

My project is to make a Serpente R2 act like a keyboard to an iPad, so I can make a ridiculously cheap accessibility switch interface. (I figure the BOM on this will be about $30; the commercial ones are in the hundreds of dollars.) When I load up this code.py on the board running 6.3.0 and connect it to a Windows 10 PC, the red LED cuts on and all pins output the correct keypresses or strings when grounded.

When connected to an iPad (Pro 11", 3rd generation, iPadOS 14.6) the LED behaves appropriately but does not output any keypresses. It behaves the same way when connected to an iPad mini 5th generation running iPadOS 15 Public Beta 2.

After reading about the changes coming in CircuitPython 7.0.0, I downloaded the alpha (4) on the board and started fiddling with the boot.py file to zap everything but the HID outputs. This boot.py file makes the USB drive disappear, but I now have a new problem: the board isn't running code.py successfully. The LED does not light up beyond a rare faint blue flicker, grounding the pins does not result in keyboard output. Updating to alpha 5 saw the same result. Commenting out the mass storage disable yields the same behavior aside from mounting CIRCUITPY again, which lets me see boot_out.txt behaving appropriately:

Code: Select all

Adafruit CircuitPython 7.0.0-alpha.5 on 2021-07-21; Serpente with samd21e18
boot.py output:
Holla if you hear me! 

Which is fitting, because what's going on makes about as much sense to me as Steiner Math. Can someone point me in the right direction on what's going on?

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by danhalbert »

I don't know why your code.py isn't running, but your boot.py is not checking the pins properly.

You have `if switch3 and switch5:` and you want `if switch3.value and switch5.value:` [CORRECTED]

User avatar
billfred
 
Posts: 12
Joined: Sun Apr 07, 2013 11:13 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by billfred »

Dan,

Thanks for the reply! I just got back to the board in my office and swapped in what you wrote. The boot_out came back with this:

Code: Select all

Adafruit CircuitPython 7.0.0-alpha.5 on 2021-07-21; Serpente with samd21e18
boot.py output:
Traceback (most recent call last):
  File "boot.py", line 9
SyntaxError: invalid syntax
Line 9 being where that code was changed. Did something change with the 7.0.0 beta?

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by danhalbert »

Let's look at your boot.py again, with any changes.

User avatar
billfred
 
Posts: 12
Joined: Sun Apr 07, 2013 11:13 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by billfred »

Cleaned it up a bit, still getting the same results (which, I suppose, is a relief?)

As it sits right now:

Code: Select all

import board
import digitalio
import storage
import usb_midi
import usb_cdc

switch3 = digitalio.DigitalInOut(board.D3)
switch3.pull = digitalio.Pull.UP
switch5 = digitalio.DigitalInOut(board.D5)
switch5.pull = digitalio.Pull.UP

if switch3.value and if switch5.value: 
    storage.disable_usb_drive()
    usb_midi.disable()
    usb_cdc.disable()
    print("Holla if you hear me! \n")
yields non-disabled mass storage and a boot_out of:

Code: Select all

Adafruit CircuitPython 7.0.0-alpha.5 on 2021-07-21; Serpente with samd21e18
boot.py output:
Traceback (most recent call last):
  File "boot.py", line 12
SyntaxError: invalid syntax

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by danhalbert »

My fault - typo, should be ( no second "if")

Code: Select all

if switch3.value and switch5.value:

User avatar
billfred
 
Posts: 12
Joined: Sun Apr 07, 2013 11:13 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by billfred »

Well, now we're getting somewhere! Kinda.

Nuked the typo second if, saved, rebooted the board with no pins grounded.

My Windows 10 PC sees a device connect, but doesn't mount mass storage. It also doesn't turn on the red LED or output keypresses when pins are grounded. I can faintly see the blue LED flicker, like when lightning is bouncing between clouds off in the distance. When I plug it into my iPad (same Pro 11" 3rd gen, but now on iPadOS 14.7.1) and open Notes, I get similar behavior--no red LED, faint flickers of blue LED, and no keypresses when pins are grounded. But it does hide the on-screen keyboard like it does when external keyboards are connected.

The way I have boot.py written, shouldn't it only disable mass storage if D3 and D5 are grounded? (Ultimately, I need the reverse of this but one calamity at a time.)

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by danhalbert »

Billfred wrote:The way I have boot.py written, shouldn't it only disable mass storage if D3 and D5 are grounded? (Ultimately, I need the reverse of this but one calamity at a time.)
No, the `value` is normally high because of the pullup, so if you don't press the buttons, then `if switch3.value and switch5.value` will be True, and it will disable the USB devices. I though that's what you wanted. If you press either button then that button will go to ground (False), and the `if` will be False.

User avatar
billfred
 
Posts: 12
Joined: Sun Apr 07, 2013 11:13 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by billfred »

danhalbert wrote:No, the `value` is normally high because of the pullup, so if you don't press the buttons, then `if switch3.value and switch5.value` will be True, and it will disable the USB devices. I though that's what you wanted.
You thought better than me; that's the behavior I was aiming for. (I wasn't looking for a full Konami code situation, but I did want to make it a little guarded.)

That put me back on "why would this work on 6.3.0 but not any of the 7.0.0 alphas?" Then I tooled around the readthedocs until I found this, emphasis mine: https://circuitpython.readthedocs.io/en ... oting.html
This error occurs when importing a module that is stored as a mpy binary file (rather than a py text file) that was generated by a different version of CircuitPython than the one it’s being loaded into. Most versions are compatible but, rarely they aren’t. In particular, the mpy binary format changed between CircuitPython versions 1.x and 2.x, 2.x and 3.x, and will change again between 6.x and 7.x.

So, for instance, if you just upgraded to CircuitPython 7.x from 6.x you’ll need to download a newer version of the library that triggered the error on import. They are all available in the Adafruit bundle and the Community bundle. Make sure to download a version with 7.0.0 or higher in the filename.
I wasn't getting that error message anywhere I could receive it, but I knew I was using adafruit_hid in there. Sure enough, I updated the Adafruit libraries to work with 7.0.0 and magic started happening almost instantly. My shout of joy may or may not have interrupted my boss meeting with a client on other things.

Thank you so much for all your help with this!

User avatar
danhalbert
 
Posts: 4613
Joined: Tue Aug 08, 2017 12:37 pm

Re: Stumped on HID Keyboard between 6.3.0 and 7.0.0 alpha 5

Post by danhalbert »

Glad you got it working!

I think you would have gotten an "incompatible .mpy" message in the serial output if the libraries were mismatched. It's always a good idea to connect serially when you're having trouble to see what error messages are being printed (hopefully some are).

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”