I'm getting started helping high school students learn about robotics and we're trying to interface a Raspberry Pi 4 to the iRobot Create 2. I've got them started with some sample code for moving the robot around, but haven't found much regarding how to read from the sensors and then use sensor data to drive robot actions. We've been using the PyCreate2 library so far.
I'd definitely appreciate any help/guidance, examples that help us understand how to read sensor data (such as bumper sensors) and take action.
Thanks! Bryan

  • $\begingroup$ Hi there, I'm torn about whether or not this question is a good one for Robotics Stack Exchange. Certainly, this site is not a good place for support on a particular manufacturer's robot platform. However, your question is really more broad, I think -- "How do I read sensors and act on them in an event loop, using the iRobot Create 2 as an example?" -- and if so, I think fact-based answers on how to write good code for robots are appropriate for this site, based on my reading of robotics.stackexchange.com/tour. $\endgroup$
    – Steve
    Commented Jan 21, 2022 at 15:08

1 Answer 1


I suspect this is a question best answered by the author of the PyCreate2 library or by the manufacturer of the product, but here's a breadcrumb for you:

If you go to the library's GitHub repository, you will find an "examples" folder. There is a file there called "sensorExample.py" which has code for polling the sensors in a while loop. It doesn't act on them, but you could imagine modifying this example to get what you want. If you want to continue using this framework, I'd suggest polling the sensors in this loop and processing them in some kind of state machine in order to control the robot based on its current state and the sensor feedback.

Best of luck and happy hacking!

Please note that while I'm an iRobot employee, the postings on this site are my own and don't necessarily represent iRobot's positions, strategies, or opinions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.