**This is an old revision of the document!**
ArduinoIDE
ArduinoIDE portable
- Download the distribution from the official webpage:
wget https://downloads.arduino.cc/arduino-1.8.13-linux64.tar.xz tar xvf arduino-1.8.13-linux64.tar.xz
- Inside arduino-1.8.13/, create a directory named portable
cd arduino-1.8.13/ mkdir portable
- By merely existing, this
portable
directory modiffies the base behaviour of the ArduinoIDE environment. From now on, all the libraries, compilers, utilities, and conffiguration files are always contained within the portable folder.
cd arduino-1.8.13/ ./arduino
ArduinoIDE with external Editor
- Go to settings and mark the
Use External Editor
option. - Now you can edit the sketch files with your favourite editor and save.
- When you're done with editing, use ArduinoIDE
Upload
and Serial Console normally.
ArduinoIDE terminal compile and program board
- You can compile and program the board using ArduinoIDE from the terminal:
./arduino --port /dev/ttyUSB0 --board Arrow:samd:SmartEverything_Fox_native --preserve-temp-files --pref build.path=/home/jsanchez/tmp/arduinobuild --verify || OR || --upload ./MYSKETCH.ino
--port
must be set to your serial device port.--board
must be set to your board model (more on this next).--preserve-temp-files
tells the compiler to build only the updated files instead of all the code.- This is a HUGE time saver!.
- Must specify with –pref build.path the directory to contain all the temporary object files. This directory can be safely be deleted later.
--verify
only compiles the code without uploading it to the board (nice for debugging).--upload
compiles and uploads the code to the board.
Don't forget the ./
in front of your sketch name!!
Finding the board name
./arduino --port /dev/ttyUSB0 --board Arrow:samd:SmartEverything_Fox_native --preserve-temp-files --pref build.path=/home/jsanchez/tmp/arduinobuild --verify || OR || --upload ./MYSKETCH.ino
--board
must be set to your board model.- You can find several boards.txt files in your source tree.
hardware/arduino/avr/boards.txt portable/packages/Arrow/hardware/samd/2.1.0/boards.txt portable/packages/arduino/hardware/samd/1.6.18/boards.txt
You can build the board following the dir names and within the boards.txt file itself:
SmartEverything_Fox_native.name=SmartEverything Fox (Native USB Port)
ArduinoIDE modular code
- Besides your
.ino
file, you can place additional source files within your sketch folder. - These will be compiled and linked implicitly by the ArduinoIDE toolchain.
- However, don't forget to do apply the correct C/C++ modular code practices!! i.e.
#include
,extern
, etc. - Note how the files are listed as TABS in the ArduinoIDE interface.
ArduinoIDE Debug PRINT
- Print function calls can be controlled across a whole
.c
file without rewriting code. - This enables us to switch the debug PRINT on/off with a simple macro definition
#define DEBUG
. - This is implemented in some way or another in difierent projects. It is a very widespread practice.
- Copy this block in your C file.
#ifdef DEBUG #define PRINT(...) Serial.print(__VA_ARGS__) #define PRINTLN(...) Serial.println(__VA_ARGS__) #define PRINT_ARRAY(add, len) \ do { \ int i; \ for (i = 0 ; i < (len) ; i++) { \ Serial.print((unsigned int)((uint8_t*)(add))[i], HEX); \ } \ Serial.println(); \ } while(0) #else /* DEBUG */ #define PRINT(...) #define PRINTLN(...) #define PRINT_ARRAY(add, len) #endif /* DEBUG */
- Then, write conditional print sentences as
PRINT(var)
. - Additionally, the
PRINT ARRAY(address, len)
function simply prints in HEX an array passed as an argument. - NOTE to activate the conditional debut pring,
#define DEBUG
must be writen before the previous code block.- Alternatively, it can be defined with a compiler CFLAG environment variable.
Use example:
uint8_t foo[255]; int bar = 7; ... PRINTLN(bar); PRINT_ARRAY(foo, sizeof(foo)) // These prints only if the DEBUG macro was defined. 7 EE FF 01 25 ...
ArduinoIDE alternative serial consoles
- ArduinoIDE comes with an embedded serial console.
- Alternatively you can use a serial console like picocom, but you must set it to the right parameters.
picocom -g "logs/serial_console_log.txt" # Save the consolo text in a log file -r # NO-reset - avoid reseting the device -b 115200 # Baudrate - MUST MATCH ARDUINOIDE! --omap crcrlf # Mapping of EOL characters /dev/ttyACM0
- Exit Picocom with
Ctrl+A
,Ctrl+X
.