Hello all,

I am using a Teensy 3.2 to drive an autonmous RC car. The car has an TX2 (with ubuntu 18.04) on it and the Teensy is suppose to do 2 things.

1. Read PWM signals from an RC receiver and use these values for a USB Joystick to the TX2
2. Read hall effect encoders and send this to the TX2 over USB Serial.

However on the TX2 it seems like the joystick locks up, if the Serial.print() is running. If I comment out that line then everything works fine.
Is this something that cannot be done? Or am I doing something wrong?

Thanks for the help. Code attached.

Code:
#define throttle_rc_pin 21
#define steering_rc_pin 20
#define aux1_rc_pin     22
#define aux2_rc_pin     23

#define hall_a_pin      5
#define hall_b_pin      4
#define hall_c_pin      3

volatile uint16_t rc_throttle;
uint16_t rc_throttle_start;

volatile uint16_t rc_steering;
uint16_t rc_steering_start;

volatile uint16_t rc_aux1;
uint16_t rc_aux1_start;

volatile uint16_t rc_aux2;
uint16_t rc_aux2_start;

volatile uint16_t hall_a;
uint16_t hall_a_start;

volatile uint16_t hall_b;
uint16_t hall_b_start;

volatile uint16_t hall_c;
uint16_t hall_c_start;

int aux1 = 0;
int aux2 = 0;
int hall = 0;
int rpm  = 0;

void setup() {
  Serial.begin(9600);
  Joystick.useManualSend(true);
  
  pinMode(throttle_rc_pin, INPUT);
  pinMode(steering_rc_pin, INPUT);
  pinMode(aux1_rc_pin, INPUT);
  pinMode(aux2_rc_pin, INPUT);
  pinMode(hall_a_pin, INPUT);
  
  attachInterrupt(throttle_rc_pin, RC_Throttle, CHANGE);
  attachInterrupt(steering_rc_pin, RC_Steering, CHANGE);
  attachInterrupt(aux1_rc_pin, RC_Aux1, CHANGE);
  attachInterrupt(aux2_rc_pin, RC_Aux2, CHANGE);
  attachInterrupt(hall_a_pin, Hall_A, CHANGE);
  attachInterrupt(hall_b_pin, Hall_B, CHANGE);
  attachInterrupt(hall_c_pin, Hall_C, CHANGE);
}

int i = 0;

void loop() {
  if(rc_aux1 > 1600 || rc_aux1 < 1400) 
    aux1 = 1;
  else
    aux1 = 0;

  if(rc_aux2 > 1600 || rc_aux2 < 1400)
    aux2 = 1;
  else 
    aux2 = 0;

  hall = (hall_a + hall_b + hall_c)/3;
  rpm = 2/(hall/1000000);
  Serial.println(rpm);
  
  Joystick.X(map(rc_throttle,1000,2000,0,1023));
  Joystick.Y(map(rc_steering,1000,2000,0,1023));
  
  Joystick.button(1, aux1);
  Joystick.button(2, aux2);
  Joystick.send_now();
  delay(5);
}


void RC_Throttle() {
  if (digitalRead(throttle_rc_pin) == HIGH) {
    rc_throttle_start = micros();
  } else {
    rc_throttle = (uint16_t) (micros() - rc_throttle_start);
  }
}

void RC_Steering() {
  if (digitalRead(steering_rc_pin) == HIGH) {
    rc_steering_start = micros();
  } else {
    rc_steering = (uint16_t) (micros() - rc_steering_start);
  }
}

void RC_Aux1() {
  if (digitalRead(aux1_rc_pin) == HIGH) {
    rc_aux1_start = micros();
  } else {
    rc_aux1 = (uint16_t) (micros() - rc_aux1_start);
  }
}

void RC_Aux2() {
  if (digitalRead(aux2_rc_pin) == HIGH) {
    rc_aux2_start = micros();
  } else { 
    rc_aux2 = (uint16_t) (micros() - rc_aux2_start);
  }
}


void Hall_A() {
  if (digitalRead(hall_a_pin) == HIGH) {
    hall_a_start = micros();
  } else { 
    hall_a = (uint16_t) (micros() - hall_a_start);
  }
}

void Hall_B() {
  if (digitalRead(hall_b_pin) == HIGH) {
    hall_b_start = micros();
  } else { 
    hall_b = (uint16_t) (micros() - hall_b_start);
  }
}

void Hall_C() {
  if (digitalRead(hall_c_pin) == HIGH) {
    hall_c_start = micros();
  } else { 
    hall_c = (uint16_t) (micros() - hall_c_start);
  }
}