Giter Site home page Giter Site logo

pybricks-ev3-ffi-demo's Introduction

Pybricks EV3 FFI Demo

This project contains a demo of using Micropython's FFI functionality on the Lego EV3 system with Pybricks. This example project takes you through all the steps of getting the ffi module working on pybricks on EV3.

This project is not supported. The current version seems to work fine on a Raspberry Pi 4 build host connected to an EV3 via bluetooth.

Requirements

  • SSH/SCP
  • Python
  • arm-linux-gnueabi-gcc and arm-linux-gnueabi-g++ are on PATH

Tour

  • common.sh contains common functions and definitions used throughout the project to build the example code. It also contains hacks for working out of WSL, which I did in a previous version of this work.
  • demo_helloworld_ev3.sh takes the previous example a step further and demonstrates the program running on the EV3 brick.
  • demo_pyfib_ev3.sh demonstrates running some simple Fibonacci sequence calcuations on the EV3 brick in pybricks-micropython.
  • demo_cfib_ev3.sh demonstrates building, loading, and running Fibonacci sequence calculations implemented in C on the EV3 brick, loaded via the ffi module, in pybricks-micropython.

Benchmark

On my EV3 brick:

Implementation Time
Python 155ms
C 6ms

Given that micropython's Viper code generator is said to be ~4x as fast as plain micropython, this suggests that writing in C can give you approximately an additional 8x speedup compared to Viper. Probably the exact speedup depends on the project.

Next Steps

  • C++?
  • Optimizer flags?

Conclusion

I hope this is helpful to anyone who wants to use C to speed up their CPU-intensive micropython programs. I suspect this would also work for C++ libraries and I may later enhance this test to show that as well.

pybricks-ev3-ffi-demo's People

Contributors

jaguilar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.