Skip to the content
PCBKitNew board
2 layers237.2 × 162.5 mmSBBMicro, the printed circuit board in 3D

Source code for the self-balancing-bike microcontroller unit

Size
237.2 × 162.5 mm
Copper layers
2
Thickness
1.6 mm
Parts
38
Nets
145
Pads
304
Tracks, vias
192, 0
Routed
Yes
KiCad
KiCad 6 (file 20211014)
Created
21 Feb 2022
Updated
18 Feb 2026

Overview

SBBMicro is an open-source printed circuit board by stefphd, from the stefphd/SBBMicro repository on GitHub. It is a 2-layer board of 237.2 × 162.5 mm with 38 parts on 145 nets, routed with 192 tracks and 0 vias.

It is built around the TEENSY 4.1, LIS3MDL and A4988, with the ISM330DHCX among its other parts. Its parts include 13 connectors, 11 ICs, 1 capacitor, 1 resistor and 1 diode. It belongs with the NXP (LPC, Kinetis, i.MX RT) boards of this library.

Main components

4

README

README.md

Introduction

This repository contains the source code for the self-balancing-bike micro-controller unit (Teensy 4.1-based 🚀️). The introduction shows the files and folders contained in this repository and how they are organized, the prerequisites necessary, and the procedures to be used in order to build and upload the code, to generate the documentation, and to automatically generate the control-algorithm code from the Simulink model (using matlab tools).

Windows is officially supported, although compilation is also implemented for Linux. MacOS is NOT supported.

Files

Files:

  • controlModel.slx: control model implementation in Simulink
  • gencode.m: MATLAB function for code generation from Simulink model
  • params.sldd: Simulink parameters used in controlModel.slx
  • build_linux.sh: build shell script for Linux
  • build_win.bat: build shmell script for Windows
  • Doxyfile: configuration file for documentation generation from source code using doxygen
  • Makefile: makefile for building, uploading and documentation generation using make
  • startup.m: startup file for MATLAB (just to add necessary path)
  • INSTALL_PREREQ.md: guide for the installation of the pre-requisites
  • README.md: readme file

Code folders:

  • ./include: contains .h files included in source code
  • ./src: contains source .c or .cpp files, including main file main.cpp
  • ./lib: contains a folder for each used library, with file library.properties for defining the library properties (mandatory for arduino compiling) and .h and .cpp files (possibly contained in folder ./src/)
  • ./tools/teensy: contains the core code for the Teensy microcontroller

Additional folders:

  • ./tools/teensy-windows: build tools for Windows
  • ./tools/teensy-linux: build tools for Linux
  • ./docs/html: contains the documentation in html (generated automatically from source code using doxygen)
  • ./docs/extra: contains extra documentation (user-written), which is included using doxygen
  • ./matlab-tools: contains matlab tools usefull for code generation and other stuff
  • ./hardware: contains the kicad project files
  • ./.vscode: contains VS code property file(s)
  • ./.build and .cache: hidden folders created only during compilation

Pre-requisites

  • MATLAB/Simulink with the Embedded Coder Toolbox installed (>=2021a), for control algorithm code generation only

No other dependecies are necessary: all used libraries are already included in ./lib/.

Additional utilities (only recommended):

  • make to build using the Makefile; alternativelly, shell or MATLAV scripts can be used
  • Visual Studio Code with C/C++ extension for code completation
  • Doxygen to generate the documentation
  • KiCad to open the schematic files in ./hardware

See the installation guide for the pre-requisites for details.

Documentation

Documentation for the source code and the user-defined libraries (but not for other third-party libraries) can be generated from the source using Doxygen with

bash
doxygen

or using make

bash
make doc

Generated documentation includes only a html version in ./docs/html, with main file index.html. Documentation is also available on https://stefphd.github.io/SBBMicro/. A latex documentation may be also generated by setting

doxygen
GENERATE_LATEX  = YES

in Doxyfile. The latex version will be in ./docs/latex, and can be compiled using latex with

bash
cd ./docs/latex
make

which generates the pdf file ./doc/latex/refman.pdf.

\attention Latex documentation requires having both latex and make installed.

Code generation

