ColorPal software and hardware serial

I’ve been trying to read some sensor valiues from my ColorPal on arduino Mega.
It works OK when I try to use software serial, but when I try to use hardware serial it doesn’t work.
This is colorPal : https://www.parallax.com/product/28380
and my code that works:

#include <SoftwareSerial.h>

int sio = 52;                // ColorPAL connected to pin 2
const int unused = 53;         // Non-existant pin # for SoftwareSerial
const int sioBaud = 4800;
const int waitDelay = 200;
void readData(byte*green);


// Received RGB values from ColorPAL
int red;
int grn;
int blu;
byte green;

// Set up two software serials on the same pin.
SoftwareSerial serin(sio, unused);
SoftwareSerial serout(unused, sio);

void setup() {
  pinMode(12, OUTPUT);
  pinMode(43, INPUT);
  Serial.begin(9600);
  reset(sio);                  // Send reset to ColorPal
  serout.begin(sioBaud);
  pinMode(sio, OUTPUT);
  serout.print("= (00 $ m) !"); // Loop print values, see ColorPAL documentation
  serout.end();              // Discontinue serial port for transmitting
  serin.begin(sioBaud);            // Set up serial port for receiving
  pinMode(sio, INPUT);
}

void loop() {
 
  readData(&green);
  Serial.println(green);
}

// Reset ColorPAL; see ColorPAL documentation for sequence
void reset(byte sio) {
  delay(200);
  pinMode(sio, OUTPUT);
  digitalWrite(sio, LOW);
  pinMode(sio, INPUT);
  while (digitalRead(sio) != HIGH);
  pinMode(sio, OUTPUT);
  digitalWrite(sio, LOW);
  delay(80);
  pinMode(sio, INPUT);
  delay(waitDelay);
}

void readData(byte * green) {
  char buffer[32];
 
  if (serin.available() > 0) {
    // Wait for a $ character, then read three 3 digit hex numbers
    buffer[0] = serin.read();
    if (buffer[0] == '

and the one that doesn’t work:

byte sio = 14;
const int sioBaud = 4800;
const int waitDelay = 200;
void readData(byte*green);


// Received RGB values from ColorPAL
int red;
int grn;
int blu;
byte green;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  reset();
  Serial2.begin(4800);
  Serial2.write("= R !");
}

void loop() {
readData(&green);
}

void reset() { 
  Serial2.end();
  pinMode(sio, OUTPUT);
  digitalWrite(sio, LOW);
  pinMode(sio, INPUT);
  while(digitalRead(sio) == LOW);
  pinMode(sio, OUTPUT);
  digitalWrite(sio, LOW);
  delay(60);
  pinMode(sio, INPUT);
  delay(10);
}

void readData(byte * green) {
  char buffer[32];
  if (Serial2.available() > 0) {       // Wait for a $ character, then read three 3 digit hex numbers
    buffer[0] = Serial2.read();
    if (buffer[0] == '

) {
      for(int i = 0; i < 9; i++) {
        while (serin.available() == 0);    // Wait for next input character
        buffer[i] = serin.read();
        if (buffer[i] == ’


and the one that doesn't work:

§DISCOURSE_HOISTED_CODE_1§


)               // Return early if $ character encountered
          return;
      }
      *green = parseAndPrint(buffer);
      delay(10);
    }
  }
}

// Parse the hex data into integers
byte parseAndPrint(char * data) {
  sscanf (data, "%3x%3x%3x", &red, &grn, &blu);
  char buffer[32];
  sprintf(buffer, "R%4.4d G%4.4d B%4.4d", red, grn, blu);
  Serial.println(buffer);
  return grn;
}

and the one that doesn’t work:

§_DISCOURSE_HOISTED_CODE_1_§

) {
      for(int i = 0; i < 9; i++) {
        while (Serial2.available() == 0);    // Wait for next input character
        buffer[i] =Serial2.read();
        if (buffer[i] == ’


) {
      for(int i = 0; i < 9; i++) {
        while (serin.available() == 0);     // Wait for next input character
        buffer[i] = serin.read();
        if (buffer[i] == '

and the one that doesn’t work:

§_DISCOURSE_HOISTED_CODE_1_§

)              // Return early if $ character encountered
          return;
      }
      *green = parseAndPrint(buffer);
      delay(10);
    }
  }
}

// Parse the hex data into integers
byte parseAndPrint(char * data) {
  sscanf (data, “%3x%3x%3x”, &red, &grn, &blu);
  char buffer[32];
  sprintf(buffer, “R%4.4d G%4.4d B%4.4d”, red, grn, blu);
  Serial.println(buffer);
  return grn;
}


and the one that doesn't work:

§DISCOURSE_HOISTED_CODE_1§


)  // Return early if $ character encountered
          return;
      }
      *green = parseAndPrint(buffer);
      delay(10);
    }
  }
}

// Parse the hex data into integers
byte parseAndPrint(char * data) {
  sscanf (data, "%3x%3x%3x", &red, &grn, &blu);
  char buffer[32];
  sprintf(buffer, "R%4.4d G%4.4d B%4.4d", red, grn, blu);
  Serial.println(buffer);
  return grn;
}

) {
      for(int i = 0; i < 9; i++) {
        while (serin.available() == 0);    // Wait for next input character
        buffer[i] = serin.read();
        if (buffer[i] == ’


and the one that doesn't work:

§DISCOURSE_HOISTED_CODE_1§


)               // Return early if $ character encountered
          return;
      }
      *green = parseAndPrint(buffer);
      delay(10);
    }
  }
}

// Parse the hex data into integers
byte parseAndPrint(char * data) {
  sscanf (data, "%3x%3x%3x", &red, &grn, &blu);
  char buffer[32];
  sprintf(buffer, "R%4.4d G%4.4d B%4.4d", red, grn, blu);
  Serial.println(buffer);
  return grn;
}

and the one that doesn’t work:

§_DISCOURSE_HOISTED_CODE_1_§

your reset function uses different timing, could that be the cause?

It doesn't work with different timing.