IDE compiling a sketch using a Makefile

Hi
I have uploaded sketches to Uno's and played with programming and also a lot with Pi's, also a bit of C programming, but its been a while.
I have a project I've built mechanically that has the software pre written for it, its called Satnogs 3.1, the project to track satellites.
This is the first time I have come across Makefiles with the Arduino though, basically I've got a Pi running satellite tracking software which via 485 talks and controls the Uno, the Arduino Uno r3 has a CNC shield and driver chips installed for stepper motors. The pre written code in the .ino file has between 6 or 8 *.h includes but the whole package is designed around a Makefile to pull it all together.
I'm running Arduino IDE 2.3.2 and am not sure if it will manage this process or I need to go to the command line in Windows 10, install a Make package then use make, I've searched, spent hours looking at options, watched YouTube but don't have a clear path forward with the IDE, but it maybe as simple as the IDE wont compile it, thanks

Project Readme file for software install

I don't think that you need the makefile.

1
You can download the relevant ino file (dc_motor_controller.ino or stepper_motorcontroller.ino) and the relevant .h files from libraries and place them all in one sketch; e.g.

dc_motor_controller
+-- dc_motor_controller.ino
+-- globals.h
+-- easycomm.h
...
...
+-- as5601.h

2
Next modify the dc_motor_controller.ino and change the include lines that start with ../libraries/ as shown below
from

#include "../libraries/globals.h"
...
...

to

#include "globals.h"
...
...

3
Compile and upload.

If it doesn't work, please post complete error messages.

1 Like

So this has been an interesting adventure, thankyou for the advice, I still haven't worked out this Makefile thing as such but what I have done is followed your advice from my understanding of it.
Prior to doing this I tried putting the *.h files into the Arduino library directory in their own folder and compiling and no luck, I tried changing the file structure around my *.h files where they were compared to the stepper_motor_controller.ino file giving them their own folder, beside the .ino file and also under the .ino file, no luck here either, then I did what you said.
I copied the .h files into the same folder as the .ino file, changed the #includes in the .ino file to what you see below with inverted commas and not the arrows and the file compiled.
The sketch is now uploaded to the Uno but not yet tested, it will take me a while to test it as its a large project, but thankyou and fingers crossed.

#include <AccelStepper.h>
#include <Wire.h>
#include "globals.h"    //changed below to "" instead of <>
#include "easycomm.h"
#include "rotator_pins.h"
#include "rs485.h"
#include "endstop.h"
#include "watchdog.h" 

previous closed forum post

From what I can gather the creators of the sketches and header files use a non standard structure that the IDE cant handle, maybe what we have now done is a workaround for this. Please everyone please comment if you see obvious errors in what I have done here or reasons this wont work as I'm still learning.

Makefiles, as you figured out, do not work with the IDE; the creators of the sketches are using a 3rd party tool Arduino-Makefile (I missed that part yesterday).

You will probably be able to set this all up on your Pi (maybe use a portable install of IDE 1.8.19 so it does not interfere with a current IDE 2.x installation). Although I'm familiar with makefiles, I can't quite help you with that.

I've created a directory called sagnos in the libraries directory and moved all the .h files in there (so the sketch only contains the .ino file). After that I compiled the sketch (as modified above) and it compiles without errors.

Structure like below

sketchbook
+--libraries
|  +-- Arduino-PID-Library-master
|  +-- ...
|  +-- ...
|  +-- sagnos
|  |   +-- as5601.h
|  |   +-- ...
|  |   +-- ...
|  |   +-- watchdog.h
|  +-- ...
|  +-- ...
+-- dc_motor_controller
   +-- dc_motor_controller.ino

If so inclined, you can change all the includes from #include "globals.h" to <#include "globals.h> etc. In that case the IDE will no longer look in the sketch directory for those includes.

Note:
To make sure that the IDE does not not use the cached older versions of the .h files that were in the sketch directory, you will need to clear the cache or create a new sketch (e.g. dc_motor_controller_new). IDE 2.x does not clear the cache on exit, IDE 1.x does clear the cache on exit.