Receiving: "error while setting serial port parameters: 74,880 n 8 1" when connected to Raspberry Pi USB

I am using an Arduino Nano connected to a Raspberry Pi to run a stepper motor driver and a couple of relays through serial monitor input. The sketch sets the baud rate to 9600 in void setup(), and the system has worked fine for months. Recently, the serial monitor input began acting erratically, as if a keyboard key were stuck, as well as the actually mechanical outputs acting as if there were recieving random signals. On compiling/loading the sketch, I now get the following error:

error while setting serial port parameters: 74,880 n 8 1

I'm not sure why it is picking the 74,880 baud rate. I have connected the Nano to a PC, and it communicates fine and the system works as it should. I feel like the error is on the RPi side, but I'm not sure what has changed or how to reset it.

Your post was MOVED to its current location as it is more suitable.

Please post the sketch that exhibits this problem, using code tags when you post it

Here is the code, but as I stated, the sketch works fine when connected to a PC but not the RPi.

Also, this is an
board: Arduino Nano
processor: ATmega328P (Old Bootloader)
port: /dev/ttyUSB0"

/*
NEMA_23_BALL_SCREW_RHS_ROOF_FLAP_MATRIX_W_30A_FAN_AND_FLAPPER_FINAL

NEMA 23 RHS ROOF FLAP MATRIX USES ARDUINO NANO
STEPPERONLINE DM542T MOTOR CONTROLLERS SET TO PULSE/REV = 3200
USES 5VDC LIMIT SWITCH FOR HOMING [PIN 2]
PREASSEMBLED BALL SCREW SYSTEM
DAMPER ON FIRIGELLI INTERNAL ACTUATOR - RELAY [PINS 8, 10]
40A SOLID STATE RELAY FOR 30A CABIN RHS NACA FAN [5VDC SIGNAL INPUT] = NORMALLY CLOSED [PIN 12]
  
 
  -JOHN ARMBRUSTER for ROUSHFENWAY RACING, LLC 8/9/21
*/

#include <AccelStepper.h>
#include <MultiStepper.h>

// Define connections
#define LIMIT_SWITCH_FLAP  2  // RHS FLAP HOMING SWITCH
#define RHS_NACA_FAN_RELAY  12  // RHS NACA 30A FAN RELAY SWITCH
#define DAMPER_RELAY_1  8 // DAMPER RELAY 1
#define DAMPER_RELAY_2  10 // DAMPER RELAY 2

AccelStepper stepperFLAP(AccelStepper(1,4,6)); // PULSE/REV = 3200 on DM542T driver - pin 4 STEP, pin 6 DIR:


// Up to 10 steppers can be handled as a group by MultiStepper steppers;
MultiStepper steppers;

// Stepper Travel Variables:
  int FLAP = 0; // Travel steps of FLAP stepper

// Temporary values of stepper postition
  int newFLAP = 0; // Travel steps of FLAP stepper

// FLAP STEP VARIABLES - DM542T CONTROLLER SET AT 3200 PULSE/REV: SET VARIABLES: 

  int ONE = 2985; // FLAP .787 INCHES
  int TWO = 2879; // FLAP .759 INCHES
  int THREE = 2819; // FLAP .743 INCHES
  int FOUR = 2815; // FLAP .742 INCHES
  int SET1 = 765; // FLAP .200 INCHES
  int SET2 = 1521; // FLAP .400 INCHES
  int SET3 = 2276; // FLAP .600 INCHES
  int SET4 = 3032; // FLAP .800 INCHES
  int SET5 = 383; // FLAP .100 INCHES
  int SET6 = 1149; // FLAP .300 INCHES
  int SET7 = 1915; // FLAP .500 INCHES
  int SET8 = 2681; // FLAP .700 INCHES
  int SET9 = 3447; // FLAP .900 INCHES
  int SET10 = 3830; // FLAP 1.000 INCHES

/* ALTERNATE FLAP STEP VARIABLES - DM542T CONTROLLER SET AT 3200 PULSE/REV: SET VARIABLES: 

  int ONE = 2985; // FLAP .787 INCHES
  int TWO = 2879; // FLAP .759 INCHES
  int THREE = 2819; // FLAP .743 INCHES
  int FOUR = 2815; // FLAP .742 INCHES
  int SET1 = 765; // FLAP .200 INCHES
  int SET2 = 1521; // FLAP .400 INCHES
  int SET3 = 2276; // FLAP .600 INCHES
  int SET4 = 3032; // FLAP .800 INCHES
  int SET5 = 383; // FLAP .100 INCHES
  int SET6 = 1149; // FLAP .300 INCHES
  int SET7 = 1915; // FLAP .500 INCHES
  int SET8 = 2681; // FLAP .700 INCHES
  int SET9 = 3447; // FLAP .900 INCHES
  int SET10 = 3830; // FLAP 1.000 INCHES */
  
// HOMING STEP VARIABLES INITIALIZED
  long initial_homingFLAP = 1;  // Used to Home FLAP Stepper at startup

  int height; // variable to define flap height position string