Code generation of the control algorithm is performed via MATLAB/Simulink with the Embedded Coder Toolbox. Other toolboxes may be required. Code generation can be launch with MATLAB using

MATLAB
startup;
gencode

The general usage of this function is

MATLAB
startup;
gencode(modelname,dest_dir);

where modelname is the name of the Simulink model (without the *.slx extension included), while dest_dir is the destination directory: generated code is placed in ./dest_dir/modelname/src. If no modelname is given, the function uses the first *.slx file found in the current directory. If no destination directory is given, the functions uses ./lib. Code generation may be also performed using make, however this may take some time.

\note Toolboxes required by the code generation can be shown by running in MATLAB

MATLAB
startup;
check_toolbox();

\attention For a correct usage in this project the above functions should be run in the main directory, and not in ./matlab-tools/.

Building

Compilation is performed using the arduino-builder. Bash scripts provide simple usage depending on the operative system:

  • Linux:

    bash
    ./build_linux.sh

    or

    bash
    bash build_linux.sh

    \note Tested with Arch-Linux x64.

  • Windows:

    bash
    ./build_win.bat

    \note Tested with Windows 10 x64.

  • MacOS: not implemented yet, however it should be similar to Linux.

Alternatively, one can use ctrl+shift+B to build the code in Visual Studio Code with both Linux and Windows (this makes use of build_linux.sh or build_win.sh depending on the operative system). One may also use make the building and uploading.

\note The above shell scripts perform both the building and the uploading: it is not possible to build or upload only.

Make tools

One may also use make for the building, uploading and the documentation generation. This allows several operations using similar syntax, so as to perform single operations at a time:

  • make or make all to build and upload the code.
  • make build to build the code only
  • make upload to upload code only
  • make clean to clean the build and cache directories
  • make remake to clean, build and upload the code
  • make rebuild to clean and rebuild
  • make doc to build the documentation
  • make cleandoc to clean the documentation
  • make help to print the Makefile help

\note The above commands can be also used at the same time, e.g. make build doc to build and generate the documentation.

MATLAB make

As an alternative to make and gencode, the code generation, buiding, uploading and documentation generation may be also performed at the same time from within the MATLAB command window. This employs a MATLAB function name make in ./matlab-tool/. The function must be used inside MATLAB with the following syntax:

  • make all or just make to generate code from the Simulink model, build and upload

  • make gencode to generate the code only from the Simulink model. Note that this corresponds to call gencode with no input arguments, i.e. the first *.slx file found is used

  • make build to build the code

  • make upload to upload the code

  • make clean to clean the build and cache directories

  • make remake to clean, build and upload the code

  • make rebuild to clean and rebuild

  • make doc to build the documentation

  • make cleandoc to clean the documentation

  • make help to print the help.

\note Note that this function emulates the function gencode and the standard make commands. However, it does not require having make installed but only doxygen for the generation of the documentation.

\note The above commands can be also used at the same time, e.g. make build doc to build and generate the documentation.

Known issues

  • Undefined identifiers found by Visual Studio Code, however this is only a C/C++ IntelliSense issue (compilation works fine)

\todo Doc: Documentaton for Simuling and code generation??? \todo Make Arduino functions working in Simulink when compiling (maybe declare Arduino functions as external in Simulink, so as the linker links them) \todo To implement brake motor

Parts

