Raspberry Pico I2C issues

Issue #303 resolved
Sean shao created an issue

Hello, I got another issue with my pico:ed board.
I2C is not working with pico. “Error: I2C transfer failed“. Is it necessary to set the i2c pin?

microblocks version: 1.1.86 vm167

Thanks

Comments (12)

  1. John Maloney repo owner

    It's not necessary to set the i2c pin before using the i2c blocks. However, a possible problem is the lack of pullup resistors on the I2C pins (pins 4 (SDA) and 5 (SCL)). With nothing connected to those pins this block:

    scriptImage1498264.png

    Should return a negative error code since there's no I2C device to respond. But attempting to write a list of bytes will give “Error: I2C transfer failed“.

    Check your connections and also make sure you are using the correct address. I like to request register 0 of the given device to check that I have the correct address. Any non-negative value means that the device responded.

  2. John Maloney repo owner

    If you are using the PicoBricks board, the "PicoBricks Test" in the "Other" folder is a quick way to verify that OLED display (an I2C device) is working.

  3. Sean shao reporter

    I tested the oled lib with my esp32 board:

    Fail:

    m5stickC plus microblocks frozen

    m5atom lite I2C transfer failed

    m5atom microblocks frozen

    Working:

    m5core working

    wemos D1 R32 working

  4. John Maloney repo owner

    This sounds like a hardware problem due to the lack of pull-up resistors built into the boards on which it is failing.

    Try adding two external pull-up resistors on the SDL and SDA lines. Each resistor should be 2k to 10k and connected between the 3.3v power and its I2C line. I am guessing that your OLED module does not have built-in pull-up resistors.

    Some microcontroller boards have built-in pull up resistors. The M5Core definitely has them since it has an optional I2C MPU. Many I2C modules have their own built-in pull-up resistors so you don't need external ones, but your OLED module may be an exception.

    If the issue is lack of pull-up resistors, this is not a software problem. You'd get the same results on that set of boards using other software such as MicroPython.

    See this for more info about I2C pullup resistors.

  5. John Maloney repo owner

    I just noticed you said "pico:ed" board in your original post.

    The "pico:ed" board is not yet fully supported. In particular, the LED matrix is not yet supported.

    That said, I think it might work with an external I2C device if you build the firmware yourself. If you are willing to use PlatformIO, you can download this repository and run:

    pio run -e pico-ed -t upload
    

    That will build and install a version of the MicroBlocks firmware for that board that should have the I2C pins mapped correctly. I think those pins are 19 and 20 on the edge connector, but check the Pico-ed documentation. The buttons, user LED, and temperature block all work. I think the main missing feature is the LED display, which needs an I2C library to control it.

    The pico-ed is a "community supported" board, which means that the MicroBlocks team does not test or support it and those using it need to build the firmware themselves. That could change in the future if the board becomes popular with educators who want to use MicroBlocks.

  6. John Maloney repo owner

    Update: I2C does work on the pico:ed board. I just tested it with the Elecfreaks Cutebot, which has an I2C motor controller, and it worked. But I think you'll need to install the pico-ed firmware using PlatformIO for it to work.

  7. Sean shao reporter

    Thanks for the thorough answer, I'll test it out. I have learned a lot from using microblocks.

  8. John Maloney repo owner

    Great! Does I2C work for you with that version? (It worked for me using the Cutebot to test.)

  9. Log in to comment