This project demonstrates the integration of embedded systems with 3D visualization, using a Microbit v2 microcontroller to control objects in Blender through motion sensing. It serves as both an educational resource for learning embedded Rust programming and a practical example of sensor data visualization.
The system captures motion data from the Microbit's accelerometer and visualizes it in two ways:
- A real-time 3D object controller in Blender
- A more physical visualization using Python's Matplotlib, showcasing vector components.
As this is a hobby/learning project. Contributions and improvements are warmly welcomed!
- An Ubuntu/Debian-based Linux system
- Other Linux distributions may work but are not officially tested yet
- A Microbit v2 microcontroller (v1 is not supported)
- Blender (tested with version 4.3+)
- A USB connection to the Microbit
- Python 3.8 or newer
-
Clone this repository:
git clone https://github.com/VHenrik007/microblender cd microblender -
Run the installation script:
chmod +x install.sh sudo ./install.sh
The script will install:
- Required system packages (clipping tools,
curl, etc...) - Rust and embedded development tools (
cargo-embed,llvm-tools, and our target) - Python dependencies in a virtual environment (
python-venvand thenmatplotlib) - Microbit udev rules for USB access
Default values:
- Networking
-
- Host: 127.0.0.1
-
- Blender: 65432
-
- Matplotlib: 65434
- Serial:
-
- Baud rate: 115200 (set in the firmware and the bridge)
-
- Output data rate: 50Hz (set in the firmware and visualization scripts)
There are two visualizations currently. One with Blender, and one using Matplotlib in Python. The latter could be changed to something more performant in the future.
-
Connect your Microbit via USB
-
Run the project with your preferred visualization:
./run.sh --blender # For Blender visualization ./run.sh --visualizer # For Python visualization ./run.sh -b -v # For both visualizations
When using the Blender visualization:
- Open Blender
- Switch to the Scripting workspace
- Create a new text file
- Paste the contents of
blender.py(automatically copied to clipboard by the run script) - Click "Run Script"
You should see the default cube that responds to your Microbit's movement.
┌─────────┐ Serial ┌────────┐ TCP/IP ┌──────────────┐
│ Microbit├───────────────┤ Bridge ├──────────────►│ Visualizers │
└─────────┘ (USB) └────────┘ (Local) └──────────────┘
board/: Rust firmware for the Microbitbridge/: Rust-based data forwarder- Visualization Components:
blender.py: 3D object controlvisualization.py: Direct visualiation of force vectors
If you encounter permission issues:
- Unplug and replug the Microbit
- Simply retry building the board. Sometimes some ARM issue occurs that goes away for the second attempt.
- Verify udev rules:
ls -l /dev/ttyACM0
If the visualizations aren't receiving data:
- Check the Microbit connection:
ls /dev/ttyACM* - Verify no other program is using the port:
lsof /dev/ttyACM0
Sometimes it's helpful to run components separately in their own terminal windows/tabs for debugging. From the project root:
-
Flash the Microbit:
cd board cargo embed --features v2 --target thumbv7em-none-eabihf -
Run the bridge (in a new terminal):
cd bridge cargo run -- --blender --visualizer -
Start Python visualization:
source .venv/bin/activate python visualization.py
Contributions are welcome! I'm planning on enhancing the actual sensor logic itself by including the magnetometer later on for example, and introducing algorithms/numerical methods for enhanced motion stability, etc. I'd be especially thankful for cross-platform validations, and more robust installation/running and networking solutions, even if that includes using containerization. I'm also open for additional tooling and potential CI/CD proposals. Improvements on more insightful visualizations and data processing are also welcomed.
Please feel free to:
- Open issues for bugs or feature requests
- Submit pull requests with improvements
This project builds upon several excellent resources:
This project is released under the MIT License. See LICENSE for details.
Component Licenses:
- Microbit firmware: Based on Discovery book examples (MIT)
- Python visualization: Uses Matplotlib (PSF License)
- Blender integration: Uses Blender Python API (GPL)