The XOR problem stems from the famous Perceptrons (1969) book by Marvin Minsky and Seymour Papert. It can be trivially solved by a decision-tree or decision-tree ensemble. Thus it is a kind of "Hello World" example. Simple and an OK sanity check, but particularly useful.
Make sure to have Python 3.10+ installed.
Make sure to have the Unix port of MicroPython setup. On Windows you can use Windows Subsystem for Linux (WSL), or Docker.
python -m venv venv
source venv/bin/activate
pip install -r requirements.txtThis will train a RandomForest model using scikit-learn, and output xor_model.csv
python xor_train.pymicropython -m mip install https://emlearn.github.io/emlearn-micropython/builds/latest/x64_6.3/emlearn_trees.mpy
micropython xor_run.pyThe fastest and easiest to to install on your device is to use Viper IDE.
This will install the library and the example code:
![]()
!Make sure you have it running successfully on host first.
This command is for ESP32 (xtensawin). For other hardware, replace the string.
mpremote mip install https://emlearn.github.io/emlearn-micropython/builds/latest/xtensawin_6.3/emlearn_trees.mpy
mpremote cp xor_model.csv :mpremote run xor_run.py