Raspberry pico. setting SDA, SCL using Arduino ide

setup is a classic 16x2 LCD with i2c module run off a Raspberry Pico and have failed at understanding how to set the gpio 4 and 5 as SDC and SCL using the Arduino ide.
every example and video I have found is in python and they set a value to the pins but I have no idea what function it is for Arduino ide and the syntax for that.

secondly the 3.3v will be enough to set the SDC and SCL lines? I can power the display from the 5v
to have a bright display but do the SDC and SCL have to be logic converted to 5v for the lcd?

There are LCD displays for 3.3V, that will be easier.

A 5V LCD display needs to be powered with 5V. It has probably pullup resistors from SDA to 5V and from SCL to 5V.
In the schematic of Adafruit for the I2C backpack module, they use are 4k7 pullup resistors.
That means that a current from 5V via the 4k7 flows into SDA and SCL. Since the Raspberry Pi Pico does not have 5V tolerant pins, you need a I2C level shifter.

There is an option to connect a 5V display to a 3.3V Raspberry Pi Pico: in a simulation !
This seems to work: PiPlusLCD.ino - Wokwi Arduino and ESP32 Simulator

For the pins, use the most common and default that everyone uses:

Wire.begin();     // use the default, GPIO4 = SDA, GPIO5 = SCL

IF you use Earl's core for Arduino:
https://github.com/earlephilhower/arduino-pico

The docs are here
https://arduino-pico.readthedocs.io/en/latest/

and the examples show:

Wire (I2C0), Wire1 (I2C1)
::setSDA(pin)
::setSCL(pin)

Hi,

After strugling I finally discovered, thanks to this post, that SCL0 and SDA0 on Pico are GPIO 5 and 4.
And I made my OLED 128x64 worked with U8g2 library, using Arduino IDE 1.0.

To change i2c0 GPIO, I tried the instructions from https://arduino-pico.readthedocs.io/en/latest/wire.html but with not success. Did some of you succeed to change the default i2c GPIO on Pico ?

Thanks for the info all, I was trying to get i2c working on my wiznet w5100s-EVB-Pico. I finally got my Adafruit 7 segment LED backpack working :slight_smile:

You can set the pins as follows, they must be set befor begin():

Wire1.setSDA(2);
Wire1.setSCL(3);
Wire1.begin();

The following helped me alot:

Default SDA SCL pins, SDA=GP4 (pin 6) SCL=GP5(pin7) (shown in dark blue in this pinout)

And the following i2c sniffer code that searches addresses:

#include <Wire.h> //include Wire.h library

void setup()
{
  Wire.begin(); // Wire communication begin
  Wire.setClock(100000);
  Serial.begin(9600); // The baudrate of Serial monitor is set in 9600
  while (!Serial); // Waiting for Serial Monitor
  Serial.println("\nI2C Scanner");
}

void loop()
{
  byte error, address; //variable for error and I2C address
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for (address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.print(address, HEX);
      Serial.println("  !");
      nDevices++;
    }
    else if (error == 4)
    {
      Serial.print("Unknown error at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
    }
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000); // wait 5 seconds for the next I2C scan
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.