I got my RP2040 Connect a few weeks ago for a project I'm working on that will require tilt and acceleration measurements. While I'm not an Arduino guru, I know some things, so I skipped the example sketches and ran the LSM6DSOX library, wrote some other sketches, etc. and they all worked fine.
The issue:
Since I was hoping to use this as an HID USB Keyboard (or Gamepad if need be), I tried running the Hello World example sketch. This caused the board to spam send Hello World (and enter) over and over (my friends on discord were confused at the messages). It also blocked the COM port, so I couldn't write to the device.
Steps taken:
First I tried unplugging the device, but upon reconnect the same thing happened; ditto for pressing the rest button. In the documentation they describe how you can reset the board and re-upload the blink sketch. After doing this, I tried the Hello World example sketch again (to check if it was a weird glitch or not), and I got the same results as before.
Question:
Is anyone else having/had this issue?
I mostly ask because a given example sketch should work with the board. Not to sound like an ass, but since Arduino's goal is to make it easy for people to get started, something like this should probably be fixed ASAP.
Sidenote Question:
Is there an HID USB library that would be better to use? Spent the past few weeks (a few hours a day) reading through the USB and HID documentation, and I think I'm finally understanding it; if I'm correct, the HID library provided only allows for 6-key rollover, which may not be enough for what I want/need.
Here it is directly on the getting started / "cheat sheet"
Below is the code from the example directly in arduino's IDE.
#include "PluggableUSBHID.h"
#include "USBKeyboard.h"
USBKeyboard Keyboard;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
Keyboard.printf("Hello world\n\r");
}
I'm gonna be blunt. It looks like you didn't read the post, just posted to be rude, or both. Similar to the guy above, though he's not being rude about it, which is why I didn't correct him when his initial post said "infinite loop" without explaining that all (or nearly all) arduinos run them.
Blockquote What else did you expect if the code endlessly sends the same line to the port?
I have code that endlessly sends information to the same port that doesn't prevent me from re-writing to the board unless I put it into "recovery"/"safe" mode. The code was from an Arduino provided example, and I was hoping to bring attention to the behavior if it wasn't known this is how it acts, and it wasn't just my board behaving aberrantly.
Me to.
This is NOT an error with the code, there is no need to fix it.
This is an error in you understanding the code and what it does.
I don't think they missed it basically because it doesn't. To get out of this loop hold down the reset button when powering up the board. This is tricky to do because you have to hold down the reset button while you insert the power lead. With only two hands it is hard,
So I have made a special small board that puts a switch in line with the USB + power. Depending on how you program it you have to do this a lot.
Hi @sakuyarules. There was a previous report about the behavior of this sketch not being user friendly:
There is an outstanding PR to mitigate that by adding a delay on startup:
However, as explained by the developer in the issue report, there is a better approach which was already established in the examples of the standard Arduino "Keyboard" library:
You can see an example of such a control system in this example:
This would be a matter of adding only a few simple lines of code to the example sketch.
I think it is likely a pull request for such a change submitted to the arduino/ArduinoCore-mbed repository would be accepted if anyone would like an opportunity to contribute to this free open source software project:
Thank you for the response, I would be happy to make a submission! I've been looking through the new HID code (there is a comment somewhere in the code about this being a modernized HID library); since it's different than the old keyboard library I'm still working through the methods. When I fully understand the methods for creating and sending the HID report it I'll take your advice make a submission.
And thank you @sterretje . I've avoided forums for years because elitism and condescension are usually rampant; was hoping that wouldn't be the case here, but well, that's just life I guess.
Since I've rarely used github, I probably have some setting incorrect, but it's not letting me clone the mbed library. So I'll upload the file here; when I figure out what I've done wrong I'll submit a pull request. example_hid_keyboard.ino (3.1 KB)
If you would like assistance with that problem, I'm happy to help. Just give me some more details about what you tried and what type of problem you encountered while doing that.
It looks like you have made some nice enhancements to the sketch!
I have a suggestion, which is good practices for pull requests in general: make sure to submit a separate pull request for each distinct (AKA "atomic") change you wish to propose, rather than unnecessarily combining multiple changes into a single pull request.
For example, I would submit a dedicated pull request for adding the control system on pin 2.
This approach makes it easier for maintainers to evaluate your proposal, which means they are more likely to make the time for this essential step in getting it accepted. It also avoids the chance that one of multiple changes might act as a "poison pill" that blocks acceptance of other distinct changes which would otherwise have been quickly merged by the maintainer.
I appreciate it! The command I ran and the output is in the blockquote below. Using GitHub Desktop I was able to clone the repository, so I probably don't have something set correctly in the command line config; as long as GitHub Desktop keeps working this is more of a minor snag than a problem.
git clone git@github.com:arduino/ArduinoCore-mbed mbed
Cloning into 'mbed'... git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Luckily, I wrote this as a completely new file, so adding things in piecewise should be easy!
Your suggestion makes a lot of sense; I'll remember it, thank you. I'll start with the control pin and wrapping the print in an if conditional. I'm thinking importing mbed.h would be its own atomic change, does that sound right? Just want to make sure I'm not spamming pull requests.
The person who wrote that documentation made it unnecessarily complex by using the SSH protocol. This requires some complex setup on your system which is basically pointless for this specific application.
You can use HTTPS instead without any special set up:
If you want to go even more simple, you can just use the GitHub web interface to edit the file directly in your fork of the repository, without ever having to use Git directly. That approach is very limiting when the proposal involves editing multiple files, but in this case when only a single file is being edited, it might be the most convenient.
The first step is to create a GitHub account if you don't have one already:
After signing in to your GitHub account, you will see a icon on the toolbar of the page for each file in the repositories on GitHub.
So you can open the page for the sketch in question:
As you might expect, this does not allow you to edit Arduino's files directly. Instead what it does is makes a fork of the https://github.com/arduino/ArduinoCore-mbed GitHub repository under your own account, and then allows you to edit the file in your fork.
Once you have edited the file in your fork, you can use a pull request to propose that change be made in Arduino's repository:
Again, thank you very much! Submitted the request. There are some automated checks that ran, and it seems I failed 1 of the 7. I'm not entirely sure what this is though:
Compile Examples / compile-examples (arduino:mbed:envie_m7) (pull_request) Failing after 8m
Some of the listed failures were: Doom, and Camera
I greatly appreciate all the help! It's submitted and if approved, I'll try to follow it up with atomic changes as you suggested.
This recent change to the code caused the breakage:
I don't know whether it was overlooked at that time, or if this is a temporary situation while waiting for some other planned change that will restore the compilations to a passing state again.
Either way, you don't need to be concerned about the failure. The important thing is that no new failures were introduced by the changes you made.