Import the libraryImport the modules
The first thing your program does is tell Pybricks: "I want to use the Pathfinder library". Without this line, the hub does not know what MBC_LINE8 means, and you get a NameError.
Pick one library. Both work the same way. Only the import line is different.
- Download the library (save the file and keep its name): MBC_line8.py (only this sensor) or MBC_sensors.py (the all-in-one library). You picked
MBC_line8.py. - Open code.pybricks.com in Chrome. Follow the steps on the site to put the Pybricks firmware on the EV3 (the release version already includes the EV3 firmware).
- Press "Import a file" in the file list on the left. Import the library into the same project.
- Do not rename the file, and do not put it in a sub-folder.
- Go back to your main program. Write the lines below at the very top (marked ① in the program on the right).
EV3 MicroPython v2 cannot use the MBC library (it does not have the PUPDevice the library needs). Use the built-in Ev3devSensor instead, and read the sensor "modes" directly. You do not need to download any file.
- Start the EV3 from the official LEGO EV3 MicroPython microSD card.
- In VS Code, install the "LEGO MINDSTORMS EV3 MicroPython" extension and create a new project.
- Open
main.py. Write the lines below at the very top (keep line 1, the one that starts with#!). - Press F5 to download it to the EV3 and run it.