38
QtyValueFootprintReferences
2Brake mtr JSTConnector_JST_inches:JST_1x04_P2.54J1, J12
2Power JSTConnector_JST_inches:JST_1x04_P2.54J4, J10
1100uCCapacitor_THT:CP_Radial_D5.0mm_P2.50mmC1
1A4988SBBMicro:A4988U11
1ArcherM+Connector_JST_inches:JST_1x04_P2.54U8
1Aux analog JSTConnector_JST_inches:JST_1x04_P2.54J2
1Bat inTerminalBlock:TerminalBlock_bornier-2_P5.08mmJ9
1Brake mtr outConnector_JST_inches:JST_1x04_P2.54J15
1DDiode_THT:D_DO-34_SOD68_P7.62mm_HorizontalD1
1ESCON_module-50/5SBBMicro:Escon module-50-5U10
1Encoder JSTConnector_JST_inches:JST_1x05_P2.54J7
1ISM330DHCXSBBMicro:ISM330DHCXU4
1LIS3MDLSBBMicro:LIS3MDLU5
1MCP4922-AKSBBMicro:MCP4922-AKU6
1Mecostrain2038SBBMicro:Mecostrain-2038U1
1ON/OFFButton_Switch_THT:SW_PUSH_6mmSW1
1On/off JSTConnector_JST_inches:JST_1x03_P2.54J5
1Power mtr outTerminalBlock:TerminalBlock_bornier-2_P5.08mmJ16
1R220Resistor_THT:R_Axial_DIN0204_L3.6mm_D1.6mm_P5.08mm_HorizontalR1
1RelaySBBMicro:RelayU9
1Steer trq & ang JSTConnector_JST_inches:JST_1x06_P2.54J8
1Steer mtr JSTConnector_JST_inches:JST_1x06_P2.54J3
1Teensy4.0teensy:Teensy40U3
1Teensy4.1teensy:Teensy41U2
1Throttle JSTConnector_JST_inches:JST_1x02_P2.54J6
1UltimateGPSSBBMicro:Ultimate-GPSU7
1Voltage_regulator_12VSBBMicro:Voltage-reg_12VVR1
1Voltage_regulator_5VSBBMicro:Voltage-reg_5VVR0

The 30 most common of 38 parts.

Questions

How big is the SBBMicro PCB?

It measures 237.2 × 162.5 mm and has 2 copper layers, 1.6 mm thick.

What parts does the SBBMicro use?

38 parts, built around the TEENSY 4.1, LIS3MDL, A4988 and ISM330DHCX. 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 SBBMicro KiCad files?

From the stefphd/SBBMicro repository on GitHub, at the commit this page was made from: the board is hardware/SBBMicro.kicad_pcb and its schematic hardware/HV-schematic.kicad_sch. PCBKit opens the board in the browser, with nothing to install.

Can I use the SBBMicro design in my own project?

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

Similar boards

  • 2 layers127.5 × 62 mmAvionics project, the printed circuit board in 3D

    Avionics project

    TUSI-KHU/2026-nura-avionics

    Embedded flight controller for the 2026 NURA competition.

    75 parts2Apache-2.0
  • 6 layers98 × 27.5 mmOvio core, the printed circuit board in 3D

    Ovio core

    korken89/ovio_core

    Work in progress. PCB have arrived for v1.0 of the board and bring-up has started.

    196 parts30
  • 4 layers30.2 × 20.5 mmBLDCM MCU, the printed circuit board in 3D

    BLDCM MCU

    brenocq/bldc-motor

    High-precision BLDC motor and controller development from scratch (in progress...)

    91 parts13MIT
  • 2 layers38.2 × 50.1 mmIMU module, the printed circuit board in 3D

    IMU module

    MohamadAminGhanoum/IMU-board

    planning to make a module that has small sensors on the pcbs, which will give me motion data, which i will track and recieve on either my phone or computer using the usb-c

    21 parts1
  • 4 layers68.8 × 68.6 mmGMWM Analysis Board, the printed circuit board in 3D

    GMWM Analysis Board

    thejamesrhodes/IMU-Quantisation-research-project

    Research into quantisation effects in MEMS gyroscopes using custom STM32 hardware.

    163 parts1MIT
  • 2 layers80 × 80 mmVECTRON V1, the printed circuit board in 3D

    VECTRON V1

    arudhranpk/VECTRON_V1

    This is a custom made flight computer designed for sounding rockets.

    161 parts
  • 2 layers101.6 × 53.3 mmArduinoMega Ethernet, the printed circuit board in 3D

    ArduinoMega Ethernet

    dmanla/SecureConnectivityDevelopmentPlatform

    A development platform which provides secure connectivity and data logging support while maintaining compatibility with Arduino-Mega hardware and software.

    116 parts
  • 4 layers11.2 × 18 mmImu board, the printed circuit board in 3D

    Imu board

    eshazen/ninjanirs-imu

    IMU and multiplexer designs for ninjaNIRS

    10 parts