Need help with RS232

Hi,
i'm kinda new to arduino, have made some little project but never something this big.
I try to make a RS232 remote for an AV device that don't have any TCP control.
I have the hex code i have to send to the av device in a pdf file + find out how to calculate the checksum and eveything, i think my code is okay on this point.

I use an arduino UNO + a mux CD74HC4067 for my 15 boutons (that works well) + a SSD1306 oled display + a TTL to RS232 to output my hex code writen into the serial (classic port 0 and 1) (link : https://www.amazon.fr/dp/B09DYDFZRW?psc=1&ref=ppx_yo2ov_dt_b_product_details)

My code :


#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

// 'Sans titre-1', 128x64px
const unsigned char sony [] PROGMEM = {
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0xff, 0xf0, 0xe0, 0x00, 0xff, 0xf8, 0x01, 0xff, 0x00, 0x7f, 0xf1, 0xff, 0xe0, 0x7f, 0xe0, 
	0x03, 0xff, 0xfd, 0xe0, 0x07, 0xff, 0xff, 0x03, 0xff, 0x80, 0x7f, 0xf9, 0xff, 0xf0, 0x7f, 0xe0, 
	0x07, 0xf0, 0x7f, 0xe0, 0x0f, 0xf0, 0x3f, 0x83, 0xff, 0xe0, 0x7f, 0xf1, 0xff, 0xf0, 0x7f, 0xe0, 
	0x0f, 0x80, 0x0f, 0xe0, 0x3f, 0x80, 0x0f, 0xe0, 0x3f, 0xf0, 0x07, 0x80, 0x3f, 0x80, 0x1f, 0x00, 
	0x1f, 0x00, 0x03, 0xe0, 0x7f, 0x00, 0x07, 0xe0, 0x3f, 0xf8, 0x07, 0x80, 0x1f, 0xc0, 0x3e, 0x00, 
	0x1f, 0x80, 0x01, 0xe0, 0x7e, 0x00, 0x07, 0xf0, 0x3f, 0xfc, 0x07, 0x80, 0x0f, 0xe0, 0x7c, 0x00, 
	0x1f, 0xc0, 0x00, 0xe0, 0xfe, 0x00, 0x03, 0xf8, 0x3f, 0xfe, 0x07, 0x80, 0x07, 0xf0, 0xf8, 0x00, 
	0x1f, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x03, 0xf8, 0x3d, 0xff, 0x07, 0x80, 0x03, 0xf9, 0xf0, 0x00, 
	0x0f, 0xff, 0xfc, 0x00, 0xfc, 0x00, 0x03, 0xf8, 0x3c, 0xff, 0x87, 0x80, 0x01, 0xff, 0xe0, 0x00, 
	0x0f, 0xff, 0xff, 0x80, 0xfc, 0x00, 0x03, 0xf8, 0x3c, 0x7f, 0xc7, 0x80, 0x01, 0xff, 0xc0, 0x00, 
	0x03, 0xff, 0xff, 0xc0, 0xfc, 0x00, 0x03, 0xf8, 0x3c, 0x3f, 0xe7, 0x80, 0x00, 0xff, 0x80, 0x00, 
	0x00, 0x7f, 0xff, 0xe0, 0xfc, 0x00, 0x03, 0xf8, 0x3c, 0x1f, 0xf7, 0x80, 0x00, 0x7f, 0x80, 0x00, 
	0x00, 0x01, 0xff, 0xf0, 0xfe, 0x00, 0x03, 0xf8, 0x3c, 0x0f, 0xff, 0x80, 0x00, 0x3f, 0x00, 0x00, 
	0x1c, 0x00, 0x0f, 0xf0, 0xfe, 0x00, 0x03, 0xf8, 0x3c, 0x03, 0xff, 0x80, 0x00, 0x3f, 0x00, 0x00, 
	0x1e, 0x00, 0x03, 0xf0, 0x7f, 0x00, 0x07, 0xf0, 0x3c, 0x01, 0xff, 0x80, 0x00, 0x3f, 0x00, 0x00, 
	0x1f, 0x00, 0x03, 0xf0, 0x7f, 0x00, 0x07, 0xe0, 0x3c, 0x00, 0xff, 0x80, 0x00, 0x3f, 0x00, 0x00, 
	0x1f, 0xc0, 0x03, 0xe0, 0x3f, 0x80, 0x1f, 0xe0, 0x3c, 0x00, 0x7f, 0x80, 0x00, 0x3f, 0x00, 0x00, 
	0x1f, 0xf8, 0x0f, 0xe0, 0x0f, 0xf0, 0x7f, 0x80, 0x7e, 0x00, 0x3f, 0x80, 0x03, 0xff, 0xc0, 0x00, 
	0x1f, 0xff, 0xff, 0x80, 0x07, 0xff, 0xff, 0x03, 0xff, 0xc0, 0x1f, 0x80, 0x03, 0xff, 0xf0, 0x00, 
	0x1c, 0x3f, 0xff, 0x00, 0x00, 0xff, 0xf8, 0x03, 0xff, 0xc0, 0x0f, 0x80, 0x03, 0xff, 0xf0, 0x00, 
	0x00, 0x01, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = 1040)
const int sonyallArray_LEN = 1;
const unsigned char* sonyallArray[1] = {
	sony
};



int freeRAM() {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

// BANQUE DE DONNEES HEXA
const byte xpt[14] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e};
const byte outs[3] = {0x00,0x02,0x03};

// Définition des broches
const int s0 = 2; // Broche S0
const int s1 = 3; // Broche S1
const int s2 = 4; // Broche S2
const int s3 = 5; // Broche S3
const int en = 6; // Broche d'activation (E) du multiplexeur

const int storeled = 8;
const int mux = 7;

bool boutons[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
bool pause = false;

// CHECKSUM 
byte calculateChecksum(byte *data, int length) {
  byte checksum = 0;
  for (int i = 0; i < length; i++) {
    checksum += data[i];
  }
  return ~checksum + 1; // Two's complement
}

// PAUSE
unsigned long derniereActivation = 0; 
const unsigned long delaiMax = 20000; 

// Stockage Variables
byte lastButtonState[12] = {0,0,0,0,0,0,0,0,0,0,0,0};
byte lastStoreState[1] = {0};
byte variable = 1;                                                                                    //  Variable maitresse, sert de fil rouge pour les fonctions inc/dec
byte variableOut = 1;                                                                                 //  Variable pour la valeur d'out sur la memoire
byte variableIn = 1;                                                                                  //  Variable pour la valeur d'in sur la memoire
byte memory[2][12] = {{0,1,2,3,4,5,6,7,8,9,10,11},                                                    //  Memoires d'inputs
                      {0,0,0,0,0,0,0,0,0,0,0 ,0 }};                                                   //  Memoires d'outputs // Données sur un ARRAY 3D // Configurées de base en 12 inputs sur la M/E 1 bus PGM      

void setup() {

  Serial.begin(38400);                                                                             
  Wire.begin();
  Serial.println(freeRAM());

  // Initialisation de l'écran OLED
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("Echec de l'initialisation de l'affichage OLED"));
    for(;;);
    }

  pinMode(mux,INPUT_PULLUP);
  pinMode(s0, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(en, OUTPUT);
  pinMode(storeled,OUTPUT);

  digitalWrite(en, LOW);
  bootscreen();
  delay(3000);
}      

void triggers(){
  for (byte i = 0; i < 16; i++) {
    digitalWrite(s0, i & 0x1);
    digitalWrite(s1, (i >> 1) & 0x1);
    digitalWrite(s2, (i >> 2) & 0x1);
    digitalWrite(s3, (i >> 3) & 0x1);

    boutons[i]= !digitalRead(mux); 
  }
}

void bootscreen(){
  display.clearDisplay();
  display.drawBitmap(
    (display.width()  - 128 ) / 2,      // Position de l'extrême "gauche" de l'image (pour centrage écran, ici)
    (display.height() - 64) / 2,       // Position de l'extrême "haute" de l'image (pour centrage écran, ici)
    sony, 128, 64, WHITE);    // "couleur" de l'image
  display.display();  
}

void updateDisplay1() {

    display.clearDisplay();

    // INTRO
    display.setTextSize(1);      
    display.setTextColor(SSD1306_WHITE); 
    display.setCursor(0,0);     
    display.println("Sony MCS-8");
    display.println("RS232 Remote V1.0");

    display.drawLine(0, 16, SCREEN_WIDTH, 16, SSD1306_WHITE);

    // INPUT / OUTPUT to STORE
    display.setTextSize(1);      
    display.setTextColor(SSD1306_WHITE); 
    display.setCursor(0,20);     
    display.print("Input : ");
    display.println(variableIn);

    display.setTextSize(1);      
    display.setTextColor(SSD1306_WHITE); 
    display.setCursor(12,28);     
    display.print("Bus : ");
      if (variableOut == 1) {
        display.println("PGM");
      } else if (variableOut == 2) {
        display.println("Aux 1");
      } else if (variableOut == 3) {
        display.println("Aux 2");
      }

    // STORED
    for (byte index = 0; index < 12; index++) {
      if (boutons[index] == 1 && boutons[13] == 1){
      display.setTextSize(1);      
      display.setTextColor(SSD1306_WHITE); 
      display.setCursor(84,20);     
      display.println("STORED");
      }
    }

    // RECAP MEMOIRES 1 - INPUT
    for (byte index = 0; index < 6; index++) {
      display.setTextSize(1);      
      display.setTextColor(SSD1306_WHITE); 
      display.setCursor((21*index +3),43);     
      display.print((memory[0][index]+1));
      display.setTextSize(1);      
      display.setTextColor(SSD1306_WHITE); 
      display.setCursor((21*index +3),54);     
      display.print((memory[0][index+6]+1));
    
    // RECAP MEMOIRES 2 - BUS représentés par 0, 1 ou 2 points
      if ((memory[1][index]) == 1){
        display.setTextSize(2);      
        display.setTextColor(SSD1306_WHITE); 
        display.setCursor((21*index +11),36);     
        display.print(".");
      }
      if ((memory[1][index+6]) == 1){
        display.setTextSize(2);      
        display.setTextColor(SSD1306_WHITE); 
        display.setCursor((21*index +11),47);     
        display.print(".");
      }
      if ((memory[1][index]) == 2){
        display.setTextSize(2);      
        display.setTextColor(SSD1306_WHITE); 
        display.setCursor((21*index +11),39);     
        display.print(":");
      }
      if ((memory[1][index+6]) == 2){
        display.setTextSize(2);      
        display.setTextColor(SSD1306_WHITE); 
        display.setCursor((21*index +11),49);     
        display.print(":");
    }
  }
    // RECAP MEMOIRES 3 - TABLEUR
    display.drawLine(0, 40, SCREEN_WIDTH, 40, SSD1306_WHITE);
    display.drawLine(0, 51, SCREEN_WIDTH, 51, SSD1306_WHITE);
    display.drawLine(0, 63, SCREEN_WIDTH, 63, SSD1306_WHITE);

    display.drawLine(0, 40, 0, 64, SSD1306_WHITE);
    display.drawLine(21, 40, 21, 64, SSD1306_WHITE);
    display.drawLine(42, 40, 42, 64, SSD1306_WHITE);
    display.drawLine(63, 40, 63, 64, SSD1306_WHITE);
    display.drawLine(84, 40, 84, 64, SSD1306_WHITE);
    display.drawLine(105, 40, 105, 64, SSD1306_WHITE);
    display.drawLine(127, 40, 127, 64, SSD1306_WHITE);
  
  display.display();
}

void compteur() {
  // FONCTIONS POUR INC/DEC les 2 variables In/Out + une variable maitresse
  if (boutons[14] == 1 && boutons[13] == 0 ) {
      variable++;
      variableIn++;
      Serial.print("INC++ - IN : ");
      Serial.print(variableIn);
      Serial.print(" OUT :");
      Serial.println(variableOut);
      Serial.println("");
      delay(200); // Délai anti-rebond
    }

  if (boutons[15] == 1 && boutons[13] == 0) {
      variable--;
      variableIn--;      
      Serial.print("DEC-- - IN : ");
      Serial.print(variableIn);
      Serial.print(" OUT :");
      Serial.println(variableOut);
      Serial.println("");
      delay(200); // Délai anti-rebond
    }

  // FONCTIONS POUR BLOQUER LES VARIABLES EN INC/DEC              
  if (variable < 1) {
    variable = 42;
    variableIn = 14;
    variableOut = 3;
    }
  if (variable == 14) {
    variableIn = 14;
    variableOut = 1;
    }
  if (variable == 15) {
    variableIn = 1;
    variableOut = 2;
    }
  if (variable == 28) {
    variableIn = 14;
    variableOut = 2;
    }    
  if (variable == 29) {
    variableIn = 1;
    variableOut = 3;
    }
  if (variable > 42) {
    variable = 1;
    variableIn = 1;
    variableOut = 1;
    }
}

void store(){
  // LED BOUTON STORE
    if (boutons[13] == 1){
      digitalWrite(storeled, HIGH);
    }
    if (boutons[13] == 0){
      digitalWrite(storeled, LOW);
    }

  // FONCTION STORE DANS LA MEMORY SELON LES VALEURS DE VARIABLES
  for (byte index = 0; index < 12; index++) {
    if (boutons[index] == 1 && boutons[13] == 1) {
      memory[1][index] = variableOut - 1;
      memory[0][index] = variableIn - 1;
      delay(200); // Délai anti-rebond
      digitalWrite(storeled, LOW);
      delay(100);
      digitalWrite(storeled, HIGH);
      delay(100);
      digitalWrite(storeled, LOW);
      delay(100);
      digitalWrite(storeled, HIGH);
      delay(100);
      digitalWrite(storeled, LOW);
      delay(100);
      digitalWrite(storeled, HIGH);
      delay(100);
      digitalWrite(storeled, LOW);
      delay(100);
    }
  }  

}

void rscommand(){
  // FONCTION POUR TRIGGER DE 1 A 12 SELON MEMORY sur les 2 dimensions INPUTS/OUTPUTS

  for (byte index = 0; index < 12; index++)
  {
    
    byte currentTriggerState = boutons[index];
    if (currentTriggerState != lastButtonState[index])
    {
      lastButtonState[index] = currentTriggerState;
      if (currentTriggerState == HIGH && boutons[13] == 0){
        {
        byte data[] = {0x80,0x80,outs[memory[1][index]],xpt[memory[0][index]]};
        byte csm = calculateChecksum(data, sizeof(data));
        byte outh = outs[memory[1][index]];
        byte xpth = xpt[memory[0][index]];

        while (!Serial.availableForWrite());           
        Serial.println("CMD Hexa : ");
        delay(200);
        for (int t = 0; t < 17; t++)                               // ENVOI TX
          {
          byte cmd[17] = {0x01,0x02,0x00,0x0b,0x01,0x50,0x20,0x00,0x00,0x04,outh,0x00,0x80,0x00,xpth,csm,0x03};
          Serial.write (cmd, sizeof(cmd));        
          }
        delay(600);
        Serial.println("");
        Serial.println("");
        Serial.println("CMD Decimale : ");   
        for (int t = 0; t < 17; t++)
          {
          byte cmd[17] = {0x01,0x02,0x00,0x0b,0x01,0x50,0x20,0x00,0x00,0x04,outh,0x00,0x80,0x00,xpth,csm,0x03};
          Serial.print (cmd[t], HEX);    
          }
        Serial.println("");
        Serial.println("- Infos -");
        Serial.print("Memory - IN : ");
        Serial.print(memory[0][index] + 1);
        Serial.print(" OUT : ");
        Serial.println(memory[1][index]);
        Serial.print("In - decimal : ");
        Serial.print(xpth, DEC);
        Serial.print(" hexa : ");
        Serial.println(xpth, HEX);
        Serial.print("Out - decimal : ");
        Serial.print(outh, DEC);
        Serial.print(" hexa : ");
        Serial.println(outh, HEX);
        Serial.print("Checksum - decimal : ");
        Serial.print(csm, DEC);
        Serial.print(" hexa :");
        Serial.println(csm, HEX);
        Serial.print("Variables - IN : ");
        Serial.print(variableIn);
        Serial.print(" OUT : ");
        Serial.println(variableOut);
        Serial.println("");
        }
      }
    } 
  }
}

void loop() {                                                                                         // Fonctions Display / Store / Variables / TRIGGERS 1 à 12 + write serial  

    if (millis() - derniereActivation > delaiMax) {
      pause = true;
    }
      for (int index = 0; index < 3; index++)
    if (boutons[13 + index] == 1) {
      pause = 0;
      derniereActivation = millis();
    }
  triggers();
  if (pause == false){
  updateDisplay1();
  } else {
  bootscreen ();
  }
  compteur();
  store();
  rscommand();
}

Simulator that helped me when i was not at home (for the actual cable diagram and things i use, but the mux seems not working on wokwi, dunno why becuase it works well irl):

My problem is : I can't see any of the commands sent by the remote into my computer on a RS232 terminal, did i miss something ?

Sorry in advance for all the french words in the code!

You can not use Serial for distinct PC and RS-232 communication at the same time.

I tried with my arduino not plugged into my pc too.

I'm facing another problem, whenever i try to add more code, my OLED screen stop working. So i can't use softwareSerial.h ...

The USB and RS-232 ports work against each other. You can not use both at the same time.

I've tried this while everything is connected,oled code included :

  • ARDUINO UNO connected by USB into my computer, i got what i want into the serial monitor, TX/RX leds blinking

  • ARDUINO UNO connected only with an external power supply, everything else except the command part is working, TX RX leds not blinking

  • ARDUINO UNO connected only with an external power supply, TTL/RS232 board connected into my RS232 to USB cable, everything else except the command part is working, TX RX leds not blinking when i send commands, nothing displayed onto my computer in a serialmonitor (into the COM port of my usb cable, baudrate set to the same as the arduino)

  • I tried the same setup with a TTL/RS232 board who have leds onto. The RX/TX LED of this boards do blink in a setup with everyone connected ! But i don't get anything in my serial monitor.

I really think it's my USB/RS232 cable that don't work, i included a print of the freeram at the boot, it should display on my SerialMonitor in IDE or PUTTY when i reset my arduino board right ?

PS : I don't have any oscillator, but i did mesure 5v at the input of my max232, a 5V for the ttl between my TX and GND, with various mesurement when i trigger so i assume that it's working, and a mesurement of -9v in the off state between my max232 TX output and GND, when i trigger something, because i don't have an oscillator, i can't really see if it goes up +3v, i only see my values going at -7 so i assume that's not a good statement.
Thanks in advance

Post #2, Post #5.
You need to refer to the Uno schematic and figure this out for yourself.

I see you are using the UNO serial port for two separate devices. Why are you doing that since it will NEVER work! If you want two separate serial ports on a UNO, you must use some version of "software serial" for the second connection.

What do you mean?
I won't use the USB port of the uno anyway, so it should work like that right ? There is only my MAX232 board plugged into my RX/TX pins

So, you're not using Serial Monitor, only the external RS232 adapter? And your code is what you're showing in Wokwi? Sorry if I'm asking you to repeat yourself, I want to confirm something.

I'm reasoanbly sure that your serial print statements will confuse your AV device.

So how do you expect to see something if you don't use the USB? I'm a bit confused.

Note
The Rx/Tx leds are controlled by the serial-to-usb converter; as far as I know they will not give any indication (at least for a genuine Uno, no idea about clones) if the board does not have a USB connection.

Ok, that's something !

My print statements will be disabled when everything will be working, it was only to help me code the entire thing. And i did add some delays before and after my Serial.write (which are slightly longer than the one Sony tell in the documentation) so i may be thinking it will be okay.

I expect to see something in a serial monitor, with a RS232 subd9 to USB cable on the pc side(on a COM something with the correct baud rate) which is plugged into the TTL to RS232 adapter on the arduino side. Sorry if it's a little bit unclear.

I just want to see the RS232 output of my TTL to RS232 adapter into my computer.

So if my leds onto the board are not blinking, it's because i don't have a usb plugged.
They do blink on the TTL to RS232 adapter that i plug into my RX/TX pins tho so it should be ok right ?

I did update the wokwi code btw.

I'm not using the USB of the Arduino Uno board. Only using it with a 12V powersupply.
I did plug the TX/RX pins onto a TTL to RS232 adapter with a max232 chip. (the attribution of thoses pins before my setup was a mistake, i did removed it)
I did plug PC side a USB to Sub-d9 RS232 cable.

I plugged this cable onto the ttl to RS232 adapter, and did expect to see in the IDE serial monitor, or PuTTY, with the com port selected to my cable, baud rate set, the print that my arduino should send in the TX pin.

Do you think i did miss something ?

I really think that the usb to subd9 cable is broken, i'll try another one sunday.

The reason we like schematics is, sorting through all that text to figure out your connection is tiring.
I don't see mention of grounds in all of that, so - do you have a common ground from Arduino, across the RS232 adapter, from one RS232 port to the other, and across the RS232-USB adapter, to the PC? And is that common ground also connected to your power for all of this?

Sorry if it wasn't clear. I didn't find or did get time to add the TTL to RS232 to wokwi.
I'll draw a quick schematics of my build and send it.
All my ground are common, i did make my build onto a breadboard so i use only one bus for all my grounds.

1 Like

I really like having schematics too ! My mistake to didn't start with that !

Usually I forget to start with a schematic when I assume the problem is too simple to be worth the explanation. Usually, I'm wrong...

So, on the PC side, what software is receiving this? You keep writing serial monitor, not Serial Monitor, so I suspect you're using some other software?
edit.
I don't know Putty, but it's a terminal app. Do you have the right baud rate, bit count, parity set?

I tried 2 ways :
PUTTY with the COM port of my usb to db9 cable set and the baud rate set like my arduino
In IDE, setting my com port to watch as the one of my cable, and using the serial monitor to watch

Dunno for the parity settings... but i almost tried every setup possible

I THINK that would work, but I've never tried that with Serial Monitor, so...
But straightforward Putty should work. I'm going back to look at your code in Wokwi. Back in a few.

Question 1. What's the memory report like, at the end of the successful compile?

Thanks for your time.
The 16ch mux does not work in wokwi, but works perfectly fine in real life.
So unfortunately, i will have to modify the code (maybe tommorow if i have some spare time) to trigger the "rscommand" function if you want to try it inside the simulator.