SamuKata
Pybricks
Pybricks

patreon


Week 5&6: Sensors

With much of the input port code for the Saving LEGO MINDSTORMS initiative completed, I have turned my attention to sensors. While the focus will be on getting the standard EV3 sensors to work first, we plan to eventually support all legacy sensors as well. What was your favorite EV3 or NXT sensor?

Smart sensors

This category includes the EV3 gyro, the EV3 infrared sensor, the EV3 ultrasonic sensor and the EV3 color sensor. These "smart" sensors have a chip of their own that does most of the work and allows you to choose different modes. These sensors send the relevant information to the hub using a dedicated LEGO protocol. Fortunately, this is mostly the same as the protocol used for newer Powered Up sensors, so we can re-use this code. (This isn't to say this was easy---the protocol is a bit of a monster---but after working on it for 5 years we've got it mostly ironed out.)

Although this protocol is quite well documented by now, each of these sensor types has their own quirks that we try to handle as well as we can. Remember the EV3 gyro sensor often drifting away, for example? We'll be adding a dedicated method to calibrate it.

Fingers crossed, but I'd love to integrate the EV3 gyro with the Drive Base like we do on SPIKE. Wouldn't that be awesome?! Since the sensor itself cannot be updated, we'll have to live with the resolution and reliability that it provides though. We'll keep you posted!

Analog Sensors

This category includes the EV3 touch sensor, the NXT light sensor, the NXT sound sensor and NXT touch sensor. These are working now, and I've even taken it up a notch with the NXT light sensor. If you've used it in the past, you'll know that it was very sensitive to ambient light since it did not automatically compensate for this like the newer sensors do. We got you covered though! I've just finished adding a background process that will do this for you.

NXT Color sensor

This is such a special sensor that it has a category of its own. Released after NXT 1.0 but before EV3 came out, it is an odd mix of an analog and digital device with its own custom data protocol. Because of its special treatment and later release date, support for this sensor isn't builtin to most unofficial firmwares like ev3dev or EV3RT.

We're changing that with Pybricks though! It will be supported in full, and even allow you to calibrate your own colors like you can with the SPIKE sensors. It works as least as well as the newer sensors.

I2C Sensors

The official NXT ultrasonic sensor, the NXT temperature sensor, and many third-part sensors use the so-called I2C protocol. The EV3 doesn't support this out of the box, so we'll have to manually flip the port pins fast enough to emulate I2C support. Since none of the EV3 sensors are using this, we'll leave this for future consideration for the moment.

Third-party sensors

Where does this leave third party sensors? I don't have all of them, so we may not be able to support all of them out of the box. However, you will have all the tools to poke at the sensor port in any way you like. Once we enable general purpose I2C support and direct access to the GPIO pins, you should be able to get any third-party NXT sensor to work. Especially combined with informative resources such as the BotBench Driver Suite.

The NXT Brick?

I'm writing all this sensor code in such a way that it should also work on the NXT brick in the future. Based on how Pybricks development for EV3 is coming along, I'm quite tempted to work on the NXT at some point!

Special thanks to our MINDSTORMS legends

Special thanks to supporters of the MINDSTORMS legend tier, including Huw Millington, Chris, Nino Guba, mrhobbles, Horst Joebges, Vitalii Bondarenko, Richard Price, Tim Bohlender, John Casey, James Greilick, Jerry Nicholls, vijv, Roy Ivan Barron Martinez, Daniel Hartl, Marcelo Vera Siel, Play Brain, Minoru Inachi, Joe Meno, Károly Tisza, and Herodotus. And of course a big thanks to all anonymous sponsors in the Code with Blocks tier!

Week 5&6: Sensors

Comments

Preliminary firmware for EV3 I set up the development environment with "Visual Studio Code" on my RaspberyPi V4 with Debian bullseye as explained in the repository on Github (CONTRIBUTING.md). With "make ev3" I was then able to create "uImage" and copy it to a 32GB SD card. Unfortunately, after booting, as already described by "ste7an", I ended up in an endless loop. I tried various branches. Which one should I use?

friedrich

Great work, I am very excited about the result.

Horst Joebges


More Creators