const char *RHSFLAP[] = {"0: FLAP POSITION CLOSED", "1: FLAP POSITION .787 INCHES", "2: FLAP POSITION .759 INCHES", "5: FLAP POSITION .743 INCHES ", "7: FLAP POSITION .742 INCHES ", "a: FLAP POSITION CLOSED ", "b: FLAP POSITION CLOSED ", "c: FLAP POSITION .200 INCHES ", "d: FLAP POSITION .400 INCHES ", "e: FLAP POSITION .600 INCHES ", "f: FLAP POSITION .800 INCHES ", "g: FLAP POSITION .100 INCHES ", "h: FLAP POSITION .200 INCHES ", "i: FLAP POSITION .300 INCHES ", "j: FLAP POSITION .400 INCHES ", "k: FLAP POSITION .500 INCHES ", "l: FLAP POSITION .600 INCHES ", "m: FLAP POSITION .700 INCHES ", "n: FLAP POSITION .800 INCHES ", "o: FLAP POSITION .900 INCHES ", "p: FLAP POSITION 1.000 INCHES ", "q: FLAP POSITION .100 INCHES ", "r: FLAP POSITION .200 INCHES ", "s: FLAP POSITION .300 INCHES ", "t: FLAP POSITION .400 INCHES ", "u: FLAP POSITION .500 INCHES "}; // strings to define FLAP, FAN, DAMPER CONDITION position
   
void setup() {

 // Setup the LIMIT SWITCHES as an Input:
  pinMode(LIMIT_SWITCH_FLAP, INPUT_PULLUP);
  
 // Setup ENABLE pins as Output
  pinMode(RHS_NACA_FAN_RELAY, OUTPUT); // FAN RELAY HIGH TRIGGER
  pinMode(DAMPER_RELAY_1, OUTPUT); // RELAY 1 HIGH TRIGGER
  pinMode(DAMPER_RELAY_2, OUTPUT); // RELAY 2 HIGH TRIGGER

 // Set RELAY pin to LOW (OFF)
  digitalWrite(RHS_NACA_FAN_RELAY, LOW); // OFF
  digitalWrite(DAMPER_RELAY_1, LOW); // OFF
  digitalWrite(DAMPER_RELAY_2, LOW); // OFF
  
 // Configure each stepper: 
  stepperFLAP.setMaxSpeed(5000);    

 // Then give them to MultiStepper to manage:
  steppers.addStepper(stepperFLAP);

// initialize serial communication:
  Serial.begin(9600);
                                  
  HOMING();
}

void loop() {
  // read SERIAL MONITOR:
  
  if (Serial.available() > 0)  {
    
    int inByteFLAP = Serial.read(); //Matrix 1 FLAP
           
  // Array of desired stepper positions
         long positions[20]; 
 
  // MATRIX CASES
    switch (inByteFLAP) {
       case '0':
         FLAP = 0;
         OPENDAMPER();
         FANOFF();
         height = 0;
        break;
      case '1':
         FLAP = ONE;
         CLOSEDDAMPER();
         FANON();
         height = 1;
        break;
      case '2':
         FLAP = TWO;
         CLOSEDDAMPER();
         FANON();
         height = 2;
        break;
      case '5':
         FLAP = THREE;
         CLOSEDDAMPER();
         FANON();
         height = 3;
        break;
      case '7':
         FLAP = FOUR;
         CLOSEDDAMPER();
         FANON();
         height = 4;
        break;
      case 'a': // WARM UP
         FLAP = 0;
         CLOSEDDAMPER();
         FANON();
         height = 5;
        break;
      case 'b':
         FLAP = 0;
         CLOSEDDAMPER();
         FANOFF();
         height = 6;
        break;
      case 'c':
         FLAP = SET1 ;
         CLOSEDDAMPER();
         FANOFF();
         height = 7;
        break;
      case 'd':
         FLAP = SET2;
         CLOSEDDAMPER();
         FANOFF();
         height = 8;
        break;
      case 'e':
         FLAP = SET3;
         CLOSEDDAMPER();
         FANOFF();
         height = 9;
        break;
      case 'f':
         FLAP = SET4;
         CLOSEDDAMPER();
         FANOFF();
         height = 10;
        break;
      case 'g':
         FLAP = SET5;
         CLOSEDDAMPER();
         FANON();
         height = 11;
        break;
      case 'h':
         FLAP = SET1;
         CLOSEDDAMPER();
         FANON();
         height = 12;
        break;
      case 'i':
         FLAP = SET6;
         CLOSEDDAMPER();
         FANON();
         height = 13;
        break;
      case 'j':
         FLAP = SET2;
         CLOSEDDAMPER();
         FANON();
         height = 14;
        break;
      case 'k':
         FLAP = SET7;
         CLOSEDDAMPER();
         FANON();
         height = 15;
        break;
      case 'l':
         FLAP = SET3;
         CLOSEDDAMPER();
         FANON();
         height = 16;
        break;
      case 'm':
         FLAP = SET8;
         CLOSEDDAMPER();
         FANON();
         height = 17;
        break;
      case 'n':
         FLAP = SET4;
         CLOSEDDAMPER();
         FANON();
         height = 18;
        break;
       case 'o':
         FLAP = SET9;
         CLOSEDDAMPER();
         FANON();
         height = 19;
        break;
      case 'p':
         FLAP = SET10;
         CLOSEDDAMPER();
         FANON();
         height = 20;
        break;
      case 'q':
         FLAP = SET5;
         OPENDAMPER();
         FANOFF();
         height = 21;
        break;
      case 'r':
         FLAP = SET1;
         OPENDAMPER();
         FANOFF();
         height = 22;
        break;
      case 's':
         FLAP = SET6;
         OPENDAMPER();
         FANOFF();
         height = 23;
        break;
      case 't':
         FLAP = SET2;
         OPENDAMPER();
         FANOFF();
         height = 24;
        break;
      case 'u':
         FLAP = SET7;
         OPENDAMPER();
         FANOFF();
         height = 25;
        break;
      default:
        
   
   // set positions to move to in steps
         positions[0] = FLAP;

   //execute move
         steppers.moveTo(positions);
         steppers.runSpeedToPosition();
       // print arrival
         //Serial.println(" ");
         Serial.print("RHS FLAP ARRIVED AT: ");
         Serial.print(RHSFLAP[height]);
         Serial.println(" ");
         Serial.println(" ");
    } 
   }
}
 
