Skip to content

Compiling and flashing

Andrey Klimov edited this page May 5, 2019 · 10 revisions

Platformio

  • Prefered and easiest way to compile project is using platformio toolchain, suitable for Arduino Due, Arduino Mega2560, ESP8266, ESP32.
  • Platformio will automatically download and install all required libraries for you.
  • You need updated bootloader in very ancient Megas as to allow watchdog working. (If you faced with "Mad Led issue" after Watchdog triggering). Easiest way to use Arduino IDE and re-flash bootloader to fix this issue.

Due compilation issue "USART0_Handler redefinition"

Please, edit /variants/arduino_due_x/variant.cpp file (usually located at ~/.platformio/packages/framework-arduinosam/variants/arduino_due_x/variant.cpp), and add line

void USART0_Handler(void)  __attribute__((weak));

Platformio command line build instructions

First of all install platformio framework. Good tutorial for fast start in RUSSIAN.

In linux\OSX you can open terminal, navigate to your programming directory, then

 git clone https://github.com/anklimov/lighthub.git
 cd lighthub

now prepare project files for your IDE

pio init --ide [atom|clion|codeblocks|eclipse|emacs|netbeans|qtcreator|sublimetext|vim|visualstudio|vscode]

Set custom build flags. (optionally) first make your own copy of template

cd custom-build-flags
cp build_flags_template.sh build_flags_<your_target_architecture>.sh

Where <your_target_architecture> is one of

  • megaatmega2560
  • due
  • esp8266
  • esp32
  • megaatmega2560-5500
  • due-5500
  • controllino
  • stm32
  • lighthub21
  • nrf52840_dk

then edit, change or comment unnecessary sections and source it

nano build_flag_<your_target_architecture>.sh

build and upload firmware for due|megaatmega2560|esp8266 board

pio run -e <your_target_architecture> -t upload

Clean pio libraries folder. Try it if you have compilation problem:

rm -Rf .piolibdeps

open COM-port monitor with specified baud rate

platformio device monitor -b 115200

Custom build flags

  • MY_CONFIG_SERVER=192.168.1.1 // address of external JSON-config http://192.168.1.1/cnf/de-ad-be-ef-fe-00.config.json
  • WATCH_DOG_TICKER_DISABLE //disable wdt feature
  • USE_1W_PIN=49 // use direct connection to 1W devices on 49 pin, no I2C bridge DS2482-100
  • SD_CARD_INSERTED // enable sd-card support and fix lan starting
  • SERIAL_BAUD=115200 // set baud rate for console on Serial0
  • Wiz5500 //Use Wiznet 5500 library instead Wiznet 5100
  • DISABLE_FREERAM_PRINT // disable printing free Ram in bytes
  • CUSTOM_FIRMWARE_MAC=de:ad:be:ef:fe:00 //set firmware macaddress
  • DMX_DISABLE //disable DMX support
  • MODBUS_DISABLE // disable Modbus support
  • OWIRE_DISABLE // disable OneWire support
  • ARTNET_ENABLE //Enable Artnet protocol support
  • AVR_DMXOUT_PIN=18 // PIN for DMX OUT (Only for AVR architecture)
  • LAN_INIT_DELAY=2000
  • ESP_WIFI_AP=MYAP
  • ESP_WIFI_PWD=MYPWD
  • WIFI_MANAGER_DISABLE
  • W5500_CS_PIN=53 //Custom pin for Ethernet CS (10 on most shields)
  • SYSLOG_ENABLE
  • DEVICE_NAME=MYDEVICE
  • DHT_DISABLE
  • COUNTER_DISABLE
  • CSSHDC_DISABLE - disable support of SCC811 and HDC1080 sensors

Arduino IDE method (Platformio alternative, not recomended)

  • Arduino 1.6.9 IDE or newer required.
  • Suitable for Arduino Due, Arduino Mega2560, ESP8266
  • Updated bootloader required if you have old Mega board and "Mad led" issue after watchdog timer triggering (Use SPI programmer and Tools/burn bootloader menu in Arduino IDE to update bootloader)
  • All Libraries, should be manually installed to IDE
  • If you've using Arduino IDE to compile & flash firmware, it will use Default options below and you will not able to configure additional compilers options except edit "options.h" file

Dependencies

(quite big number of libs required. Use git clone to have your local copy in your Arduino libs folder) Please check updates for all dependences.

For patched libraries, appropriate GitHub repo URL provided:

Default compilation behavior:

  • Config server: lazyhome.ru
  • Watchdog enabled
  • 1-Wire communication with DS2482-100 I2C driver
  • No SD
  • Serial speed 115200
  • Wiznet 5100 (for MEGA & DUE)
  • Free Ram printing enabled
  • de:ad:be:ef:fe:00
  • DMX support enabled
  • Modbus support enabled
  • OneWire support enabled
  • Artnet disabled
  • Defailt MQTT input topic: myhome/in
  • Default MQTT topic to publish device status: myhome/s_out
  • Default Alarm output topic alarm

First launch

  • You can use cloud configuration utility (RU) to prepare configuration of your controllers on Web interface and store to default http server lazyhome.ru. If you prefers to use your own config server - please follow next steps
  • Define MY_CONFIG_SERVER directive with any applicable http (not https) server address, available for you. If no http server you have - just install web-server-chrome plugin on your PC browser and setup your PC local IP address in MY_CONFIG_SERVER before compilation. If your prefers to use pre-compiled image - you can re-define config URL later, by get CLI command - see below
  • Compile and flash firmware.
  • Connect Ethernet Board with router LAN connection (DHCP should be enabled) and connect Arduino Mega or DUE to PC with USB cable
  • Configure terminal on 115200 Baud and use Command Line interface to invoke command mac 12:34:56:78:90:EE (with unique MAC you want) - optionally. Have a sense for Mega2560 only. ESPx have own unique MAC, DUE have unique MAC, generated automatically from MPU ID. Refer terminal log while starting MPU to find MAC address.
  • Create and place JSON config in /cnf folder of your web server with name like "12-34-56-78-90-ee.config.json"
  • Use command get <config_server_IP_or_name> to load config from your webserver (and store server name to NVRAM)
  • Restart board
  • Upon successful testing of configuration - save it NVRAM. (save CLI command)
  • Controller ready for operation.

Compiled images

Compiled image has been added to compiled/ folder. Flash your Mega 2560

avrdude  -v -V -patmega2560 -cwiring -b115200 -D -Uflash:w:firmware.hex:i

or flash your DUE (need to correct path and port, of course)

/Users/<user>/Library/Arduino15/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i -d --port=cu.usbmodem1451 -U false -e -w -v -b firmware.bin -R

Note: binary images usually not up-to-date with recent code. And compiled with default settings. The preferred way, to use Platformio method compile and upload firmware to your controller.