• Hello,

    When I have my Wifi plugged in with USB and I load the code through the IDE, everything works fine. The moment I save() it breaks and I get the I2C error above. Where should I begin to hunt down what's causing the issue?

    Full code

    Excerpt of code that is raising an error

    function setup(){
      NEOPIXEL.write(B15, [0,0,0]);
      I2C2.setup({scl:B10,sda:B3});
    
      nfc = require("PN532").connect(I2C2);
      nfc.SAMConfig();
    
      setInterval(function() {
        nfc.findCards(function(card) {
          card = JSON.stringify(card);
          checkCard(card); 
          return;
        });
      }, 1000);
    
      spi = new SPI();
      spi.setup({mosi: B6 /* D1 */, sck:B5 /* D0 */});
      g = require("SSD1306").connectSPI(spi, A0 /* DC */, B7, start,{ height : 32 });
    }
    

    Full Error Message:

    Uncaught InternalError: Timeout on I2C Write BUSY
     at line 1 col 172
    ...sh(0);this.i2c.writeTo(36,b);b=this.i­2c.readFrom(36,6);b[4]&...
                                  ^
    in function "cmd" called from line 1 col 18
    this.cmd([74,1,0]);var d=this;setTimeout(function(){var c=d....
                     ^
    in function "findCards" called from line 69 col 6
        });
         ^
    in function called from system
    

    I have also attached an image of the NFC chip I'm using. It is wired as follows:

    • NFC -> Espruino
    • GND -> -
    • VCC -> 3.3v
    • SDA -> B3
    • SCL -> B10

    I have looked at some of the Troubleshooting guides and they suggest:

    • Remove all console.log/print statements. I think I have done so.
    • Setting USB.setConsole() during onInit(). That changed nothing.

    Any pointers would be greatly appreciated, I'm very new to all of this. Thanks in advance!


    1 Attachment

    • IMG_0909.JPG
  • Hi,

    I think the issue you're seeing is that some stuff (the SSD1306 and NFC) will need initialising at power on.

    What happens when you type save() is it saves the current state of the interpreter, but that doesn't include the external hardware.

    There's more in-depth info on this here: http://www.espruino.com/Saving

    But either you could add the lines:

    function onInit() {
      // remove stuff if setup() was called previously
      clearInterval();
      clearWatch();
      // start up properly
      setup();
    }
    

    and save as you were doing, or you could use "save on send" which does what I think you're expecting happens now - which is basically to run all your code at boot time as if it were uploaded fresh each time.

    The downside of the second option is you can't fiddle with the code while it's running and then re-save it, but you may not want to do that anyway.

  • Gordon! Thank you so much for your detailed advice. The path with using "save on send" unfortunately did not work, but setting up the onInit() function like you suggested worked like a charm! And thanks for including the resource on Saving, I had not seen that yet. Very helpful.

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

'Uncaught InternalError: Timeout on I2C Write BUSY' after save()

Posted by Avatar for benortiz @benortiz

Actions