Module Programming

From OpenMotics
Jump to navigation Jump to search


Every module must have firmware loaded before it can be used.

When modules are shipped by OpenMotics, the latest release of the firmware (with bootloader) is pre-programmed so the modules are ready to use. Since further upgrades are done by a single click in the cloud, this section is for your information only.

When you make your own hardware, please read the below sections carefully.

Types of Firmware files

The gateway (master controller), input, output, dim control etc all have a source file and a hex file:

  • The source file (.PBP) is the non compiled code which is in a readable format but can not be programmed in the module without going through the compilation phase. Source files can be found back in GitHub:
  • The HEX file (.HEX) is the compiled version of the source file and can be programmed directly into the module (but is not human readable). Every module will have its own specific HEX file that needs to be programmed in that module. The latest HEX files can be found back in the modules pages on

Types of HEX files

  • Hex file with Bootloader: OpenMotics has included a bootloader on every module enabling firmware upgrade with a single click in the cloud. This is only possible when the specific HEX file with bootloader is programmed on the module.
  • Hex file without Bootloader: When the source code is compiled, a HEX file is obtained without bootloader. This HEX file can be used to be programmed by using the bootloader routines available in cloud.

In other words, the first time a module is programmed, it will be programmed with a programmer (Pickit2 for example) and the HEX file WITH bootloader will be programmed. Once the modules have their initial firmware version programmed (with bootloader), the cloud will be used to perform further upgrades (HEX files without bootloader will be loaded) with a single click.

Methods of programming

2 methods of programming are available depending on the way you've setup the OpenMotics system:

  • Cloud programming: The modules will be updated over the cloud, nothing specific needs to be done. Just go to the update section in the cloud. When a new version is available, this will be displayed and by pressing update, all your modules (firmware and software) will be updated automatically. This methods of updating is only possible when the HEX file with bootloader has been programmed in the modules (Modules shipped by OpenMotics always have the version with bootloader pre-installed)
  • PICKIT2 programming: Microchip PICKIT2 programmer will be used to load the HEX files in the modules.

Cloud programming

Cloud programming is very easy and straight forward: When a new version of firmware is available, it will appear in the cloud so every user will see that a new version is available. Just by clicking Update, all modules will be upgraded to the newest version available.

Firmware Update.png

Cloud programming will only be possible when all modules have the HEX file with bootloader pre-loaded.

PICKIT2 programming

PICKIT2 Hardware

Microchip has a range of programmers available to program PIC micro-controllers. Since the PICKIT2 is a good and cheap solution, we describe the hardware programming with the PICKIT2 programmer.


Pickit2 drawing.jpg

Every OpenMotics module has a red Program Connector as described below:


Below you'll find the description of the Program Connector pins and how they must be connected with the PICKIT2:

PIN Description
1 MCLR -> Connected to Pin 1 of PICKIT2
2 VCC -> Connected to Pin 2 of PICKIT2
3 GND -> Connected to Pin 3 of PICKIT2
4 DAT -> Connected to Pin 4 of PICKIT2
5 CLK -> Connected to Pin 5 of PICKIT2
6 DEB -> Not connected on PICKIT2

Installing the PICKIT2 software

First download and install the PICKIT2 software on your PC. Below, you'll find the link of the software from Microchip when you don't have the Microsoft .net framework installed:

When you already have .Net on your PC, you can use the below link:

The standard PICKIT2 software does not support the PIC18F45K80 which is used in many of our modules. To be able to program the full list of processors, the processor database file (PK2DeviceFile.dat) needs to be updated to support the newer Microchip processors as well.

First download the PK2DeviceFile.dat


The downloaded new PK2DeviceFile needs to replace the existing PK2DeviceFile which can be found in your Pickit2 directory (c:/program files (x86)/Microchip/Pickit 2 v2). Once that file is replaced, your Pickit2 application will know the additional microcontrollers including the needed 18F45K80.

Using the PICKIT2 Software

Once the Pickit2 software is started, you get the below screen when the Pickit2 usb is not connected to your USB.


First connect your Pickit2 USB to your pc before opening the Pickit2 software. Also immediately connect your module you want to program before opening your Pickit2 software. If everything is well connected, you'll get below screen.


Please note that you must have the message "Pickit2 found and detected" and "PIC device found"

If you get below error message, the PK2DeviceFile is probably still the old version or your connections to the module are not correct. Close the Pickit2 software and follow the procedure found in the beginning of this document and check your connections between the Pickit2 and the module. Instead of closing, you can also use the menu "Tools" and then "Check Communication".


Once everything is working fine, the Pickit2 and the PIC processor are detected, you can load the HEX file in the programmer but first set the Voltage of the programmer to 3.3V. No go to File - Import HEX and select the location where you've saved your downloaded HEX file from the OpenMotics site. Please make sure you load the correct HEX file on the correct module. Every module has its own specific HEX file so make sure you load the correct one. Once loaded, you will get a similar screen as below.


The only thing you have to do now is press on the write button to program the HEX file in the module.

Important Remark: The Microcontroller PIC18F45K80/PIC18F46K80 has been used for all slave modules (input, output, Dim control, Temperature etc) except for the OpenMotics Power module. The 18F45K80/PIC18F46K80 has built-in eeprom memory which stores module settings and the slave address. When programming a new module, we don't care if this eeprom data is overwritten, however, when a module is in use and new firmware is loaded by using the Pickit2 (not by using the cloud), the "write eeprom" option must be deselected. On the bottom, you'll see "EEPROM data", deselect "Enabled" so the eeprom data of the processor will not be overwritten.