Managing multiple main.cpp files in one project (src_filter alternative?)

Hi all,

Most Arduino/ESP projects I do in Platformio involve combining some number of adafruit-esque add on boards. The typical workflow is to connect things and play with examples to get a hang of whatever library is being used, then to make a sketch specific to that sensor, and eventually make a sketch that combines all the pieces in one.

In the original arduino IDE, each of these sketches are their own file, and because the libraries are sort of universal for all sketches, it’s easy to work this way.

In platformio, the method i’ve adopted is the one in this thread:

This makes a seperate env in the platformio.ini file for each scenario, and a seperate main-scenario.cpp file. Compiling and uploading is done in the command line:

pio run -t upload -e scenario

Project structure:

.ini file example:

[env:huzzah]
platform = espressif8266
board = esp_wroom_02
framework = arduino
upload_port = /dev/cu.usbserial-0001
monitor_speed = 115200
monitor_filters = send_on_enter
monitor_echo = yes
lib_deps = 
	plerup/EspSoftwareSerial@^6.16.1
	adafruit/Adafruit SCD30@^1.0.9
	adafruit/Adafruit MPRLS Library@^1.2.0
	adafruit/Adafruit SSD1306@^2.4.3
	adafruit/Adafruit GFX Library@^1.11.3
	adafruit/Adafruit PM25 AQI Sensor@^1.0.6
	adafruit/Adafruit BusIO@^1.14.0
	adafruit/Adafruit Unified Sensor@^1.1.6
	paulstoffregen/Time@^1.6.1
	adafruit/RTClib@^2.1.1
src_filter = +<*.h> +<main-${PIOENV}.cpp>

[env:pm25]
platform = espressif8266
board = esp_wroom_02
framework = arduino
upload_port = /dev/cu.usbserial-0001
monitor_speed = 115200
monitor_filters = send_on_enter
monitor_echo = yes
lib_deps = 
	plerup/EspSoftwareSerial@^6.16.1
	adafruit/Adafruit SCD30@^1.0.9
	adafruit/Adafruit MPRLS Library@^1.2.0
	adafruit/Adafruit SSD1306@^2.4.3
	adafruit/Adafruit GFX Library@^1.11.3
	adafruit/Adafruit PM25 AQI Sensor@^1.0.6
	adafruit/Adafruit BusIO@^1.14.0
	adafruit/Adafruit Unified Sensor@^1.1.6
	paulstoffregen/Time@^1.6.1
	adafruit/RTClib@^2.1.1
src_filter = +<*.h> +<main-${PIOENV}.cpp>

[env:press5]
platform = espressif8266
board = esp_wroom_02
framework = arduino
upload_port = /dev/cu.usbserial-0001
monitor_speed = 115200
monitor_filters = send_on_enter
monitor_echo = yes
lib_deps = 
	plerup/EspSoftwareSerial@^6.16.1
	adafruit/Adafruit SCD30@^1.0.9
	adafruit/Adafruit MPRLS Library@^1.2.0
	adafruit/Adafruit SSD1306@^2.4.3
	adafruit/Adafruit GFX Library@^1.11.3
	adafruit/Adafruit PM25 AQI Sensor@^1.0.6
	adafruit/Adafruit BusIO@^1.14.0
	adafruit/Adafruit Unified Sensor@^1.1.6
	paulstoffregen/Time@^1.6.1
	adafruit/RTClib@^2.1.1
src_filter = +<*.h> +<main-${PIOENV}.cpp>

It works well, but I am getting a warning that the src_filter method is depreciated or dissapearing or the wrong way to go about things. I’m wondering if anyone has a different, possibly better method of approaching this kind of thing.

Thanks for your time :slight_smile:

1 Like

https://docs.platformio.org/en/latest/projectconf/section_env_build.html#build-src-filter

EDIT: I’m actually doing same kind of thing, just using build_src_filter, not src_filter [src_filter may be deprecated as legacy, but build_src_filter I guess is not]

1 Like