also worth looking at is esp32-spi-communication-arduino which prints the default SPI pins
I extended it to also print the I2C pins
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-spi-communication-arduino/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
//Find the default SPI pins for your board
//Make sure you have the right board selected in Tools > Boards
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(3000);
Serial.print("MOSI: ");
Serial.println(MOSI);
Serial.print("MISO: ");
Serial.println(MISO);
Serial.print("SCK: ");
Serial.println(SCK);
Serial.print("SS: ");
Serial.println(SS);
Serial.print("SDA: ");
Serial.println(SDA);
Serial.print("SCL: ");
Serial.println(SCL);
}
void loop() {
// put your main code here, to run repeatedly:
}
on a RPi Pico displays
SDA 4
SCL 5
MOSI: 19
MISO: 16
SCK: 18
SS: 17
the program can be extended to print further information, e.g. on a ATtiny85
Some boards have more than one Wire (I2C) interface.
Is it possible to extract the actual SDA and SCL from the TwoWire object?
Something like int mySDA = getSDA(Wire1); etc?
never heard of such a thing
with a new micro I generally run the code of post 2 to print the SPI and I2C pins but also look at pinouts, e.g. the ESP32 I2C, DAC, VSPI and HSPI pins etc
here is an example of setting I2C pins I used on an ESP-CAM wirh a BMP280
/* Interfacing ESP32-CAM with BMP280 temperature and pressure sensor.
* Temperature and pressure values are displayed on 16x2 LCD.
* This is a free software with NO WARRANTY.
* https://simple-circuit.com/
*/
#include <Wire.h> // include Wire library, required for I2C devices
#include <Adafruit_Sensor.h> // include Adafruit sensor library
#include <Adafruit_BMP280.h> // include adafruit library for BMP280 sensor
// define I2C pins
#define I2C_SDA 16
#define I2C_SCL 0
// define device I2C address: 0x76 or 0x77 (0x77 is library default address)
#define BMP280_I2C_ADDRESS 0x76
Adafruit_BMP280 bmp280;
void setup() {
Serial.begin(115200);
Serial.println(F("ESP32-CAM + BMP280"));
Wire.begin(I2C_SDA, I2C_SCL); // <<<<<<<< set I2C pins
if (!bmp280.begin(BMP280_I2C_ADDRESS)) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1)
;
}
Serial.println("Found BMP280 sensor!");
}
void loop() {
// get temperature, pressure and altitude from library
float temperature = bmp280.readTemperature(); // get temperature
float pressure = bmp280.readPressure(); // get pressure
float altitude_ = bmp280.readAltitude(1013.25); // get altitude (this should be adjusted to your local forecast)
// print data on the serial monitor software
// 1: print temperature
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" °C");
// 2: print pressure
Serial.print("Pressure = ");
Serial.print(pressure / 100);
Serial.println(" hPa");
// 3: print altitude
Serial.print("Approx Altitude = ");
Serial.print(altitude_);
Serial.println(" m");
Serial.println(); // start a new line
delay(2000); // wait 2 seconds
}
serial monitor output
ESP32-CAM + BMP280
Found BMP280 sensor!
Temperature = 20.81 °C
Pressure = 1006.52 hPa
Approx Altitude = 56.21 m
Temperature = 20.84 °C
Pressure = 1006.48 hPa
Approx Altitude = 56.55 m
Temperature = 21.91 °C
Pressure = 1006.36 hPa
Approx Altitude = 57.55 m
Temperature = 21.87 °C
Pressure = 1006.37 hPa
Approx Altitude = 57.40 m
Temperature = 23.89 °C
Pressure = 1007.74 hPa
Approx Altitude = 43.99 m
Temperature = 24.87 °C
Pressure = 1006.06 hPa
Approx Altitude = 60.36 m
Temperature = 24.68 °C
Pressure = 1006.02 hPa
Approx Altitude = 60.74 m