Arduino Code Cheat Sheet



  1. An interrupt cheat sheet would have to cover the workings of most of the MCU peripherals: to much material for a “cheat sheet” format. – Edgar Bonet Feb 27 '17 at 8:35 The 'cheat sheet' is more commonly known as the datasheet.
  2. 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.

Program Execution

Arduino IDE Commands Cheat Sheet By Sayak Boral on July 5, 2019 If you are a new Arduino user, you might be interested in a list of commands that are useful for the most important activities. You need them to control the Arduino board and define simple logical operations.

CommandShort formDescription
continuecRun the program
advance setupadv setupRun the program and stop at the beginning of setup() *
nextnExecute the next line of code (step over)
stepsStep into the next line of code
finishfinRun the program until the current function returns (step out)
nextinExecute the next instruction (step over)
stepisiStep into next instruction
untiluLike next, but doesn't go back in loops
Ctrl+CBreak the program at the current instruction

* The advance command will also stop if the current function returns

Breakpoints

CommandShort formDescription
info breakpointsi bDisplay a list of all the breakpoints
break loopb loopSet a breakpoint at the beginning of loop()
break 42b 42Set a breakpoint in line 42
break *0x156b *0x156Set a breakpoint at program address 0x156
tbreak looptb loopSet a one-time (temporary) breakpoint in loop()
clear loopcl loopDelete any breakpoints on loop()
clear 42cl 42Delete any breakpoints on line 42
delete 1d 1Delete breakpoint number 1
disabledisDisable all breakpoints
disable 1dis 1Disable breakpoint number 1
enableenEnable all breakpoints
enable 1en 1Enable breakpoint number 1
enable once 1en once 1Enable breakpoint number 1 for a single hit

Arduino Programming Pdf Free Download

Call Stack

CommandShort formDescription
backtracebtDisplay a backtrace of the current call stack
backtrace -fullbt -fuDisplay backtrace including local variables
info argsi arDump the arguments of the current function
info localsi loDump local variables and their values
info registersi rDump MCU registers
faas info argsfa i arDump the arguments of all functions in the call stack
frame 2f 2Select frame number 2
upGo one stack frame up (e.g. calling function)
downdoGo one stack frame down

Inspecting Code

CommandShort formDescription
list loopl loopShow the source code of loop()
disassembledisasDisassemble the current program location
disassemble/sdisas/sDisassemble including source code
disassemble/rdisas/rDisassemble including opcodes (in hex)
disassemble loopdisas loopDisassemble the loop() function

Inspecting Data

CommandShort formDescription
print $pcp $pcPrint the value of PC (Program Counter)
print $r0p $r0Print the value of the R0 register
print ip iPrint the value of the variable i
print PORTBp PORTBPrint the value of the I/O register PORTB
dprint loop,'Loopn'dp …Print 'Loop' every time loop() starts
dprint loop,'%dn',idp …Print the value of i every time loop() starts
x/16b $spDump 16 memory bytes starting at $sp (stack pointer)
x/10w 0x800200Dump 10 dwords starting at data space address 0x200
x/s 0x800151Dump a string from the data space address 0x151
display someVardisp someVarDisplay the value of someVar whenever the program stops
info displayi diList active auto-display (watch) expressions
delete display 1d d 1Delete auto-display expression number 1

Modifying Data

CommandShort formDescription
set i = 0s i=0Change the value of variable i to 0
set $pc = 0s $pc=0Jump to the beginning of the program
set $r12 = 0x55s $r12=0x55Set r12 to 0x55
set PORTB = 0xffs PORTB=0xffSet PORTB (I/O register) to 0xff
set {int}0x800200 = 50s …Set an integer at dataspace address 0x200 to 50

Text User Interface (TUI)

CommandShort formDescription
tui enabletu eEnabled the TUI mode (also Ctrl X+A)
tui disabletu dEnabled the TUI mode (also Ctrl X+A)
tui reg alltu r aDisplay registers window
layout asmla aSwitch to Assembly view
layout srcla srSwitch to Source Code view
layout splitla spSwitch to Split (Assembly + Source Code) view
updateupdShow the current line in the Source Code window
Ctrl+LRedraw the screen

Other commands

CommandShort formDescription
(empty line)Repeat the previous command
help continueh cShow help about the 'continue' command
help breakh bShow help about the 'break' command
help breakpointsh breakpointsDisplay a list of all breakpoint-related commands
quitqExit 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.

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.

Arduino

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.

Download imovie 09 free for mac. When GDB is ready, it should print something like:

Arduino Cheat Sheet Pdf

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.

Arduino Code Cheat Sheet

ArduinoCheatSheet

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 thereference for while programming. What data type does the millis()function return? How long till that overflows again? How large can along get? What baud rates can the serial handle?
Any other things you'd like to see added, send me an email and I'll stick them on Rev 3!
Edit: Thanks to Macca and TBAr for their feedback. Here's V.02b
Edit2: Thanks to others for their feedback. Here's V.02c!
Click for large version. For printable, check out the PDF at the bottom of the page

Thanks to the guys at Arduino.CC and also Fritzing.Org, whos images I shamelessly stole in making it. (I'm pretty sure it's all OK under the CC, but if not let me know).
Arduinocheatsheetv02c.vsd