void HOMING() { //Start Homing procedure of Stepper Motor at startup:

   Serial.println("STEPPERS ARE HOMING_____________________________________"); 
 
// Home RHS FLAP stepper:

stepperFLAP.setMaxSpeed(10000); // Set Max Speed of Stepper (Slower to get better accuracy);

  while (digitalRead(LIMIT_SWITCH_FLAP)) {  // Make the FLAP Stepper move CCW until the switch is activated   
    Serial.println(digitalRead(LIMIT_SWITCH_FLAP));
    stepperFLAP.moveTo(initial_homingFLAP);  // Set the position to move to
    Serial.println(initial_homingFLAP);
    stepperFLAP.run();  // Start moving the stepper
    initial_homingFLAP++;  // Increase by 1 for next move if needed
    }

  stepperFLAP.setCurrentPosition(0);  // Set the current position as zero for now
  initial_homingFLAP = -1;

  while (!digitalRead(LIMIT_SWITCH_FLAP)) { // Make the FLAP Stepper move CW until the switch is deactivated
    Serial.println(digitalRead(LIMIT_SWITCH_FLAP));
    stepperFLAP.moveTo(initial_homingFLAP);  // Set the position to move to
    Serial.println(initial_homingFLAP);  
    stepperFLAP.run();
    initial_homingFLAP--;  
    }
  
  stepperFLAP.setCurrentPosition(0);
  Serial.println();
  
  Serial.println("Homing RHS FLAP Completed");
  
  Serial.println();
  
  stepperFLAP.setMaxSpeed(5000);      // Set Max Speed of FLAP Stepper

Serial.println("___________________________________________________HOMED");
}

void OPENDAMPER() { // OPEN DAMPER
        digitalWrite(DAMPER_RELAY_1, HIGH);
        digitalWrite(DAMPER_RELAY_2, LOW);
        Serial.println(" ");
        Serial.println("DAMPER OPEN");
}
void CLOSEDDAMPER() { // CLOSED DAMPER
        digitalWrite(DAMPER_RELAY_1, LOW);
        digitalWrite(DAMPER_RELAY_2, HIGH);
        Serial.println(" ");
        Serial.println("DAMPER CLOSED");
}
void FANOFF() { // FAN OFF
        digitalWrite(RHS_NACA_FAN_RELAY, LOW); 
        Serial.println("FAN OFF");
}
void FANON() { // FAN ON
        digitalWrite(RHS_NACA_FAN_RELAY, HIGH); 
        Serial.println("FAN ON");
}

Well, did you try a RPi serial loop back test to see if your RPI is doing the correct thing?

And those logic level converters how are they doing? Perhaps one of the logic level converters has went bad.

What does that mean?

Show an image of how your are connecting the Nano to a RPi.

The Mini-B USB port on the Nano is connected directly to one of the 3.0 USB ports on the RPi via a 6" cable.

Is the Pi creating a virtual COM port on the USB port that you are connecting to, as a PC with the correct driver installed does ?

I'm not sure how to check this. The listed ports are /dev/ttyAMA0 and /dev/ttyUSB0.

I have plugged a Mega 2560 in as well, the ports listed are /dev/ttyACM0 (Arduino Mega or Mega2560) and /dev/ttyACM0. It chooses the former, and has the same error. It will compile and load the program, but as soon as there is a serial input, the serial output scrolls as if a key is stuck.

What exactly chooses the COM port ?

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