Porting Arduino Libraries?

Posted on
  • How would you go about porting a library from Arduino to an Espruino module??

  • It depends on what it is - if it's SPI or I2C the commands are pretty similar, so all you're really doing is changing C to JavaScript. If it's moving pins up and down you need to give it a bit more thought because ideally you want to be using setWatch to respond to events on pins.

    A good start would be looking at the existing modules in: https://github.com/espruino/EspruinoDocs­/tree/master/devices

    In terms of development, what I tend to do is something like this in the right of the web terminal:

    var exports = {};
    exports.connect = function(pina, pinb, pinc) {
    var foo = exports.connect(A1,A2,A4);

    And then I get everything working as I want, and when I'm done I copy the exports.connect bit into a JavaScript file. After that, you can put the JS file on a webserver (even if it's on your local PC) and access it via URL:


    Note that you have to have the webserver set up to serve up the file with the Access-Control-Allow-Origin "*" header so that JavaScript can access it correctly :(

    And when that works, you could add it to https://github.com/espruino/EspruinoDocs­/tree/master/devices and issue me a pull request :)

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Porting Arduino Libraries?

Posted by Avatar for StuntMonkeh @StuntMonkeh