“i2c device _ read list _” hangs when i2c device not found

Issue #86 resolved
John Maloney repo owner created an issue

The “i2c device _ read list _” primitive hangs (ED1) or crashes (micro:bit) if there is no i2c device with the given ID. It should fail more gracefully.

Comments (15)

  1. connochaetes

    Since I updated microBlocks from v0.3.3 to v0.3.4 my micro:bit disconnects as soon as I use a block from the RFID library. (Even if I’m not sure if this is connected to the “i2c device _ read list _” primitive, I guess this might be the right place to mention it.)

  2. John Maloney reporter

    Yes, this is the right place to mention it.

    That’s what I see on my micro:bit with no RFID board plugged in. The MicroBlocks virtual machine is crashing and restarting. For me, the IDE reconnects to the board 5-10 seconds later (i.e. the “Connect” icon turns green again.)

    Does the RFID library work when you have the RFID board connected?

  3. connochaetes

    The behavior doesn 't depend on whether the RFID board is connected or not. Here are more details:

    • My micro:bit connects to the microBlocks IDE v0.3.4 without any problem.
    • I click on the “read PN532 RFID” block from the IDE’s official library. → disconnection & flickering yellow LED at the side of the micro:bit’s Micro USB connector
    • no automatic reconnection (no green connect icon) for the next few minutes
    • I click on the plug icon for the connection to /dev/tty/ACM0 on my Debian 10 system. → no reconnection
    • I click on “settings” & “update firmware on board”. → reconnection

  4. John Maloney reporter

    Do you have any code that calls the RFID library under a “when started” hat block? If so, that might be causing repeated crashes every time the micro:bit restarts.

    You could try creating a new, empty project, importing the RFID library, and just clicking on the “read PN532 RFID” in the palette. If my guess is right, then the micro:bit will disconnect (crash) but then reconnect again in 5-10 seconds.

  5. connochaetes

    The scripting area is empty. I activate the “read PN532 RFID” block by clicking it in the palette. I observe the behavior from my last posting. There 's no reconnection for the next few minutes.

  6. John Maloney reporter

    I think the difference in reconnection behavior might be the result of differences between Mac OS and Linux.

    In any case, I think I’ve fixed the underlying issue. MicroBlocks will give an error if it can’t talk with the i2c device rather than hanging or crashing. That fix will be in the next MicroBlocks release.

    Are you able to use the RFID library in the latest release (with the RFID board connected)? If not, does José's original program still work for you?

  7. connochaetes

    Since I upgraded microBlocks to v0.3.4, I wasn ‘t able to use any kind of RFID functionality. José’s original program shows the same behavior as described.

  8. John Maloney reporter

    That’s puzzling. There were no changes to the i2c functionality in the VM, so José’s original program should work with 0.3.4. I wonder if a wire got loose?

    If you want to revert back to 0.3.3, you can download it from here:

    https://github.com/bromagosa/microblocks-site/releases

    Be sure to install the firmware from the 0.3.3 release by starting that version of MicroBlocks and running “update firmware on board”. Then try José’s original program as a test. If that works, you might try the RFID library from 0.3.4:

    https://bitbucket.org/john_maloney/smallvm/raw/0b38c2cca6ae9c95aad905faef38ba172c7cf9f8/gp/Libraries/RFID.ubl

  9. connochaetes

    Now this is strange. I downgraded MicroBlocks to v0.3.3. I tested José's orginal program. I worked.

    I tested the new RFID library unsuccessfully. Afterwards I tested José's orginal program unsuccessfully. (….?) I checked wires. I did test runs with and without the breakout board. I re-installed MicroBlocks. I could not reproduce a working state. Sometimes MicroBlocks crashed in a way that I had to force cancelling. I guess, today I 'll call it a day and check it out systematically soon.

  10. John Maloney reporter

    This sort of random behavior could be the result of a marginal power supply. The micro:bit’s voltage regulator doesn’t provide much extra current for external devices. You might see if plugging in a battery pack helps. I believe the battery input by-passes the volage regulator so the battery pack can provide more current than you get when running off the USB.

  11. John Maloney reporter

    Just checked the specs:

    https://tech.microbit.org/hardware/powersupply/

    On USB power, the micro:bit voltage regulator can only supply 120 mA and the RFID module can use up to 150mA when transmitting:

    https://www.nxp.com/docs/en/nxp/data-sheets/PN532_C1.pdf

    So, indeed, the RFID board may be pulling too much power and causing the micro:bit to reset.

    I also confirmed that the battery power supply does not go through the voltage regulator, so you should have more current available with batteries unless they are almost dead.

    Good luck!

  12. connochaetes

    Now, that 's the “fun” with physical computing (in which you obviously got some expertise). It was actually all about the power supply.

    I used a power bank. The LED battery level display ( ~ 75 % ) obviously mislead me. After replacing the external power supply, it 's all working just fine with MicroBlocks v0.3.4, firmware v074 and the new official RFID library that came along with v0.3.4.

    Another problem solved. Thank you very much.

  13. Log in to comment