I2c NodeMCU esp8266 and Raspberry Pi Pico using pico-sdk C/C++

Hello, does anyone know how to convert this micropython code into c/c++ pico-sdk using i2c, I need this for my AI project with the edge impulse c++ sdk, please help. The Raspberry Pi pico as the master and NodeMCU esp8266 as the slave.

Micropython code (working):

#Code for Raspberry Pi Pico
import utime
import machine
from machine import I2C

I2C_ADDR = 0x05 #I2C Address of NodeMCU
data = "BinFull" #Data to send to I2C device

def main():
    print("Initalizing I2C as Master")
    i2c = I2C(0, sda=machine.Pin(16), scl=machine.Pin(17), freq=10000)
    while True:
        i2c.writeto(I2C_ADDR, data) 
        a = i2c.readfrom(I2C_ADDR, 8)

C++ code using pico-sdk (not working):

#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/i2c.h"

#define I2C_PORT i2c0

static int peripheral_address = 0x05;

int main()
    char data[] = "BinFull";
    char data_to_receive[] = "";


    i2c_init(I2C_PORT, 10000);
    gpio_set_function(8, GPIO_FUNC_I2C);
    gpio_set_function(9, GPIO_FUNC_I2C);
    while (true)
        i2c_write_blocking(I2C_PORT, peripheral_address, (uint8_t *) data, 7, true);
        i2c_read_blocking(I2C_PORT, peripheral_address, (uint8_t *) data_to_receive, 8, false);
        for (int i = 0; i < sizeof(data_to_receive); ++i)
            printf("%c", data_to_receive[i]);

    return 0;

Hi @Boratron,

Are you seeing any errors related to running the Edge Impulse SDK on the Pico? I don’t see any calls to Edge Impulse functions in your code. If you are looking for general C++ help with the Pico, your best bet is to create a post in the official Raspberry Pi Pico forums: Raspberry Pi Pico - Raspberry Pi Forums.


No errors related to running the sdk on the Pico. I just want to make the i2c code work in C++ /C with the pico and esp8266 so I can add the code to my edge impulse project. And yeah i’ll try the forum link you pasted, thanks for replying.