Ghost signals, pull ups not working

I'm not sure if this is because of my code or if its the board itself. I keep getting ghost signals from my input pins when I run my code. I have tried turning on the pull up resistors and changing the if statements accordingly but then the code won't register any inputs at all. The input voltages are coming from a rasberry pi's GPIO pins, which have been set to output. any advice guys? Here is my code

static int LeftPin= 6;
static int RightPin= 7;
static int Inpin1 = 3;
static int Inpin2 = 4;
void setup() {
pinMode(Inpin1,INPUT_PULLUP);
pinMode(Inpin2,INPUT_PULLUP);
pinMode(LeftPin,OUTPUT);
pinMode(RightPin,OUTPUT);
Serial.begin(4800);
}

void loop() {
 if (digitalRead(Inpin1)==LOW)
 {
  digitalWrite(LeftPin,HIGH);
  Serial.print(1);
 }
  else {
  digitalWrite(LeftPin,LOW);
  Serial.print(4);
  }
  
  if (digitalRead(Inpin2)==LOW) {
    digitalWrite(RightPin,HIGH);
    Serial.print(3);
  }
   else {
    digitalWrite(RightPin,LOW);
    Serial.print(4);
  }
 }

Did you share grounds?

When one board is accidently off, the other one will try to phantom-power it throught the I/O pins.
So it's wise to have (1-10k) protection resistors between the IO pins of both boards.
Leo..