Strange problem with PRO Mini

i have a 433mhz module with arduino pro mini with the following Code :

#define TX 10
#define LED 13
void setup() {
  pinMode(LED, OUTPUT);
  pinMode(TX, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  Serial.begin(9600);
}
void sendPacketStr(char * packet , int len){
  for (int i = 0 ; i < strlen(packet); i++){
    Serial.print(packet[i]);
    if(packet[i] == '1'){
      digitalWrite(TX,HIGH); 
      digitalWrite(LED,HIGH);
    }else {
      digitalWrite(TX,LOW); 
      digitalWrite(LED,LOW);
    }
    delayMicroseconds(len); 
  }
  digitalWrite(TX,LOW);
  Serial.println();
  delay(10.5);
}
void slot2(){
	char * MAIN_DOOR = "100011101110100011101110111010001000111010001110100010001110100010001110100010001000100010001110100";
	int MAIN_DOOR_DELAY = 355;
	sendPacketStr(MAIN_DOOR,MAIN_DOOR_DELAY);
}
void loop() {
 if (digitalRead(2) == LOW){
  Serial.println("2 pressed");
  slot2();
 }
}

i used this code on Arduino PRO Mini and my bit length was 1ms instead 355us but when i've uploaded the same code to the UNO or Leonardo It works normally and my bit length was 355us
also if i comment delayMicroseconds line on Pro MINI it does not effect at all ! and it will 1ms again !

Is it a 5V/16MHz Pro Mini or a 3.3V/8MHz Pro Mini? It's shouldn't make a difference if the right board definition is used but that's all I can think of right now.

You should probably use a much higher baud rate. At 9600 baud it takes about a millisecond to send each character. If you fill the output buffer your loop is going to slow way down. These days I default to 115200 baud. 9600 is so 1980's.

how do you measure timing?

at 9600 bauds you send give or take 960 character per second out - let's call that 1000 --> it means give or take you have 1ms per character

When you do

   Serial.print(packet[i]);

you add one character in the output buffer. it's handled through interruption so you don't need to worry about it UNLESS your Serial.print fills up the 64 bit buffer. At that point the Serial.print will become blocking until a slot is available.

As seen above, that wait period to free up a slot is ~1ms --> that's likely what you see (after the first ~65 bits). I would suggest to remove the print from the for loop.

what do you expect from this delay?

 delay(10.5);

oh i feels like an idiot now with that baudrate ...
thank you
i think i should kill my self

J-M-L:
how do you measure timing?

at 9600 bauds you send give or take 960 character per second out - let's call that 1000 --> it means give or take you have 1ms per character

When you do

   Serial.print(packet[i]);

you add one character in the output buffer. it's handled through interruption so you don't need to worry about it UNLESS your Serial.print fills up the 64 bit buffer. At that point the Serial.print will become blocking until a slot is available.

As seen above, that wait period to free up a slot is ~1ms --> that's likely what you see (after the first ~65 bits). I would suggest to remove the print from the for loop.

what do you expect from this delay?

 delay(10.5);

i've corrected the baudrate and removed the outputs , pro mini works now
but why this code works on the uno and leonardno ? that's weird that same code have different behavior across different boards !

I doubt it work on the UNO... are you sure? did you test with this exact same code?

try this code (typed here but should work)

#define TX 10
#define LED 13
void setup() {
  pinMode(LED, OUTPUT);
  pinMode(TX, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  Serial.begin(9600);
}
void sendPacketStr(const char * packet , int len) {
  for (size_t i = 0 ; i < strlen(packet); i++) {
    Serial.print(packet[i]);
    if (packet[i] == '1') {
      digitalWrite(TX, HIGH);
      digitalWrite(LED, HIGH);
    } else {
      digitalWrite(TX, LOW);
      digitalWrite(LED, LOW);
    }
    delayMicroseconds(len);
  }
  digitalWrite(TX, LOW);
  Serial.println();
  delay(10);
}
void slot2() {
  const char* MAIN_DOOR = "100011101110100011101110111010001000111010001110100010001110100010001110100010001000100010001110100";
  int MAIN_DOOR_DELAY = 355;
  Serial.print("2 pressed, sending string of length:");
  Serial.println(strlen(MAIN_DOOR));
  Serial.flush();
  unsigned long t0 = micros();
  sendPacketStr(MAIN_DOOR, MAIN_DOOR_DELAY);
  t0 = micros() - t0;
  Serial.print("duration:");
  Serial.println(t0);
  Serial.print("duration per bit:");
  Serial.println(t0/strlen(MAIN_DOOR));
}

void loop() {

  if (digitalRead(2) == LOW) {
    slot2();
    delay(1000);
  }
}

and change MAIN_DOOR_DELAY to see the impact on the duration per bit

you should see the same "weird" (but totally logic and expected) behavior on a UNO

J-M-L:
I doubt it work on the UNO... are you sure? did you test with this exact same code?

try this code (typed here but should work)

#define TX 10

#define LED 13
void setup() {
  pinMode(LED, OUTPUT);
  pinMode(TX, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  Serial.begin(9600);
}
void sendPacketStr(const char * packet , int len) {
  for (size_t i = 0 ; i < strlen(packet); i++) {
    Serial.print(packet[i]);
    if (packet[i] == '1') {
      digitalWrite(TX, HIGH);
      digitalWrite(LED, HIGH);
    } else {
      digitalWrite(TX, LOW);
      digitalWrite(LED, LOW);
    }
    delayMicroseconds(len);
  }
  digitalWrite(TX, LOW);
  Serial.println();
  delay(10);
}
void slot2() {
  const char* MAIN_DOOR = "100011101110100011101110111010001000111010001110100010001110100010001110100010001000100010001110100";
  int MAIN_DOOR_DELAY = 355;
  Serial.print("2 pressed, sending string of length:");
  Serial.println(strlen(MAIN_DOOR));
  Serial.flush();
  unsigned long t0 = micros();
  sendPacketStr(MAIN_DOOR, MAIN_DOOR_DELAY);
  t0 = micros() - t0;
  Serial.print("duration:");
  Serial.println(t0);
  Serial.print("duration per bit:");
  Serial.println(t0/strlen(MAIN_DOOR));
}

void loop() {

if (digitalRead(2) == LOW) {
    slot2();
    delay(1000);
  }
}


and change MAIN_DOOR_DELAY to see the impact on the duration per bit

you should see the same "weird" (but totally logic and expected) behavior on a UNO

thanks ,i've got it !