Designing the e-bike BlackBox

I am building an e-bike Blackbox to monitor the dynamics of the bike and the power consumption profile. As explained in the previous post, I have an ebike to instrument and get data off. The idea is to estimate battery discharge profiles to do accurate range and state of charge estimations. I am interested in finding out the factors that affect e-bike performance. Is it riding speed? Road incline? Outdoors weather? Stop-start riding in traffic? Weight/profile of rider? How to I maximise my riding range? This E-bike Blackbox should be able to collect data to answer these questions.

Requirements

The Blackbox needs to:

  • Measure: battery current for output and charging(1mA precision), battery voltage(10mV precision), inclination of road, humidity(as proxy for rain), temperature of battery, external temperature, e-bike velocity, acceleration.
  • Run off the battery pack
  • Consume minimal power
  • Be sturdy enough to survive near the battery pack
  • Measure the environmental values(temperature, humidity) without being affected by the system(e.g. heat from the battery)
  • Measure at least 2 weeks of non stop data
  • Option to auto upload to the cloud, when connected to wifi.
  • Cloud dashboard for data visualisation
  • Log data at max data rate of 1000 samples per second
  • Needs to handle significant noise in power supply generated by Motor
  • Need to handle inductive currents from motor
  • Needs isolation from motor.

System Architecture

The architecture of the system is as follows. There will be one main BlackBoard motherboard, with two satellite INA226 current/voltage sensors to measure the battery charge/discharge current. It will also measure the inputs from the Pedal Assist sensor and brake. GPS position and Speed, acceleration/angular velocity, temperature/pressure/humidty are also measured with on-board sensors. All data is logged to an SD card.

I have been putting my designs on Github for easy reference.

System architecture

The following table shows the variables the device will be recording and their purpose.

Inputs and their use cases

Circuit

The circuit

The main parts are the ESP32 WROOM processor, the MS8607 pressure/temperature/humidity sensor, LSM6DS3 Accelerometer/Gyroscope. It can be powered off USB power or direct from the e-bike battery. E-bike Battery voltage is regulated to 5V via the STH0548S05 buck converter module. The nice thing is the module is its surface mountable, and integrates all the circuitry(Inductor, buck converter etc). The data is stored on a microSD card, via the reader.

GPS sensing is done with a seperate u-blox module, connected to the e-bike BlackBox via a UART connection.

The e-bike battery current/voltage measurement is done with INA226 breakout boards. The INA226 measures current and voltage drop across a shunt resistor and power. It measures voltage drop at 16 bit resolution from -82 mV to +82 mV. The E-bike battery is expected to discharge up to 10 A. This current value is calculated from the maximum power of the motor: 250 W. The motor is a 24 V motor, and therefore the current consumption of the motor will go up to 10.4 A. In order to use the full voltage range of the INA226, a shunt resistor value of ~7 mΩ must be used.

INA226 Current/voltage sensor on breakout board

The USB-to-UART conversion is done by the Silabs CP2104 USB-to-UART bridge. The circuit is based on the design used on the Adafruit HUZZAH32 – ESP32 Feather, which is a known working implementation.

The PDF version of the e-bike BlackBox circuit is here.

The PCB is 90 mm X 48 mm in size. It uses 2 layers. All the surface mount components are on the top, except for the ESP32 WROOM module. All SMT components are reflowed on one side, and the ESP32 WROOM module is hand soldered onto the other side of the PCB.

PCB view

Assembling & Programming

The prototype device, v0.1 was assembled with surface mount soldering. There appear to be no fatal errors in the design so far.

Top view after reflow.
Bottom view after reflow
With peripherals(GPS and INA226 module) connected

The device is programmed with Arduino, over USB. So far, all peripherals have worked. Here is the output of the SD card tests.

I have tested the WIFI functionality here as well. It polls the NTP server and prints it out. Many thanks to this useful tutorial by Last Minute Engineers.

Assembly into E-bike wiring harness

The electronics was assembled into a waterproof case, containing the shunt resistor and the e-bike Blackbox. More work must be done to secure all the parts inside the case, and preventing them for shorting out the contacts. The circuit diagram is found below. The GPS is mounted on the outside to maximise reception. More satellites in view, the better the fix accuracy.

Issues

IO12 pin connected to SD card MISO

Issues I encountered so far are: Unexpected second functions of some pins on the ESP32 WROOM module. There are 5 pins that have second functions during boot: IO0, IO2, IO5, IO12(MTDI), I015(MTDO). I had connected IO12 to the MISO pin of the SD card holder. Turns out, if the SD card is inserted, that pin is pulled high, but must be held low during boot. Otherwise, it constantly resets, going into a boot loop. The workaround is to disable the strapping function of IO12 by setting the efuses. Instructions to do so are on the respository’s Readme.

Comments

The ESP32 is fantasic. I am really pleased with it. It has plenty of RAM/Flash storage/processing power and WIFI/bluetooth built in. The arduino platform is wonderful because of the extensive libraries and common API. In just 3 days I have most of the firmware working. It took months on a camera I worked on in a previous company. The arduino core takes care of all the peripheral drivers(i2c, uart, timers etc). This takes a long time to implement.

Acknowledgements

Many thanks to Richard Ibbotson for his assistance and advice in designing and building the e-bike BlackBox. Many thanks to Dr Billy Wu for providing the motivation/inspiration to develop this device.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *