I’m not able to develop the same sketch for this two enviroment :
[platformio]
env_default = leonardo
[env:atmega328pb]
platform = atmelavr
board = atmega328pb
framework = arduino
upload_flags = -P$UPLOAD_PORT -F
upload_port = /dev/ttyACM0
upload_protocol = stk500v1
[env:leonardo]
platform = atmelavr
board = leonardo
framework = arduino
it works fine with Leonardo, but with atmega there are a lot of missing references when I add the Wire o SPI library. es
.platformio/packages/framework-arduinoavr/libraries/cores/arduino/SPI/src/SPI.h:203:5: error: ‘SPCR’ was not declared in this scope.
The same for SPSR,SPDR and other SPI def. The same for the Wire library.
I found others SPI and Wire libs here GitHub - watterott/ATmega328PB-Testing: Atmel/Microchip ATmega328PB support for Arduino IDE and if I put them in my lib folder the problem is solved (only for the wire lib I had to add some others definitions in twi.cpp)
I think that this is not the good way because when I want to build for the Leonardo I need to go back to the native environment and this is a mess.
Could some one please help me?
Use lib_extra_dirs for the environment if you need to override generic library.
So, just create somewhere folder /some/path/custom-lib-storage/
and place here custom libraries. Later,
[env:atmega328pb]
platform = atmelavr
board = atmega328pb
framework = arduino
upload_flags = -P$UPLOAD_PORT -F
upload_port = /dev/ttyACM0
upload_protocol = stk500v1
lib_extra_dirs = /some/path/custom-lib-storage
1 Like
Thanks Ivan this can be done as I only miss some declarations es.
’#ifndef SPCR
’#define SPCR SPCR0
’#define SPSR SPSR0
’#define SPDR SPDR0
’#endif
for SPI.h and
`#ifndef TWSR
’#define TWSR TWSR0
’#define TWDR TWDR0
’#define TWCR TWCR0
’#define TWBR TWBR0
’#define TWAR TWAR0
’#endif
for Wire.h
I tough that maybe there are some .h file missing because if I build for boards (as Leonardo or Uno) everything is fine but for the atmega328pb micro alone I got that error messages… and I’m talking about native libs as Wire and SPI.
Just define macros manually with Redirecting...
1 Like
1)added
build_flags = -include /mypath/myfile.h
in platformio.ini,in the atmega328pb enviroment
2) Wrote in myfile.h the missing definitions
worked perfectly 
Thanks Ivan.