Programming / firmware updates

The firmware for the CurrentRanger is freely available as an Arduino IDE sketch and you can tweak it, change it’s default behavior and even make it better.

The sketch is published on Github here.

To compile and upload the firmware you will have to install the following packages in Arduino IDE. First ensure you have the official Arduino SAMD Boards package installed:

Then install or ensure you have the official Arduino SAMD Boards (32-bits ARM Cortex-M0+) boards package, via the Tools>Boards>Boards Manager :

Then you will need the LowPowerLab SAMD boards package, which includes the CurrentRanger SAMD21 board definition. Add the following URL to your Preferences:

Then open Tools>Boards>Boards Manager and install or update to the latest LowPowerLab SAMD package:

Then once plugged in (it has to be powered ON as well), the CurrentRanger will show as a serial USB device that you can pick as a target in the Arduino IDE, just make sure you pick the correct serial port associated with CurrentRanger from the Tools>Port menu or you may use Felix’s custom Arduino IDE with serial/port shortcut bars add-on:

The CurrentRanger’s USB port can power it for programming purposes even without a battery attached. You should only use a standard Lithium-Polymer rechargeable battery while connected to USB since there is a LiPo charger on board that expects this type of battery.

You will need to install several 3rd party libraries to be able to compile the firmware. Please see the sketch header for the links to each library, they should all be available to install through the IDE’s Tools>Manager Libraries dialog.

Older Windows Drivers

If you’re on MAC or Linux you should not need any drivers. Also Windows 10 will probably detect the board as a virtual serial port and assign it a COM port by default without the need of installing a driver. Older Windows versions are likely going to fail to install a driver when CurrentRanger is first plugged in. Click below to get the USB driver and unzip it to your Desktop or another folder. The ZIP file contains a screenshot walkthrough of how to install the driver (shown for MoteinoM0, same for CurrentRanger).

ADC calibration

The firmware code includes a call to calibrate the ADC. This is a one time call after the each programming cycle and ADC calibration values are stored in EEPROM. The SAMD21 emulated EEPROM is erased during each programming cycle and will trigger this re-calibration when the code detects empty EEPROM values for the ADC calibration. To ensure proper calibration make sure there is nothing attached to the input and output of the unit when re-programming firmware. Also, ideally you should remove the USB as soon as the programming is done to allow calibration to be as precise as possible.

LDO output value

Your CurrentRanger is provided with a label showing the measured LDO output during testing, it is a value around 3.3V. This value can slightly change based on load and how long the unit has been turned ON. If you reload firmware you should change the value to this provided value or your own measurement (measure between any GND and “3V” pins), on the following line in the firmware code, example for measured 3.305v:

#define LDO_OUTPUT 3.305 //volts

Reset button, manually running the bootloader

There is a RESET button on the bottom side. Although it should not be necessary, you may double-tap the RESET button to enter the bootloader to accept a new firmware upload if you try something that causes the SAMD21 to becomes unresponsive. You know you are in the bootloader if the LPF LED displays a breathing pattern.

OLED I2C Clock Speed

It’s desirable to speed up the clock of the I2C bus when using an I2C SSD1306 based OLED display. Without this optimization there will be more noise on the output when the OLED is connected (visible on a scope only). The “factory” firmware loaded into the CurrentRanger contains this optimization as well as the latest sketch update:

u8g2.setBusClock(1000000); //1Mhz i2C clock