Skip to the content
2 layers102.8 × 42 mmBatteryMonitor, the printed circuit board in 3D

BatteryMonitor

ieb/CanDiagnose5

Small firmware to run on an ESP32 and diagnose devices and messages on a canbus.

Size
102.8 × 42 mm
Copper layers
2
Thickness
1.6 mm
Parts
28
Nets
22
Pads
92
Tracks, vias
272, 15
Pours
6
Routed
Yes
KiCad
KiCad 4
Created
27 Oct 2021
Updated
19 Apr 2026

Overview

BatteryMonitor is an open-source printed circuit board by ieb, from the ieb/CanDiagnose repository on GitHub. It is a 2-layer board of 102.8 × 42 mm with 28 parts on 22 nets, routed with 272 tracks and 15 vias.

It is built around the MAX3485ED, MAX9918ASA+ and AMS1117. Its parts include 9 resistors, 7 capacitors, 7 connectors and 5 ICs. It belongs with the interfaces and adapters boards and the AVR (ATmega, ATtiny) boards of this library.

Main components

3

README

README.md

Can Diagnose

Runs on a ESP32 with a webserver exposing an API to diagnose and monitor CanBus traffic. Based on Datadisplay and DeviceAnalyser from the NMEA2000 libraries.

  • Setup Wifi
  • Setup MDNS registration
  • Implement webserver
  • Serve files from Flash (SPIFFS)
  • Implement data api /api/data/ where n == 0-10.
  • Expose set of standard CAN messages on /api/data
  • Implement simple UI in Javascript hosted on SPIFFS, targetting eink and normal browsers (based on SignalK eink)
  • Implement BPM280 source
  • Implement calibration mechanism using DAC
  • [Fail] Implement ADC Source

The ESP32 ADC source cannot be made reliable enough or accurate enough to be used to monitor a battery. It is possible to get down to a 0.2% error with a callibrated lookup table, however the ADC mechamism (Sucessive Aproximation Register) produced noisy values that are frequetly as much as +- 3%. At 12.6v this is 0.4v which is unworkable. Offsetting the voltage with a precision opamp so the ESP32 reads from 11 to 15v would reduce this to 0.15v, however this is still to large to be usable. Multi sampling helps generate a stable reading, however this requires 64 samples with a /5 moving average so over at least 60s. This does give and acceptable accuracy, but the speed of measuring the voltage is close to unworkable.

All attenuations were tried, and 1,2,4,16,32,64 clock divisions were tried to see if the rate of the SAR made any difference. It does not appear to change the results.

On that basis, I am giving up on using the ESP32 ADC for this purpose.

It still provides a good platform for a Wifi data server, and Can reader.

  • Redesign PCB to use 16bit ADC over i2c (ADS1115)
  • Implement ADC sensor code.
  • Implement admin interface.
  • Support configuration and calibration via web browser.
  • Support Configuraiton of single and differential ADC.
  • Add OLED display
  • Add touch sensor to control oled display
  • Bench Calibrate expecialy shunt
  • Install test and calibrate. - Failed, the distance beween the board and the batteries is too great to get reliable shunt measurements.
  • Investigate using a shunt amplifier as used by VRA Alternator controll
  • Implement remote battery sensor using Modbus (see BatterySensor project)
  • Reimplement PCB to have no BME280 and no ADS1115 replacing with a RS485 interface to ModBus devices. (see CanPressure for Can based pressure, humidity, temperature sensor)
  • Implement Modbus master

Usage

The device will boot and connect to wifi controlled by its burned in config file (data/config.txt). There are 2 modes it can run in, a WiFi client or a AP. If its configured to be an AP, then join its network. If its a client find its ip. From now on this will be

Go to its ip on http:// and you will see a data view of the data it is capturing. Go to http:///admin.html and you will see a admin view with the ability to upload a new configuration file and reboot.

Both these views ae SPAs served from static files burned into the ESP32 Flash using APIs.

Connecting to the serial port monitor allows lower level control and diagnostics, enter 'h' to get help.

