Upload a firmware to the node with the d-diot hub v.2.0

To upload the firmware to your Arduino based MySensors node you can use the Arduino IDE that is quite easy to use, but you need a separate PC to run it.

To flash an Aduino Pro Mini or directly an ATMega MCU, like the one present in some PCB of this project, you need an FTDI adapter.

FTDI adapter with selectable voltage (3.3V and 5V)

Since d-diot image v.1.1 you can use your d-diot hub to flash your Arduino board, but only if the firmware is built with PlatformIO, like the ones present in the d-diot github repository.

This is possible because, respect to the Arduino IDE, PlatformIO has a CLI interface and can run on a headless machine. PlatformIO is one of the dependencies of ESPHome, so it is already installed if you are running a d-diot image v.1.1 or above.

In this article you can find a more detailed comparison between the two IDE, but one of the advantages of PlatformIO is the library management.

To configure the USB port auto detection in PlatformIO run the following commands:

pi@d-diot:~ $ curl -fsSL | sudo tee /etc/udev/rules.d/99-platformio-udev.rules
pi@d-diot:~ $ sudo usermod -a -G plugdev homeassistant

Reboot your system:

pi@d-diot:~ $ sudo reboot

The best way to explain how to do that is with an example using the d-diot-personalize-node firmware. Of course the process is the same for other programs built with PlatformIO, simply change some folder path.

The first step is to open a terminal and switch to Home Assistant user.

pi@d-diot:~ $ sudo -u homeassistant -H -s

Create a folder to store your PlatformIO projects. This step is not necessary for the d-diot images 1.2 and above:

homeassistant@d-diot:/home/pi $ cd /home/homeassistant
homeassistant@d-diot:~ $ mkdir /home/homeassistant/pio

Enter into the PlatformIO projects directory:

homeassistant@d-diot:~ $ cd /home/homeassistant/pio

Download the d-diot-personalize-node PlatformIO projects from the d-diot github repository and enter in the project folder.

homeassistant@d-diot:~/pio $ git clone
homeassistant@d-diot:~/pio $ cd /home/homeassistant/pio/d-diot-personalize-node

To select your board type (Arduino Uno, Nano, Pro Mini, etc..) edit the platformio.ini file.

homeassistant@d-diot:~/pio/d-diot-personalize-node $ nano platformio.ini

Look for the [platformio] section at the beginning of the file.

env_default = uno
;env_default = nanoatmega328new
;env_default = nanoatmega328
;env_default = pro8MHzatmega328
;env_default = pro16MHzatmega328
;env_default = megaatmega2560

Leave uncommented only the line with your target board (Arduino Uno in the example above).

Activate the python virtual environment:

homeassistant@d-diot:~/pio/d-diot-personalize-node $ source /home/homeassistant/ESPHome/env/bin/activate

Now is time to connect your Arduino board to one of the four USB ports of the Raspberry Pi.

Then compile (build) the source code and upload the resulting binary file to the Arduino.

See the PlatformIO documentation to known more about the Platformio CLI usage

(env) homeassistant@d-diot:~/pio/d-diot-personalize-node $ platformio run --target upload

If for some reason the USB port autodetect is not working properly, you can specify manually the USB port adding the –upload-port parameter to the platformio command:

(env) homeassistant@d-diot:~/pio/d-diot-personalize-node $ platformio run --target upload --upload-port /dev/ttyUSB0

To list all the USB devices recognized by PlatformIO run the following command:

(env) homeassistant@d-diot:~/pio/d-diot-personalize-node $ platformio device list

If you want to compile and upload for a specific board (Arduino Nano with the new bootloader in this example) without editing the platformio.ini file, run the following command:

(env) homeassistant@d-diot:~/pio/d-diot-personalize-node $ platformio run -e nanoatmega328new -t upload

To compile without uploading, run the following command:

(env) homeassistant@d-diot:~/pio/d-diot-personalize-node $ platformio run -e nanoatmega328new

To open the serial monitor and check the serial output of your node:

(env) homeassistant@d-diot:~/pio/d-diot-personalize-node $ platformio device monitor

Once you have finished with PlatformIO, deactivate the python virtual environment and switch back to the pi user:

(env) homeassistant@d-diot:~/pio/d-diot-personalize-node $ deactivate
homeassistant@d-diot:~/pio/d-diot-personalize-node $ exit

  • how_to/mysensors/firmware_upload.txt
  • Last modified: 2021/02/15 16:41
  • (external edit)