Port monitor error: command open failed serial port busy

Hello!! I am trying to use Raspberry Pi pico in Arduino using the platform Raspberry Pi Pico/ RP2040. For some codes, it is working well, like a simple blink code, where I print On when led is ON and OFF when LED is off. The message appear in monitor serial and my code run very well in Pi Pico. But in other codes, I have some issues. The monitor serial appear the message "Connecting to Raspberry Pi Pico in COM..." and after that "port monitor error command 'open' failed serial port busy. could not connect to com serial port". I've been searching for many solutions but I can't get sucess. I can run the code to Pi Pico, the only thing is not working is the monitor serial. I ran a code there and tested in Teraterm, but it can identify the port as well. I am using Windows 11 and Arduino version is 2.3.2.

Thanks for any solution!!

I'll leave the code I am trying run:

#include <Wire.h>
#include <INA226_WE.h>
#define I2C_ADDRESS 0x40

INA226_WE ina226 = INA226_WE(I2C_ADDRESS);

#define SDA_PIN 2  // Exemplo: GP2 como SDA
#define SCL_PIN 3  // Exemplo: GP3 como SCL

void setup() {
  while (!Serial)
    ;  // wait until serial comes up on Arduino Leonardo or MKR WiFi 1010
  Wire.setSDA(SDA_PIN);
  Wire.setSCL(SCL_PIN);
  Wire.begin();
  ina226.init();

  /* Set Number of measurements for shunt and bus voltage which shall be averaged
    Mode *     * Number of samples
    AVERAGE_1            1 (default)
    AVERAGE_4            4
    AVERAGE_16          16
    AVERAGE_64          64
    AVERAGE_128        128
    AVERAGE_256        256
    AVERAGE_512        512
    AVERAGE_1024      1024*/

  //ina226.setAverage(AVERAGE_16); // choose mode and uncomment for change of default

  /* Set conversion time in microseconds
     One set of shunt and bus voltage conversion will take:
     number of samples to be averaged x conversion time x 2
 
       Mode *         * conversion time
     CONV_TIME_140          140 µs
     CONV_TIME_204          204 µs
     CONV_TIME_332          332 µs
     CONV_TIME_588          588 µs
     CONV_TIME_1100         1.1 ms (default)
     CONV_TIME_2116       2.116 ms
     CONV_TIME_4156       4.156 ms
     CONV_TIME_8244       8.244 ms  */

  //ina226.setConversionTime(CONV_TIME_1100); //choose conversion time and uncomment for change of default

  /* Set measure mode
    POWER_DOWN - INA226 switched off
    TRIGGERED  - measurement on demand
    CONTINUOUS  - continuous measurements (default)*/

  //ina226.setMeasureMode(CONTINUOUS); // choose mode and uncomment for change of default

  /* Set Resistor and Current Range
     if resistor is 5.0 mOhm, current range is up to 10.0 A
     default is 100 mOhm and about 1.3 A*/

  ina226.setResistorRange(0.1, 1.3);  // choose resistor 0.1 Ohm and gain range up to 1.3A

  /* If the current values delivered by the INA226 differ by a constant factor
     from values obtained with calibrated equipment you can define a correction factor.
     Correction factor = current delivered from calibrated equipment / current delivered by INA226*/

  ina226.setCorrectionFactor(0.93);

  Serial.println("INA226 Current Sensor Example Sketch - Continuous");

  ina226.waitUntilConversionCompleted();  //if you comment this line the first data might be zero
}

void loop() {
  float shuntVoltage_mV = 0.0;
  float loadVoltage_V = 0.0;
  float busVoltage_V = 0.0;
  float current_mA = 0.0;
  float power_mW = 0.0;

  ina226.readAndClearFlags();
  shuntVoltage_mV = ina226.getShuntVoltage_mV();
  busVoltage_V = ina226.getBusVoltage_V();
  current_mA = ina226.getCurrent_mA();
  power_mW = ina226.getBusPower();
  loadVoltage_V = busVoltage_V + (shuntVoltage_mV / 1000);

  Serial.print("Shunt Voltage [mV]: ");
  Serial.println(shuntVoltage_mV);
  Serial.print("Bus Voltage [V]: ");
  Serial.println(busVoltage_V);
  Serial.print("Load Voltage [V]: ");
  Serial.println(loadVoltage_V);
  Serial.print("Current[mA]: ");
  Serial.println(current_mA);
  Serial.print("Bus Power [mW]: ");
  Serial.println(power_mW);
  if (!ina226.overflow) {
    Serial.println("Values OK - no overflow");
  } else {
    Serial.println("Overflow! Choose higher current range");
  }
  Serial.println();

  delay(3000);
}

Edson

Hello y'all! i found out something. Apparently when I use I2C0 in Raspberry Pi Pico, like 0 and 1, or 4 and 5 (default), it works well. But When I use I2C1, like 2 and 3, it has some problem with the port COM. Do you guys know what this can be? Cause I ran this code before and it works with I2C1 as well, and now it is not running anymore. Thankss for any help!

Edson

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