Developing

Project uses PlatformIO in VSCode. WebUI is in ui/einkweb with build files added to data/ to be built into a flash image using ./buidui.sh

PIO commands

because I alwaysforget.

  • pio run -t upload
  • pio device monitor

See buildui.sh for SPIFFS image commands.

Connectors

text
---------------------------------------------
|           a b c d e f g h                 |
|  A                                        |
|  B                                        |
|  C                                        |
|  D                                     H  |
|  E                                     I  |
|  F                                     J  |
|  G           i j k l m                 K  |
---------------------------------------------

a  SPI BL   GPIO13
b  SPI RST  GPIO12
c  SPI DC   GPIO26
d  SPI CS   GPIO25
e  SPI SCK  GPIO33
f  SPI MOSI GPIO32
g  SPI GND  
h  SPI 3V    
i  i2c GND      Display black/blue
j  i2c SCL  D5    Display green
k  i2c SDA  D18    Display white
l  i2c BTN  D19    Display yellow
m  i2c 3V       Display red

eInk Waveshare display

This uses SPI output only with a bunch of additional pins.

text
eInk DIN <-  f  SPI MOSI GPIO32
eInk CLK <-  e  SPI SCK  GPIO33
eInk CS  <-  d  SPI CS   GPIO25
eInk DC  <-  c  SPI DC   GPIO26
eInk RST <-  b  SPI RST  GPIO12
eInk BUSY -> a  SPI BL   GPIO13

4 inch TFT display 480x320 24 bit colour driven by a ILI9488 driver.

uses SPI + a PWM blacklight. Control via a TPP233 Touch switch. Library is TFT_eSPI library. Pin mappings defined as compile definitions.

text
-D TFT_MISO=GPIO_NUM_35
-D TFT_MOSI=GPIO_NUM_32
-D TFT_SCLK=GPIO_NUM_33
-D TFT_CS=GPIO_NUM_25
-D TFT_DC=GPIO_NUM_26
-D TFT_RST=GPIO_NUM_27
-D TFT_PWM_BL=GPIO_NUM_14
-D ILI9488_DRIVER

The display sleeps after 60s of inactivity to reduce power drain, but turning off the backlight. Sleeping the IMI9488 driver has not been done as of yet. Pages are implemented as classes using widgets. When a page is selected it is allocated into heap and does not exist while not displaying. On other drivers here all pages were compiled in, however the RAM usage is higher on account of full colour and display size.

In most cases attempts to update the screen, on screen causes flickering so double buffering of updates is done using sprits with DMA transfers from the sprite to the screen. Images for screen are stored in jpg on flash, consuming about 30KB per screen.

Drawing to sprites also works in 1bpp, 4bpp or 16bpp.

TFT case

3d printed case, with 2 touch sensors and round shielded cable, as ribbon will emit too much interference to nearby devices.

Wires

|| color || designation || ESP32 Pin ||

| Red | 5v | 5v | | black | 0v | 0v | | pink | CS | GPIO_NUM_25 | | cyan | Reset | GPIO_NUM_27 | | white | DC/RS | GPIO_NUM_26 | | blue | SDI(MOSI) | GPIO_NUM_32 | | green | SCK | GPIO_NUM_33 | | grey | LED | GPIO_NUM_14 | | Purple | SDO(MISO) | GPIO_NUM_35 | | Orange | 3.3v | 3.3v | | Brown | Touch Lower | GPIO_NUM_19 | | Yellow | Touch Top | TBD |

Due to the additional touch pins a fresh PCB is probably needed.

Parts

