How to define an SPI connection ...?

Posted on
  • Hi All, my problem is in short:

    • the hw: Espruino PICO 1v89 connected to MCP23S17-E/SP with two LED, etc...
    • the sw: Espruino WEB IDE, Communication set to "" and ".min.js|.js"
    • the problem: I'm using SPI, but have "i2c is not defined" and other errors, see the attachement

    Thank you for your answer!

    2 Attachments

    • xScr20170112.010.JPG
    • xScr20170112.020.JPG
  • It looks to me like someone didn't test all the modules they uploaded to :) Just a second, I'll make some fixes - what you're doing seems fine.

  • Actually I was being unfair. Espruino changed recently so it errors for undefined variables - this would have worked fine previously, but it had some code left over from being copy/pasted from the MCP20S17 that would make it fail now.

    If you try now I've changed it and it should work (you may have to shut down the IDE and restart it, as it might cache the modules).

  • @Gordon Thanks for the fast answer, it seems to working now correctly! Thank you!

  • ... and the next question, of course...:
    can I have the modul extension for MCP23S17 permanently on my PICO - that is without the WEB IDE? Currently I use for my js code always the function E.setBootCode(... .... ...); and it works fine in standalone´. Should I separately download and add the­.js´ too?

  • No, that's fine - once it's written into flash with E.setBootCode (assuming you are using the IDE to do it?) everything will be stored on the Pico, including the module

  • @Gordon thanks for the answer. No, I use an external text editor and I copy (frequently) the whole E.setBootCode (...) with ctrl+C/V to the left side of WEB IDE. In this way the download of external moduls are missing. Is there the possibility to download separately a package?lib?include?etc? to the moduls e.g. to MCP23S17 - also without the rigth side of WEB IDE?

  • Well, you can:

    • Just use the Web IDE normally and set save on send in the options, which wraps everything in setBootCode for you automatically. That'd be the sensible thing to do, but maybe you have other reasons :)
    • Use the espruino NPM package ( on the command-line. You can make this write code to Espruino, or can get it to write the code it would have written to Espruino to a file, which might be what you want?
    • Manually download modules from and try and put them in manually with Modules.addCached (inside E.setBootcode)), but that just seems a bit crazy to be honest :)
  • @Gordon thanks for the info. I'll check all the three. You're right the first is the most convenient way. Thank you!

  • Can you please give me a solution, how can I control the LED in this example (see the attached picture)? PICO can now see the MCP23S17 (see console.log() on the IDE picture), but I cannot control the LED (on/off) with port.A0.* or other commands - what I'm doing wrong?
    The cabel numbers on the picture:
    1-white) to PICO B15 (MCP->14)
    2-green) to PICO B14 (MCP->13)
    3-yellow) to PICO B13 (MCP->12)
    4-red) to PICO A8 (MCP->18)
    5-black) direct to USB-
    6-red) direct to USB+
    Many thanks in advance!

    2 Attachments

    • zz170116_012.JPG
    • zz170116_020.JPG
  • Have you set the pin mode to output?

    Also, to check it's working, you could also try reading back the values with port.readPort() and see if you can get them to change by connecting pins to 3.3v or 0v?

  • write/read was ok and readPort returns with 4801 (see att.), but no LED activitate was visible...
    ...but the LED lights up when I shortly test it at MCP-19 or MCP-20

    1 Attachment

    • zz170116_030.JPG
  • Not sure I understand? what's MCP-19/MCP-20?

    What happens to the value from readPort if you connect up other pins of the MCP23S17 to 0 or 3.3v?

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

How to define an SPI connection ...?

Posted by Avatar for xas @xas