PlatformIO Community

PIO in VSCode doesn't know how to switch between Arduino Uno and Pro Micro targets


#1

I have a simple test blink project that I’m trying to use with both my Arduino Uno and Arduino Pro Micro boards. I set up board targets for both,

[platformio]
;env_default = sparkfun promicro16

[env:uno]
platform = atmelavr
board = uno
framework = arduino

[env:sparkfun promicro16]
platform = atmelavr
framework = arduino
board = sparkfun_promicro16

but when I click upload, it tries to upload an Arduino Uno hex firmware file to the Arduino Pro Micro, even when it’s the only device plugged in. How can I correct this? If I uncomment the line above, it uploads to the Pro Micro, but that’s not a sustainable solution.


#2

no spaces in env labels. try using sparkfun_promicro16 or even sp for short


#3

Nope. Same behavior. Do I need to restart VSCode?


#4

Is this when you click the main ‘Build’ option, instead of the environment specific one? As if that is the case, when you have multiple environments configured, unless you set a default, they will ALL build/upload when you hit the main Build/Upload option. btw, spaces in the environment name didn’t seem to be an issue here.

i.e.
image


#5

Yes, that all happens, but then PIO tries to upload an Uno firmware to a Pro micro…

...
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   9.9% (used 202 bytes from 2048 bytes)
PROGRAM: [=         ]   6.2% (used 2000 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Auto-detected: COM10
Uploading .pioenvs\uno\firmware.hex

#6

And this is when you hit the Upload option specifically for the sparkfun promicro16 environment? As I can’t really tell which build environment that was for as you snipped the top bit… the very first line of the output is quite important.

It should look more like this… (note, no device plugged in, and see that the uno environment was skipped)…

Processing sparkfun promicro16 (platform: atmelavr; board: sparkfun_promicro16; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/sparkfun_promicro16.html
PLATFORM: Atmel AVR > SparkFun Pro Micro 5V/16MHz
HARDWARE: ATMEGA32U4 16MHz 2.50KB RAM (28KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 24 compatible libraries
Scanning dependencies...
No dependencies
Checking size .pioenvs/sparkfun promicro16/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   5.8% (used 149 bytes from 2560 bytes)
PROGRAM: [=         ]  12.6% (used 3618 bytes from 28672 bytes)
Configuring upload protocol...
AVAILABLE: avr109
CURRENT: upload_protocol = avr109
Looking for upload port...
Auto-detected: /dev/ttyACM0
Forcing reset using 1200bps open/close on port /dev/ttyACM0
Waiting for the new upload port...
Uploading .pioenvs/sparkfun promicro16/firmware.hex

Connecting to programmer: .
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = "S"; type = p
Software Version = V.; Hardware Version = v.
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.

avrdude: error: programmer did not respond to command: leave prog mode
avrdude: error: programmer did not respond to command: exit bootloader

avrdude done.  Thank you.

*** [upload] Error 1
=============================================== [ERROR] Took 22.28 seconds ===============================================

======================================================== [SUMMARY] ========================================================
Environment uno                 [SKIP]
Environment sparkfun promicro16 [ERROR]
=============================================== [ERROR] Took 22.28 seconds ===============================================

Whereas you get this if you try to build/upload the uno environment… (and this time skipping the promicro16)…

Processing uno (platform: atmelavr; board: uno; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR > Arduino Uno
HARDWARE: ATMEGA328P 16MHz 2KB RAM (31.50KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 24 compatible libraries
Scanning dependencies...
No dependencies
Checking size .pioenvs/uno/firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [          ]   0.4% (used 9 bytes from 2048 bytes)
PROGRAM: [          ]   1.4% (used 444 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Auto-detected: /dev/ttyACM0
Uploading .pioenvs/uno/firmware.hex
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x20

avrdude done.  Thank you.

*** [upload] Error 1
================================================ [ERROR] Took 2.21 seconds ================================================

======================================================== [SUMMARY] ========================================================
Environment uno                 [ERROR]
Environment sparkfun promicro16 [SKIP]
================================================ [ERROR] Took 2.21 seconds ================================================
The terminal process terminated with exit code: 1

#7

Yes, those respective outputs are generated when I click the Upload buttons for the individual targets. When I use the upload keyboard shortcut, Ctrl + Alt + U, the following happens:

Processing uno (platform: atmelavr; board: uno; framework: arduino)
---------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/uno.html
PLATFORM: Atmel AVR > Arduino Uno
HARDWARE: ATMEGA328P 16MHz 2KB RAM (31.50KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 6 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pioenvs\uno\src\main.cpp.o
Archiving .pioenvs\uno\libFrameworkArduinoVariant.a
Compiling .pioenvs\uno\FrameworkArduino\CDC.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\HardwareSerial0.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\HardwareSerial1.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\HardwareSerial2.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\HardwareSerial3.cpp.o
Indexing .pioenvs\uno\libFrameworkArduinoVariant.a
Compiling .pioenvs\uno\FrameworkArduino\IPAddress.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\PluggableUSB.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\Print.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\Stream.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\Tone.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\USBCore.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\WInterrupts.c.o
Compiling .pioenvs\uno\FrameworkArduino\WMath.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\WString.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\abi.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\hooks.c.o
Compiling .pioenvs\uno\FrameworkArduino\main.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\new.cpp.o
Compiling .pioenvs\uno\FrameworkArduino\wiring.c.o
Compiling .pioenvs\uno\FrameworkArduino\wiring_analog.c.o
Compiling .pioenvs\uno\FrameworkArduino\wiring_digital.c.o
Compiling .pioenvs\uno\FrameworkArduino\wiring_pulse.S.o
Compiling .pioenvs\uno\FrameworkArduino\wiring_pulse.c.o
Compiling .pioenvs\uno\FrameworkArduino\wiring_shift.c.o
Archiving .pioenvs\uno\libFrameworkArduino.a
Indexing .pioenvs\uno\libFrameworkArduino.a
Linking .pioenvs\uno\firmware.elf
Building .pioenvs\uno\firmware.hex
Checking size .pioenvs\uno\firmware.elf
Memory Usage -> http://bit.ly/pio-memory-usage
DATA:    [=         ]   9.9% (used 202 bytes from 2048 bytes)
PROGRAM: [=         ]   6.2% (used 2000 bytes from 32256 bytes)
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Auto-detected: COM10
Uploading .pioenvs\uno\firmware.hex
^Cscons: *** [upload] Build interrupted.
Error: Aborted by user
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

I terminated it once I realized it was uploading the wrong file.


#8

If you had left it, it would have failed, and then moved on to building and uploading the promicro16 environment.

When you have multiple environments configured, unless you set a default, they will ALL build/upload when you hit the main Build/Upload option (which includes using the keyboard shortcut). PIO is doing exactly what you have told it to do… it is attempting to build and upload both environments (in sequence).


#9

Please connect 2 boards and provide an output from

$ pio device list

It seems that we need to configure PID/VID in board manifests.


#10

Oh, really? Can you explain please?


#11

Please open PlatformIO IDE Terminal and type pio device list.


#12

Do what Ivan said. For some background, what he’s saying (and I hadn’t realised at the time) is that platformio does try to actually work out which of the connected devices is your Uno or Pro Micro, etc, etc, and then flash that device, rather than just the first one it comes across. It does this via the PID/VID (product and vendor IDs) identifiers the device offers up to identify itself to the computer. Since platformIO isn’t working out which of the boards is the pro micro, yours may have a different PID/VID, so if it doens’t clash with another board, it can be added so it can be automagically detected when you have both an uno and pro micro connected (without having to use the 'upload_port" parameter in your platformio.ini, and deal with it potentially changing…) :wink:


#13

So, uh, the thing is that I haven’t been able to get to a terminal that recognizes a pio command. Even if I click on the icon for the terminal in the status bar, I still can’t get to a shell that is configured properly. Is there another way I can fetch this information for you?


#14

YOU BROKE THE TERMINAL… HOW COULD YOU DO SUCH A THING?! :open_mouth:

On more more serious note, does Ctrl+Shift+P and >platformio: new terminal (you should be able to start typing ‘term’ and let autocomplete find it…) work or is it just as non-cooperative?


#15

Yep, that terminal is unresponsive. It doesn’t recognize the pio command. Might I need to use powershell as my terminal for this to work? I’m currently using WSL.


#16

Ok, please open PIO Home > Devices and make screenshot.


#17

I’m sorry for the delay, I’ve been really busy with school. Here:

Transcription:

|COM3 |Arduino Uno (COM3)|USB VID:PID=2341:0043 SER=95432313538351C080A1 LOCATION=1-4|
|COM13 |Arduino Micro (COM13)|USB VID:PID=2341:8037 SER=6 LOCATION=1-1:x.0|

#18

Out of curiosity, if you instead declare it to be a micro (as in Arduino Micro) as opposed to the sparkfun promicro16? Since the board is being detected as a Arduino Micro, and they seem to be essentially the same other than for colour and layout… go with the flow it if automagically works it out?


#19

Nice thought, but alas, same behavior. :frowning_face:


#20

Well, that’s just rude… if I’m reading the hwid parameters correctly, your sparkfun board should be detected properly… :-/

The Micro has the exact same hwid also, was well as sharing a second identifer with the sparkfun pro micro.

Neither of which overlap with the uno board. How very interesting!