Git Product home page Git Product logo

tretroller's Introduction

Tretroller

This project is intended to light up a scooter. It offers a almost non-invasive speed measurement using a hall sensor and a magnet glued to the wheel, and lots of WS2812b led strips.

A cheap blue pill STM32F103 microcontroller board is used to control everything.

Features

Hall-sensor based speed measurement with software compensation for inaccurately placed magnets enable light effects synchronized to the driving speed.

8 different bottom light effects and two front/side lighting programs. Switch the bottom lights with a short button press. A longer (0.25s - 1s) press will change the front/side program and its brightness. Holding the button for more than a second performs the brightness selection.

Battery monitoring: Connect two resistors as follows: Battery (+) -----[100kOhm]----- PA0 -----[10kOhm]----- GND. The firmware will auto-detect the number of LiPo cells. The number of cells is displayed as white dots on the front, while the current battery estimate is displayed on both sides.

Battery protection: If the estimated battery cell voltage drops below 3V, the lights are turned off except for the front lights, which are dimmed and sometimes flash. This reduces power consumption to approx. 50mA.

Hardware Setup

You need a strong 5V power supply (1-5 ampere, the LEDs consume lots of power), a blue pill board (or any other STM32F103 board, actually), and a WS2812b LED strip (preferably a waterproof one, depending on what you want to do with it). I use a LM2596 DC/DC-converter to generate 5V @ max. 3A from a 3-cell LiPo battery.

Connect the 5V power supply and the GND with the blue pill and with the LED strip. The LED strip's data in pin goes to PA7, and the tacho input is at PA8. I use an open-collector hall sensor (A3144, deprecated) with an 1k pull-up. A push-button shorts PB10 to +3.3V for user input. (For convenience, you can tie the PB10-side terminal of that switch to the BOOT0 pin, too.)

Building and Flashing

cd firmware

git submodule update --init
cd libopencm3 && make -j5 && cd ..

cd src
make
stm32flash -w tretroller.bin /dev/ttyUSB0

For flashing, you need a USB-serial-converter. Connect its RX/TX pins to PA9/PA10. (And don't forget GND.)

Learning the magnet distance

It is difficult to glue the magnets perfectly equally spaced and failure to do so results in a noisy speed estimate. This problem is illustrated in the graphics below, which show a continuously spinning wheel which is slowly decelerating due to friction. The colored dots signify which magnet caused the current reading.

uncompensated compensated

Easily, one can recognize a repeating jumpy pattern in the left, uncompensated graph, while the compensation produces a quite smooth graph on the right.

To calibrate the magnet distance, do the following:

Connect the battery and an UART adapter, then run the following command to log the debug output: miniterm.py /dev/ttyUSB0 115200 | tee log.txt

Then, execute python learn.py log.txt 5, where 5 is the number of magnets. Note that this tool discards the first full wheel revolution (in fact, it discards one more pulse), assuming a steady wheel motion after this.

The last line of the output looks similar to [64306564, 65027442, 66437832, 65699997, 66208162]. Copy this array to DISTANCES in tacho.c and adjust N_MAGNETS in this file.

License

The source code is licensed under the terms of the 3-clause BSD license. This project uses the libopencm3 library, which is licensed as LGPL3 or any later version, so same terms apply to the resulting binary.

Credits

The WS2812b code was stolen and adapted from https://github.com/hwhw/stm32-projects @ a1de68cbee09631836c205106fbc2fd64d2a93ec. The original readme has been preserved here.

tretroller's People

Contributors

windfisch avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

tretroller's Issues

tacho calibration

the magnets are difficult to glue equally-spaced. try to compensate for this in software

distance measurement

Three counters:

  • Total distance ever traveled
  • Resettable distance
  • Distance since last boot

Display via:

  • BCD-encoding on the LED strips
  • Display?

battery monitoring and warning

The LEDs are quite capable of thrashing batteries, discharging them way over their limits.
There must be some battery monitoring that reduces the LED power to protect the battery

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.