How to add and incorporate external physical code to MIT App Inventor

You could start here

then move on to the Open Source section, using and writing extensions.