Ino2cpp
Convert Arduino INO sketches to C++
Install / Use
/learn @arquicanedo/Ino2cppREADME
ino2cpp
Convert Arduino INO sketches to C++
Abstract
Arduino sketches and C++ are very similar. However, an INO file cannot be compiled as-is by C/C++ compilers (e.g., GCC). This tool converts INO sketches to C++ code such that off-the-shelf compilers and static analysis tools can be executed on the code.
Converter
There are three steps in this conversion [1][2]:
- Generate forward declarations. Arduino INO sketches allow the use of a function before its definition. The first step is to parse the INO sketch to obtain function signatures, and generate a header file with these signatures ("sketch_name.h").
- Includes. Two includes are inserted before the content of the INO sketch: #include <Arduino.h>, and #include "sketch_name.h". Future work includes the parsing of header files from Arduino's standard library, search the Arduino app install path for the library, and include these dependencies in a Makefile.
- Write C++ to disk. Write the resulting C++ file to disk.
Usage Example
$ python ino2cpp.py examples/*.ino -o output
writing to output/1.cpp
writing to output/2.cpp
$ ls output/
1.cpp 1.h 2.cpp 2.h
$ cat output/1.h
void updateScale();
void isrEncoder();
void isrSwitch();
void setup();
void loop();
void precrtajScale();
$ head -2 output/1.cpp
#include <Arduino.h>
#include "1.h"
The generated C++ files can be parse and semantically analyzed. The full output of clang's pre-processor and semantic analysis can be found here.
Similarly, clang's AST dump is as follows:
clang -Xclang -ast-dump -x c++ -fsyntax-only -D__AVR_ATmega328P__ -DARDUINO=100 -DF_CPU=16000000L -Wno-unknown-attributes -Wno-attributes -I/path/to/local/Arduino/JavaAppAndIncludedLibraries output/1.cpp

References
[1] https://arduino.stackexchange.com/questions/32998/how-to-convert-arduino-example-sketch-to-a-complete-c-project<br> [2] https://forum.arduino.cc/index.php?topic=232632.0
Related Skills
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
