In my project I have over 200 line of simple action code like pressing A button and wait for 2 second, but I found out that after I compiled it into hex file and load it to my uno r3, the device is doesn’t respond or pressing one action nonstop.
I think it’s out of memory so I want to ask the expert how to code more effectively to minimize memory usage. The flash size of 32kb isn’t a problem, just the memory is halting me.
Extra question: I have quite a few repeated action so for example the DOWN key. Please point me to a right direction.
Sdokdyg5656:
Thanks you for replying, I uses Atmel studio7 to edit c++ file and use make file command to product hex file for my uno r3 to run.
Have you been able to successfully program a UNO with Atmel before?
Have you developed your code in sections, and got each section working on the UNO, before combining them?
Tom...
This is about the 4th thread you have open on this project, and while they haven't been quite identical enough to get you in trouble for cross-posting, neither have any of them really been sufficient to help you very much, either. Here's what I've been able to piece together:
The project is a USB Joystick "spoofer" for Nintendo switch. You play your game, come to some point that requires a boring amount of repetitive action, so you plug in an arduino, and it performs them for you.
The project isn't really an Arduino project; it runs entirely on the 16u2 co-processor of the Uno.
It's not C++, and it's not set up for Atmel Studio, either. Straight CLI Makefiles.
It's for the 16u2 that's on the Uno, not for the 32u4 that's on a "Pro Micro" (hoping that you have a "realish" Pro Micro, rather than a badly named Pro Mini clone (which wouldn't support USB at all.)
In its current state, you load up separate programs (.hex files, via DFU programmer/bootloader) to the 16u2 for each "spoofed action" that you want, and "plug it in" to start it. Not convenient, and this is one of the things the OP would like to change - separate buttons for each action instead.
The "code" that has been posted in each thread is the table of individual events/delays needed for a particular action. It's currently not stored in PROGMEM, so it quickly eats up the RAM of the 16u2.
There's substantial additional code, using LUFA, to do the USB Joystick emulation, as well as the code to read the event table and turn them into commands.
Since the program currently runs on the 16u2, it doesn't have any access to to the actual digital "Pins" of an Uno, so adding actual buttons to the existing code would require significant additional work (some sort of communications between the 328p and the 16u2 (serial, presumably), and an Arduino sketch to read the buttons and send the info to the 16u2.) Running on a 32u4 (Pro Micro) would be ... different than that.
Tutorial-wise, in terms of "how to compile and upload to the 16u2 of an Uno", the Github Project is pretty good. The code itself is so-so, I guess.
The owner of the GitHub project (can't tell if that's the same as Sdokdyg5656) already says that the "releasebox" "script" doesn't work due to memory limitations.
So if the goal is to have a set of "cheat" buttons on a Pro-Micro, there are three parts to the problem, approximately:
Move script data structures to PROGMEM
Add support for Buttons.
Port Code from 16u2 to Pro-Micro, perhaps using Atmel Studio, perhaps even using the Arduino IDE.
None of these are "really difficult", but from what we've seen, they seem like they are probably beyond the skills of the OP. It's a relatively interesting project from the coding side, but I don't have the gaming skills or equipment to use or test it at all.
It might be easier to extract the scripts iand script player nto an Arduino-based Pro-Micro sketch (using one of the available "USB joystick libraries"), rather than modifying the pure C code to run on a more Arduino platform.
It's astonishing how fast this little side project has been discovered by others :o
All statements of "westfw" are correct so far.
I've created this project also based on a prototype and just reorganized it in a more convenient way than it was before. one hex = one bot. And so far it has fulfilled my simple needs perfectly.
At the moment of writing this I must say that I have very little experience in programming Arduinos what so ever. But because there seems to be at least some interest, I'm motivated to acquire some further knowledge in this field.
westfw thank you for the tip with the PROGMEM, I will try it later. I also appreciate the nice words about the tutorial
BTW, "PROGMEM" would be needed for C++ programs (ie a native Arduino environment.)
As per the patch I submitted, "__flash" is easier for a pure C program.
The difference is that with PROGMEM, you need special functions to access the data as well as the special declaration. With __flash, the compiler will access the data properly automatically.