28
QtyValueFootprintReferences
6RResistors_SMD:R_0805R102, R103, R105, R106, R107, R108
3100nFCapacitors_SMD:C_0805C104, C105, C106
3RS+Connect:1pinP103, P106, P107
2100KResistors_SMD:R_0805R109, R110
210uFCapacitors_SMD:C_1206C101, C103
2CONN_4Connect:bornier4P101, P102
2MAX9918Housings_SOIC:SOIC-8_3.9x4.9mm_Pitch1.27mmU102, U103
11nFCapacitors_SMD:C_0805C107
14K7Resistors_SMD:R_0805R104
1AMS1117TO_SOT_Packages_SMD:SOT-223-3Lead_TabPin2U101
1ATTINY84-SHousings_DIP:DIP-14_W7.62mmIC103
1CCapacitors_SMD:C_0805C108
1ICSP/UDPIPin_Headers:Pin_Header_Straight_2x03P104
1MAX3485EHousings_SOIC:SOIC-8_3.9x4.9mm_Pitch1.27mmIC101
1RS-Connect:1pinP105

More from ieb/CanDiagnose

1
  • 2 layers73.1 × 58.9 mmESP32CanBoard, the printed circuit board in 3D

    ESP32CanBoard

    ieb/CanDiagnose

    Small firmware to run on an ESP32 and diagnose devices and messages on a canbus.

    35 parts5

Similar boards

  • 2 layers56.7 × 25.4 mmBatteryMonitorATTiny3224, the printed circuit board in 3D

    BatteryMonitorATTiny3224

    ieb/BatterySensor

    A Modbus RTU Battery Current and Voltage sensor board based Attiny3224, MAX485, MAX9918 chips.

    24 parts1
  • 2 layers71 × 71 mmSensactUp3, the printed circuit board in 3D

    SensactUp3

    klaus-liebler/sensact

    Es gibt vier Namespaces für Nachrichten "REQUEST" und "RESPONSE", "EVENT" und "ACKNOWLEDGE". Dies wird mit den beiden LSB des Versions-Namespace-Bytes erklärt (Somit bleiben 64 Versionierungsmöglichkeiten) Alle vier…

    80 parts4Apache-2.0
  • 2 layers100 × 100 mmExplorer, the printed circuit board in 3D

    Explorer

    anyshake/explorer

    🌏 Detecting seismic wave using 3 geophones and 3-axis accelerometer, pack & send data to AnyShake Observer over RS232 / RS485 serial.

    266 parts100
  • 2 layers120 × 80 mmRx72t 100 pga usb, the printed circuit board in 3D

    Rx72t 100 pga usb

    hirakuni45/RX

    Renesas RX Microcontroller, C++ framework, Library, Sample

    113 parts86BSD-3-Clause
  • 4 layers106 × 63.5 mmBrineomatic, the printed circuit board in 3D

    Brineomatic

    hoeken/brineomatic

    Open Source Watermaker Controller.

    323 parts47LGPL-2.1
  • 4 layers100 × 75 mmOpenAirScope, the printed circuit board in 3D

    OpenAirScope

    emertcakir/OpenAirScope

    Open-source air quality and environmental monitoring node with STM32H743 + ESP32-C3, LoRaWAN, RS485, USB-C, Li-ion charging, and multi-sensor support.

    282 parts26MIT
  • 4 layers80 × 60 mm01 main, the printed circuit board in 3D

    01 main

    wgbowley/OpenLSM

    Low-Cost Linear Synchronous Permanent-Magnet Motor

    99 parts11MIT
  • 2 layers92 × 51 mmRs485-spy injector, the printed circuit board in 3D

    Rs485-spy injector

    rmingon/rs485-spy-injector

    RS485 Spy is an open-source hardware tool for real-time monitoring, logging, and testing of RS-485 networks

    44 parts7CERN-OHL-S-2.0

Questions

How big is the BatteryMonitor PCB?

It measures 102.8 × 42 mm and has 2 copper layers, 1.6 mm thick.

What parts does the BatteryMonitor use?

28 parts, built around the MAX3485ED, MAX9918ASA+ and AMS1117. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the BatteryMonitor KiCad files?

From the ieb/CanDiagnose repository on GitHub, at the commit this page was made from: the board is pcb/BatteryMonitor/BatteryMonitor.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the BatteryMonitor design in my own project?

Its repository states no licence, so its author keeps all rights: ask ieb before reusing the design.