Uploading to Multiple Identical Devices

As a newbie, I am not confident I know how to control the upload to a specific com port under PlatformIo in contrast to the Arduino IDE where it is always a very specific choice.

For example: I have two Mega2560s attached to com ports. One is in operational mode on my cockpit hardware and I don’t want to change anything until I am ready. The other Mega2560 is in development mode and I want to make changes and test it independently.

As far as I have gathered ( as a 3-day newbie), both Megas just appear on the Devices list without any obvious way of locking onto one or the other. Did I miss something?.

PlatformIO has automatic upload port detection that will get the first “good looking” (in terms of some filters…) COM port available on the machine.

Since you seem to want to make sure that you only update to the right board, use upload_port = COMx in the platformio.ini with the COM port you want, and it will overwrite any automatic detection; Just like in the Arduino IDE.

Hi Max,
Thanks for the quick response. As a newbie, I am reluctant to make critical comments about PlatformIO function, but surely editing a control file is a clumsy way of solving such an issue. I am not exactly sure at what instant the platformio.ini control file changes become activated? Shouldn’t it be part of end-user interactive interface? eg pointing at the list of com port devices and clicking, I want that one to be active at this point in time? I suppose I am really just asking for a functional update, which is somewhat cheeky for a complete newbie.
Cheers.

No, the platformio.ini is the main configuration file in which we want an end user to insert all the wanted settings, akin to the “menu selection” that the Arduino IDE has. This also makes it persistent and visible – e.g., if you setup your menu options in some way in the Arduino IDE to make the sketch work, say you need exceptions enabled in an ESP8266 project, the Arduino IDE has no way of storing that information with your sketch. PlatformIO has, it’s part of the configuration file. In the same way, you can save the information that the file has to be uploaded a certain way (upload_protocol, upload_speed, etc.), and the upload_port is one part of that. Indeed, if you set the upload_port, it becomes very computer- or network-specific, but sometimes you want exactly that (e.g., hardcoding an IP address or hostname for an ESP OTA upload, or hardcoding a COM port for upload when you have a development session).

I can definitely see that being a good feature in cases where no specific upload_port is set, the UI can offer some way to tell the PlatformIO core which upload_port should be used, if multiple are found. I’d also argue that that is one of the only options where you want to have a quick switching control over it. Issues · platformio/platformio-vscode-ide · GitHub is always open for feature requests (same for the core).

Max,

Firstly I should say as a newbie, I am very impressed with the functionality of PlatformIO, and will certainly be switching to it as my main code editor from now on.

With regard to my clumsy remark, there are various pros and cons about what control parameters are fairly static and belong in an .ini file, and those that are dynamic and are selected interactively. An ini file is usually something that is edited, saved, and normally requires a reboot of the application before changes become activated ( situation for the PlatformIo.ini is not clear to me at the moment. Do the changes activate without a reboot?)

At the moment I have added the statement you suggested to my ini file, and now my development uploads will always be locked to one specific com port. This is a comfort to know that I am not going to accidentally mess up a device that is currently in “production” mode rather than “development” mode. This is fine while the code is being developed, the problem arises when it becomes ready to be inserted in a production device. These devices are buried deep in my cockpit, and have a multitude of wires feeding various cockpit components. They cannot easily be moved to the fixed development com port. So there are two alternatives. Firstly replace the entry in the .ini file to temporarily target the actual device in the cockpit, and then reset it back to the development port. This is liveable with although a bit clumsy. The second alternative is to switch back to arduino IDE, temporarily, and this is also clumsy.

Thank you again for responding to my questions.

Cheers

Yes absolutely. As soon as the file is saved, the PlatformIO VSCode extension also triggers a reload of tasks and IntelliSense. When you hit the build / upload / whatever task button, and PlatformIO starts executing, it will read out the platformio.ini at that point in time. So, doing a change to the platformio.ini and then pio run / Build it immediately after, the changes apply. That would be extremely painful if that took a restart of VSCode.

No, the option applies only to that project and can be instantly changed in the platformio.ini. We don’t lock you in forever :slight_smile:

Max,
Thanks for your comments on my concerns.

If I know what the current choice for “upload_port =” in my saved Platformio.ini, and I am confident it is the right one, then ALL uploads will only go to this port, and devices on other ports are protected?
If I want to change the target COM port for an upload, I first have to bring Platformio.ini up for edit, preferably in the right side of a split screen. Then edit the line “upload_port = COM9” say, to some other COM number. Then make sure the right panel is active, move up to the Menu Bar File drop-down and select Save. From this point on, all uploads will be sent to that port only. If I now close the ini panel, then my choice disappears from view, any further change of target port requires the whole procedure to be repeated, unless of course the ini file remains on screen. I can live with this process, but I dont think it is an attractive one ( I hope, as a newbie, my thoughts are not considered impertinant. Sometimes fresh eyes can be constructive to product improvemets)

However, having said all that, my experience with Uploading to COM ports, has now gone completely downhill!!! At first I was able to compile and upload my Arduino code using PlatformIo with complete success. Now it always fails the upload operation! At first I got 10 iterations of the “avrdude … failed to synch” message. Now it is supplemented with the additional error " programmer is not responding". If I switch away from Platformio back to the Arduino IDE, I can compile and upload to the COM port without problems. I have absolutely no idea why PlatformIO is more problematic about Uploads, I have tried all the usual remedies of re-booting, re-plugging etc etc. This could be the real show-stopper, with PlatformIO being only useful as colourful and highly predictive Arduino code editor!

Any thoughts on my Upload error problems?

Cheers

I solved my Upload problem; I chose the wrong one between two Mega2560 options.

With respect to controlling COM ports discussed above, I now realize that there are multiple PlatformIO.ini files, one for each project. The name confused me, surely they ought really have unique names related to their corresponding projects ie project-name.ini. PlatformIO.ini should be rerserved strictly to the PlatformIO program. Just another of the odd things that hit the eyes of a newbie user

1 Like