Arduino 101: coding cheat sheet language defining variable int this semicolon ends the command. This is the new name. Pick one that makes sense to you. Corrections, suggestions, and new documentation should be posted to the Forum. The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.Code samples in the reference are released into the public domain. A nice cheat sheet was posted a couple of years ago too. Got a link to it somewhere. Jeroen Doggen has designed an Arduino Cheat Sheet which gives an overview of the most important Arduino commands and syntax. Arduino Cheat Sheet –.
Program Execution
I really love cheat sheets. In a lot of cases they can take the place of an entire manual. So I was surprised, given its popularity that I couldn't find a single-page reference for the arduino online. I tried to make a sheet that captured all the things I hit the reference for while programming. What data type does the millis function return?
Arduino Commands Cheat Sheet Free
Command | Short form | Description |
---|---|---|
continue | c | Run the program |
advance setup | adv setup | Run the program and stop at the beginning of setup() * |
next | n | Execute the next line of code (step over) |
step | s | Step into the next line of code |
finish | fin | Run the program until the current function returns (step out) |
nexti | n | Execute the next instruction (step over) |
stepi | si | Step into next instruction |
until | u | Like next , but doesn't go back in loops |
Ctrl+C | Break the program at the current instruction |
* The advance
command will also stop if the current function returns
Breakpoints
Command | Short form | Description |
---|---|---|
info breakpoints | i b | Display a list of all the breakpoints |
break loop | b loop | Set a breakpoint at the beginning of loop() |
break 42 | b 42 | Set a breakpoint in line 42 |
break *0x156 | b *0x156 | Set a breakpoint at program address 0x156 |
tbreak loop | tb loop | Set a one-time (temporary) breakpoint in loop() |
clear loop | cl loop | Delete any breakpoints on loop() |
clear 42 | cl 42 | Delete any breakpoints on line 42 |
delete 1 | d 1 | Delete breakpoint number 1 |
disable | dis | Disable all breakpoints |
disable 1 | dis 1 | Disable breakpoint number 1 |
enable | en | Enable all breakpoints |
enable 1 | en 1 | Enable breakpoint number 1 |
enable once 1 | en once 1 | Enable breakpoint number 1 for a single hit |
Call Stack
Command | Short form | Description |
---|---|---|
backtrace | bt | Display a backtrace of the current call stack |
backtrace -full | bt -fu | Display backtrace including local variables |
info args | i ar | Dump the arguments of the current function |
info locals | i lo | Dump local variables and their values |
info registers | i r | Dump MCU registers |
faas info args | fa i ar | Dump the arguments of all functions in the call stack |
frame 2 | f 2 | Select frame number 2 |
up | Go one stack frame up (e.g. calling function) | |
down | do | Go one stack frame down |
Inspecting Code
Command | Short form | Description |
---|---|---|
list loop | l loop | Show the source code of loop() |
disassemble | disas | Disassemble the current program location |
disassemble/s | disas/s | Disassemble including source code |
disassemble/r | disas/r | Disassemble including opcodes (in hex) |
disassemble loop | disas loop | Disassemble the loop() function |
Inspecting Data
Command | Short form | Description |
---|---|---|
print $pc | p $pc | Print the value of PC (Program Counter) |
print $r0 | p $r0 | Print the value of the R0 register |
print i | p i | Print the value of the variable i |
print PORTB | p PORTB | Print the value of the I/O register PORTB |
dprint loop,'Loopn' | dp … | Print 'Loop' every time loop() starts |
dprint loop,'%dn',i | dp … | Print the value of i every time loop() starts |
x/16b $sp | Dump 16 memory bytes starting at $sp (stack pointer) | |
x/10w 0x800200 | Dump 10 dwords starting at data space address 0x200 | |
x/s 0x800151 | Dump a string from the data space address 0x151 | |
display someVar | disp someVar | Display the value of someVar whenever the program stops |
info display | i di | List active auto-display (watch) expressions |
delete display 1 | d d 1 | Delete auto-display expression number 1 |
Modifying Data
Command | Short form | Description |
---|---|---|
set i = 0 | s i=0 | Change the value of variable i to 0 |
set $pc = 0 | s $pc=0 | Jump to the beginning of the program |
set $r12 = 0x55 | s $r12=0x55 | Set r12 to 0x55 |
set PORTB = 0xff | s PORTB=0xff | Set PORTB (I/O register) to 0xff |
set {int}0x800200 = 50 | s … | Set an integer at dataspace address 0x200 to 50 |
Text User Interface (TUI)
Command | Short form | Description |
---|---|---|
tui enable | tu e | Enabled the TUI mode (also Ctrl X+A) |
tui disable | tu d | Enabled the TUI mode (also Ctrl X+A) |
tui reg all | tu r a | Display registers window |
layout asm | la a | Switch to Assembly view |
layout src | la sr | Switch to Source Code view |
layout split | la sp | Switch to Split (Assembly + Source Code) view |
update | upd | Show the current line in the Source Code window |
Ctrl+L | Redraw the screen |
Other commands
Command | Short form | Description |
---|---|---|
(empty line) | Repeat the previous command | |
help continue | h c | Show help about the 'continue' command |
help break | h b | Show help about the 'break' command |
help breakpoints | h breakpoints | Display a list of all breakpoint-related commands |
quit | q | Exit GDB (in Wokwi Web GDB, GDB will restart) |
Using GDB with the Wokwi Simulator
You can use the Wokwi simulator to play around with GDB and debug your Arduino code. Deezer dark mode.
To start a GDB session, open any project on Wokwi (e.g. this Simon game), click on the code editor, and press F1. In the prompt that opens, type 'GDB':
Then choose one of the options to launch GDB in a new browser tab. In general, the 'debug build' is recommended for optimal debugging experience, but some libraries (e.g. FastLED) may not function correctly without the compiler optimizations.
I suggest to start with the 'debug build', and switch to the 'release build' only if the program doesn't work correctly. Download opera gx gaming.
The Web GDB app takes about 30 seconds to start for the first time, and should load within a few seconds after the first time.
When GDB is ready, it should print something like:
At this point, you can write continue
to start running the program, advance setup
to run the program and stop at the beginning of the setup()
function, or any other command from the GDB cheat sheet above.
P.S. if you are curious, here's how I got GDB to run in the browser.
* The advance
command will also stop if the current function returns
Breakpoints
Command | Short form | Description |
---|---|---|
info breakpoints | i b | Display a list of all the breakpoints |
break loop | b loop | Set a breakpoint at the beginning of loop() |
break 42 | b 42 | Set a breakpoint in line 42 |
break *0x156 | b *0x156 | Set a breakpoint at program address 0x156 |
tbreak loop | tb loop | Set a one-time (temporary) breakpoint in loop() |
clear loop | cl loop | Delete any breakpoints on loop() |
clear 42 | cl 42 | Delete any breakpoints on line 42 |
delete 1 | d 1 | Delete breakpoint number 1 |
disable | dis | Disable all breakpoints |
disable 1 | dis 1 | Disable breakpoint number 1 |
enable | en | Enable all breakpoints |
enable 1 | en 1 | Enable breakpoint number 1 |
enable once 1 | en once 1 | Enable breakpoint number 1 for a single hit |
Call Stack
Command | Short form | Description |
---|---|---|
backtrace | bt | Display a backtrace of the current call stack |
backtrace -full | bt -fu | Display backtrace including local variables |
info args | i ar | Dump the arguments of the current function |
info locals | i lo | Dump local variables and their values |
info registers | i r | Dump MCU registers |
faas info args | fa i ar | Dump the arguments of all functions in the call stack |
frame 2 | f 2 | Select frame number 2 |
up | Go one stack frame up (e.g. calling function) | |
down | do | Go one stack frame down |
Inspecting Code
Command | Short form | Description |
---|---|---|
list loop | l loop | Show the source code of loop() |
disassemble | disas | Disassemble the current program location |
disassemble/s | disas/s | Disassemble including source code |
disassemble/r | disas/r | Disassemble including opcodes (in hex) |
disassemble loop | disas loop | Disassemble the loop() function |
Inspecting Data
Command | Short form | Description |
---|---|---|
print $pc | p $pc | Print the value of PC (Program Counter) |
print $r0 | p $r0 | Print the value of the R0 register |
print i | p i | Print the value of the variable i |
print PORTB | p PORTB | Print the value of the I/O register PORTB |
dprint loop,'Loopn' | dp … | Print 'Loop' every time loop() starts |
dprint loop,'%dn',i | dp … | Print the value of i every time loop() starts |
x/16b $sp | Dump 16 memory bytes starting at $sp (stack pointer) | |
x/10w 0x800200 | Dump 10 dwords starting at data space address 0x200 | |
x/s 0x800151 | Dump a string from the data space address 0x151 | |
display someVar | disp someVar | Display the value of someVar whenever the program stops |
info display | i di | List active auto-display (watch) expressions |
delete display 1 | d d 1 | Delete auto-display expression number 1 |
Modifying Data
Command | Short form | Description |
---|---|---|
set i = 0 | s i=0 | Change the value of variable i to 0 |
set $pc = 0 | s $pc=0 | Jump to the beginning of the program |
set $r12 = 0x55 | s $r12=0x55 | Set r12 to 0x55 |
set PORTB = 0xff | s PORTB=0xff | Set PORTB (I/O register) to 0xff |
set {int}0x800200 = 50 | s … | Set an integer at dataspace address 0x200 to 50 |
Text User Interface (TUI)
Command | Short form | Description |
---|---|---|
tui enable | tu e | Enabled the TUI mode (also Ctrl X+A) |
tui disable | tu d | Enabled the TUI mode (also Ctrl X+A) |
tui reg all | tu r a | Display registers window |
layout asm | la a | Switch to Assembly view |
layout src | la sr | Switch to Source Code view |
layout split | la sp | Switch to Split (Assembly + Source Code) view |
update | upd | Show the current line in the Source Code window |
Ctrl+L | Redraw the screen |
Other commands
Command | Short form | Description |
---|---|---|
(empty line) | Repeat the previous command | |
help continue | h c | Show help about the 'continue' command |
help break | h b | Show help about the 'break' command |
help breakpoints | h breakpoints | Display a list of all breakpoint-related commands |
quit | q | Exit GDB (in Wokwi Web GDB, GDB will restart) |
Using GDB with the Wokwi Simulator
You can use the Wokwi simulator to play around with GDB and debug your Arduino code. Deezer dark mode.
To start a GDB session, open any project on Wokwi (e.g. this Simon game), click on the code editor, and press F1. In the prompt that opens, type 'GDB':
Then choose one of the options to launch GDB in a new browser tab. In general, the 'debug build' is recommended for optimal debugging experience, but some libraries (e.g. FastLED) may not function correctly without the compiler optimizations.
I suggest to start with the 'debug build', and switch to the 'release build' only if the program doesn't work correctly. Download opera gx gaming.
The Web GDB app takes about 30 seconds to start for the first time, and should load within a few seconds after the first time.
When GDB is ready, it should print something like:
At this point, you can write continue
to start running the program, advance setup
to run the program and stop at the beginning of the setup()
function, or any other command from the GDB cheat sheet above.
P.S. if you are curious, here's how I got GDB to run in the browser.
Recently I had the chance to incorporate the DFPlayer Mini into a project. It's a super cute MP3 player that is great for Arduino powered projects. The only problem being with the documentation. It is a little spotty and I had to work pretty hard to get around a few issues. So here is a little cheat sheet to help you along:
How should I wire up the DFPlayer Mini to my Arduino?
If you dig into the pin map for the DFPlayer mini, you will find two different ways of driving a speaker. One set labeled ‘DAC left' and ‘DAC right' for use with an an inbuilt digital to audio converter. The other set labeled ‘SPK1 and SPK2', and from the documentation looked like it is only useful for mono.
In practice, the SPK set supports stereo, and I found the DAC set to introduce a considerable amount of line noise. (Despite using the recommended 1K resistors between the Arduino and DFPlayer). Switching to the SPK set of outputs made a huge improvement in sound quality. I wired my DFPlayer mini up like this:
Oh and the polarity of a 3.5mm headphone jack? The pointy bit is the left channel, the middle the right and the part closest to the cable goes to ground.
What library should I use with the DFPlayer Mini?
The DFRobotDFPlayerMini library for the most part works pretty well. It works great with software serial, which is what DFRobot use in their example code on their wiki.
The DFPlayer library has made my main loop very slow?
I found making a call to setVolume each time in the main loop to be fairly destructive on the loop performance. This call could take upwards of 100ms and, this made the frame-rate of some LED animation stuff that I was doing unacceptable. In the end, I only called setVolume when the value of a potentiometer was adjusted. Playback volume is something that is only occasionally changed, and having a drop in animation performance during those times wasn't noticeable.
How do I format and organise my micro SD Card to be compatible with the DFPlayer Mini?
Plug your micro SD card into your computer and then In OSX open up a terminal and use the following commands:
This will let you work out what logical disk is being used for your micro SD Card. In my case, I used the listed SIZE to work out that it was /dev/disk2. Now the card can be correctly formatted:
Now copy your MP3 files over to the micro SD card. They can go into a folder named ‘mp3', but will work fine straight on the disk themselves. They must be sequentially numbered like so:
You will also need to copy these files across in order, the DFPlayer seems to use some sort of creation timestamp when the files are index. So don't copy 0003.mp3 and then 0001.mp3, otherwise wacky things will happen.
Finally, if you have done this all on OSX, you will need to clear out any hidden files as that will also mess up the DFPlayer's indexing system.
(Your volume folder might be different, depending on what you used as the disk name during the disk erase step).
Wechip remote nvidia shield pro. WeChip W1 Remote 2.4G Wireless Keyboard Multifunctional Smart TV Remote Control for Nvidia Shield/Android TV Box/PC/Projector/HTPC/TV (Renewed) $12.75 Works and looks like new and backed by the Amazon Renewed Guarantee. 1 of WeChip G20 Voice Remote Wireless Replacement Remote for Nvidia Shield/PC/Android TV Box/Smart TV. (438) Voice Control: Press the voice button on the remote control to search for the channel you want to see, easy and convenient to use.
I had a bunch of MP3 files and micro SD cards to produce, so I made a little script to make it a bit easier (I had all my sequentially numbered files on the desktop in a folder titled ‘soundFiles'):
DFPlayer Mini randomly locks up and doesn't play
This one was really tricky to nail down, it only happened maybe 4% of the time I called ‘void play(int fileNumber)'? Everything was setup correctly the selected MP3 fie would play most of the time, but every now and then it wouldn't. Super annoying. I had to write my own play method to work around the issue:
This method makes sure any existing tracks are stopped first. Then we make sure that the current file number that the DFPlayer has matches the one we supplied. Keep trying till these track numbers match. It was the only way that I could play a track 100% of the time on the DFPlayer mini.
Edits:
- 2019/01/19 - Updated schematic so that the speakers are wired to SPK1 and SPK2
Arduino Commands Cheat Sheet Cheat
Hi! Subconsciously you already know this, but let's make it obvious. Hopefully this article was helpful. You might also find yourself following a link to Amazon, Lego or eBay to learn more about parts or equipment. If you end up placing an order, I make a couple of dollarydoos. We aren't talking a rapper lifestyle of supercars and yachts, but it does help pay for the stuff you see here. So a massive shoutout to everyone that enables this place. Thanks!