M5Stack modules and Espruino

Posted on
  • Hi,

    I got a M5Stack thing with several I2C sensors. All work with Espruino. Awesome!
    I got a LEGO+ module (AKA DC Motor) which can control Lego motors from the Mindstorm series. It works using M5Stack's microPython. Capabilities are limited to turn motor to speed -255..255 and read the encoder absolute values. The actual logic is handled by a Atmel Mega328. Here an example how you talk to it via Arduino code.

    It behaves as a I2C slave device (addr 0x56), but I cannot make it work using Espruino.

    M5Stack has has several similar modules with on-board controller and I assume the way to talk to them is similar.
    Does anyone have an example of talking to those M5Stack modules which are I2C slave devices? Any of them?

    This code does not work:

    I2C1.writeTo(0x56, 0, 100, 0, 2);

    which is (supposedly) matching line 43 of the LEGO_PLUS.ino sample code.
    What am I missing?

  • I can't remember for sure, but is I2C1.writeTo(0x56, [0, 100, 0, 2]); any better? Also, did you set I2C1 up first? And did you try setting the bitrate to something low? If there's a Mega328 handling it, it may not be happy with high speed I2C.

    Another thing to do might be to use a software I2C instance just in case...

  • Thanks for the quick reply Gordon!
    And yes, setup is done:

    I2C1.setup({scl: D22, sda: D21, bitrate: 400000});
    I2C1.writeTo(0x56, [0, 100, 0]);    // the 2 is not needed as it's the length of the data

    Tried with [] and without, with 100 and 400 kbit/s

    I cannot change the pins. I can see/detect the slave Mega328. I2C1 works for everything I throw at. I think I'm missing something to make the Lego+ module "start" somehow.
    My hope is someone uses a M5Stack module and loves using Espruino on it too.

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

M5Stack modules and Espruino

Posted by Avatar for HaraldK @HaraldK