You can’t go a long way as a maker with Raspberry Pi before you run into Arduino and realize how it can supplement, replace, modify or integrate with a maker experience.
It would really be nice to program the Arduino in Python and this is supposed to be possible using an Arduino sketch called Firmata. But at the end of the day, when the dust has settled, the bottom line (that’s all the cliches I can think of) is that to really learn how to use the Arduino you can’t avoid learning to use “sketches” in its very own programming language, which is a subset of C++, which is a super-set of C. C is just another of those old computer languages (not as old as Fortran or Cobol or that bunch) whose time has come and gone, and come, and gone again, and come again, and I understand C programmers make more than Python guys. Life is so unfair. Once you have the basic C concept you graduate to C++ where the language becomes object oriented. (If you just asked “Why not skip this process and move straight to Python?” the answer is “I’ll think about it.”) The nature of Arduino requires some syntactical changes, always requiring a Do-this-once part followed by a Do-this-loop part.
…so C is a little more complicated than Python on the Pi, but unavoidable with Arduino. I may see a Arduino/C toolbox on the horizon. To learn C you first have to pick both a compiler and an IDE. I’ll save you the torturous story of my journey, but ultimately I settled on starting out on my Windows laptop using Microsoft’s VS Code as an IDE, and a group of compilation tools you can find free in a distribution here:
by a guy named Stephan T. Lavavej – who deserves major thanks for what he has put together.
Once you have all that installed, writing your first program can be, well, daunting. Its is not nearly as easy as using IDLE or Pycharm. There is no getting around the hours of work necessary to understand it but just getting “hello world” under your belt can help you feel a huge sense of accomplishment and keep you motivated. I finally took notes on the process and I hope this could be of help to somebody else.
Creating and Running a Program in VS Code Using the Mingw-w64 Compiler
- This assumes installation of VS Code, Mingw, & paths in Windows
- Test the Mingw tools: at a command prompt : g++ –version or g++ –help
- This also assumes you have a “projects” folder and specific project “myproject” subfolder
- Click on TERMINAL and navigate to your program “myproject” subfolder. (create it with mkdir myproject if necessary)
- type “code .” (“code” space period) to use that folder as a workspace for your project – a new workspace opens
- Hover over the new “myproject” subdirectory name under Explorer. 4 icons appears to the right – click the new file icon (the first one) then name your file with a .cpp extension; ie. myfile.cpp
- Click the new file icon (page doc with “+” in top left corner.
- input your source code, then save it (Ctl-S); yourfilename.cpp appears under Explorer
- Create a tasks.json file to program the compiler: Terminal -> Configure Default Build Task -> g++.exe build active file
- Under .vscode you will see tasks.json which has been created and opened in the editior where you can modify: program to run, args, active file ($(file))
- Select (click on) your file, i.e., myfile.cpp or whatever
- Ctl-Shift-B or Terminal -> Tasks: Run Bild Task to have have complier build your file based on your tasks.json instructions- be patient, takes a minute
- Open a new terminal by clicking the “+” button – top line of current terminal or from top tab Terminal ->New Terminal
- Confirm creation of your executable with dir command – should see your new myfile.exe
- Run your new program in Terminal with .\ + filename; ie, .\myfile.exe