Тулчейн разработки под Arduino для ценителей командной строки: PlatformIO или как перестать использовать Arduino IDE


Arduino . , . >10 .



?


, Arduino , IDE :
  • - , Gemfile/requirements.txt/package.json,
  • Git VCS

Arduino . , . Atmel Studio Visual Studio CE . .



Ino


Ino — , Arduino.
, >200 . 2014, IDE ( 1.5).
Arturo, , - .


Arduino-Makefile


Arduino-Makefile — make. Arduino Due, Zero 32- . IDE , , . , Arduino-Makefile SparkFun Pro Micro.



PlatformIO


PlatformIO — , . , (Atmel AVR, Atmel SAM, ST STM32, TI MSP430 ). ( PlatformIO ): Arduino, Energia, mbed, Atmel AVR, espressif, MSP430.
PlatformIO , IDE: Atom, CLion, Eclipse, Emacs, NetBeans, Qt Creator, Sublime Text, Vim Visual Studio
PlatformIO :
  • , ..
  • , .. ,
  • ssh, PlatformIO Raspberry Pi

image


Arduino

, , Quick Start
PlatformIO Arduino IDE, platformio.ini . .
PlatformIO Arduino. , PlatformIO. platformio.ini :
[env:nanoatmega328]
platform = atmelavr
framework = arduino
board = nanoatmega328

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

[env:due]
platform = atmelsam
framework = arduino
board = due

[env:teensy31]
platform = teensy
framework = arduino
board = teensy31

[env:nodemcu]
platform = espressif
framework = arduino
board = nodemcu

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

:
platformio run

uno :
platformio run -e uno

uno:
platformio run --target upload -e uno

:
platformio serialports monitor

.zshrc :
alias compile="platformio run"
alias upload="platformio run --target upload"
alias serial="platformio serialports monitor"

:
compile         #    
compile -e uno  #   uno
upload  -e uno  #  uno
serial          #   

Travis CI CI , .
- Arduino IDE , .


PlatformIO

PlatformIO , Arduino IDE . :
  • PlatformIO Arduino IDE, PlatformIO Arduino IDE
  • Arduino IDE
  • platformio lib

Serial.print(" ");


?


Serial.print()
, "pin_2 = < 2>, pin_3 = < 3>" :
Serial.print("pin_2 = ");
Serial.print(digitalRead(2));

Serial.print(", pin_3 = ");
Serial.println(digitalRead(3));

, . Serial.print(), .



arduinoLogging


printf- , LOGLEVEL . Error, Info, Debug Verbose.
:
  #include "Logging.h"

  // LOGLEVEL   LOG_LEVEL_X,  X ∈ { NOOUTPUT, ERRORS, INFOS, DEBUG, VERBOSE }
  #define LOGLEVEL LOG_LEVEL_INFOS

  void setup() {
    Serial.begin(9600);
    Log.Init(LOGLEVEL, &Serial);

    //   
    Log.Info("pin_2 = %d, pin_3 = %d"CR, digitalRead(2), digitalRead(3));

    //    
    Log.Debug("   ,   LOGLEVEL = LOG_LEVEL_INFOS");
  }


wildcardcommentExample
%sreplace with an string (char*)Log.Info("String %s", myString);
%creplace with an characterLog.Info("use %c as input", myChar)
%dreplace with an integer valueLog.Info("current value %d",myValue);
%lreplace with an long valueLog.Info("current long %l", myLong);
%xreplace and convert integer value into hexLog.Info ("as hex %x), myValue);
%Xlike %x but combine with 0x123ABLog.Info ("as hex %X), myValue);
%breplace and convert integer value into binaryLog.Info ("as bin %b), myValue);
%Blike %x but combine with 0b10100011Log.Info ("as bin %B), myValue);
%treplace and convert boolean value into "t" or "f"Log.Info ("is it true? %t), myBool);
%Tlike %t but convert into "true" or "false"Log.Info ("is it true? %T), myBool);


advancedSerial


Error, Info, Debug Verbose arduinoLogging . Error , LOGLEVEL ( NOOUTPUT).
printf , advancedSerial.
advancedSerial : print() println() .
  int a = 1;
  int b = 2;

  aSerial.print("a = ").print(a).print("b = ").println(b);

  //     
  aSerial.p("a = ").p(a).p("b = ").pln(b);

Basic.ino
Serial.print() Serial.println(), , , Serial aSerial.
v, vv, vvv, vvvv, , -v, -vv .
, vv -> vvv Info -> Debug.
  #include "advancedSerial.h"

  void setup() {
    Serial.begin(9600);

    aSerial.setPrinter(Serial);    //      

    //  ,      v  vv,  vvv  vvvv   
    aSerial.setFilter(Level::vv);
  }

   void loop() {
     aSerial.l(Level::vv).pln(" ");
     aSerial.l(Level::vvv).pln("  ");

     delay(3000);
   }

Advanced.ino



F(), (SRAM), F():
  aSerial.print(F(" 16 "));

advancedSerial Serial, . Arduino Uno, 2KB .

, - :
  void setup() {
   Serial.begin(9600);
  }

  void loop() {
    Serial.print("test");
    Serial.println("test");
  }

storage space: 5%
dynamic memory: 9%

advancedSerial:
  #include <advancedSerial.h>

  void setup() {
   Serial.begin(9600);

   aSerial.setPrinter(Serial);
   aSerial.setFilter(Level::vv);
  }

  void loop() {
    aSerial.print("test").println("test");
  }

storage space: 5%
dynamic memory: 10%

examples/Advanced.ino
storage space: 9%
dynamic memory: 26%

examples/Advanced.ino F()
storage space: 9%
dynamic memory: 10%
. advancedSerial , , Debug.



?


Arduino IDE ( #include ) . - , . , . Arduino IDE PlatformIO.


Arduino IDE


Arduino IDE, . : (?) libraries ( Arduino IDE).
, , Arduino IDE libraries , libraries . Arduino IDE.


PlatformIO


PlatformIO lib, . . PlatformIO platformio lib, , lib platformio.ini :
[platformio]
lib_dir = ./lib

platformio lib .

Source: https://habr.com/ru/post/ar392639/


All Articles