I2C Examples

Hi there,

I'm trying to port my Espruino npm package to Kinoma. You can see it here - https://github.com/chalkers/espruino-adafruit-led-backpack (https://github.com/chalkers/espruino-adafruit-led-backpack/blob/master/index.js)

I'm having trouble accessing I2C with the documentation on the site. I saw there's the BLL way of creating modules but is there a way to just experiment with I2C directly?

Thanks.

Comments

  • I've got communication going.

    In my display.js:

    //@module
    
    const COMMANDS = {
        TURN_ON_OSCILLATOR: 0x21,
        TURN_ON_DISPLAY: 0x81,
        SET_BRIGHTNESS: 0xE0
    }
    
    exports.pins = {
        display: {type: "I2C", address: 0x70}
    };
    
    exports.configure = function () {
        this.display.init();
    }
    
    exports.close = function() {
        this.display.close();
    }
    
    exports.start = function (options) {
        this.display.writeByte(COMMANDS.TURN_ON_OSCILLATOR);
        this.display.writeByte(COMMANDS.TURN_ON_DISPLAY);
        this.display.writeByte(COMMANDS.SET_BRIGHTNESS | options.brightness);
    }
    

    And in my main.js:

    import Pins from "pins";
    var main = {
        onLaunch(){
            Pins.configure({
                display: {
                    require: "display",
                    pins: {
                        display: {  sda: 13, clock: 14},
                        ground: { pin: 12, type: "Ground"},
                        power: { pin: 11, type: "Power"}
                    } 
                },
            }, (success) => {
                if (success) {
                    Pins.invoke("/display/start", {brightness: 0});     
    
    
                } else {
                    trace("Failed to configure\n");
                }
            });
        }
    };
    
    export default main;
    

    The display is showing something!

    https://pbs.twimg.com/media/CeShNiuWsAIJ8ps.jpg

    Is there anything glaringly wrong with this code?

  • Late post, but for anyone that may end up looking at this thread--Chalkers' app has been added to our GitHub repository! You can see the source code here.

    So no, there was nothing 'glaringly wrong' with his code :)

Sign In or Register to comment.