Issue with Serial.write

Hey all. I’m facing an issue with the Serial.write function, and I’m not sure what exactly I’m doing incorrectly. I’m using an Arduino Leonardo, on the ROMI robot. My code is as per below. I’m in the prototyping stage, but effectively all that should happen is the robot goes forwards for the moment, using PWM on a couple of motors. My issue is that during the “setup” function, the serial monitor should be reading “Waiting for button A…” until I push the A button on the hardware, and “Initialisation Complete.” once setup is done. It’s no displaying either of those currently. Any help if very much appreciated.

include <Arduino.h>
#include <Romi32U4.h>
#include <Pushbutton.h>

// Pin and sensor definitions
#define BAUD_RATE = 115200
#define L_PWM_PIN 10
#define L_DIR_PIN 16
#define R_PWM_PIN  9
#define R_DIR_PIN 15
#define LINE_LEFT_PIN A4 //Pin for the left line sensor
#define LINE_CENTRE_PIN A3 //Pin for the centre line sensor
#define LINE_RIGHT_PIN A2 //Pin for the right line sensor
#define BUZZER_PIN 6

Romi32U4ButtonA buttonA;
unsigned long last_timestamp;       // Store a timestamp in this.
const int buzzer = BUZZER_PIN;
byte l_power;                       // Store variables for left and right motor
byte r_power;                       // from 0 to 255.
byte sensorL;
byte sensorC;
byte sensorR;
int thresholdL;
int thresholdC;
int thresholdR;
bool returnHome;

void setup() {
  // Initiate Pins and Variables. 
  pinMode( L_PWM_PIN, OUTPUT );     // PWM left motor.
  pinMode( L_DIR_PIN, OUTPUT );     // Direction left motor.
  pinMode( R_PWM_PIN, OUTPUT );     // PWM right motor.
  pinMode( R_DIR_PIN, OUTPUT );     // Direction right motor.
  pinMode( buzzer, OUTPUT );        // Buzzer.
  pinMode( LINE_LEFT_PIN, INPUT );
  pinMode( LINE_CENTRE_PIN, INPUT );
  pinMode( LINE_RIGHT_PIN, INPUT );
  sensorL = digitalRead( LINE_LEFT_PIN );
  sensorC = digitalRead( LINE_CENTRE_PIN );
  sensorR = digitalRead( LINE_RIGHT_PIN );
  last_timestamp = millis();        // We set an intial timestamp value.
  returnHome = false;
  Serial.write("Waiting for button A...");
  buttonA.waitForButton();          // Wait for button A to be pushed before starting loop.

  // Define Initial Pin and Variable Values.
  digitalWrite( L_DIR_PIN, LOW );   // Set initial direction L.
  digitalWrite( R_DIR_PIN, LOW );   // Set initial direction R.
  l_power = 0;                      // Set power.
  r_power = 0;                      // Set power.
  thresholdL = sensorL + 20;
  thresholdC = sensorC + 20;
  thresholdR = sensorR + 20;
  Serial.write("Initialisation Complete.");
}

void joinLine() {
  l_power = 25;
  r_power = 26;
  analogWrite( L_PWM_PIN, l_power );
  analogWrite( R_PWM_PIN, r_power );
  while ( sensorC < thresholdC ) {

  }
  digitalWrite( R_DIR_PIN, HIGH );
  delay(500);
  digitalWrite( R_DIR_PIN, LOW );
  Serial.write("Line Joined.");
}

/* void followLine() {
  do {
    while ( sensorL < sensorR ) {
      l_power = l_power + 1;
      r_power = r_power - 1;
      analogWrite( L_PWM_PIN, l_power );
      analogWrite( R_PWM_PIN, r_power );
    }
    while ( sensorL > sensorR ) {
      l_power = l_power + 1;
      r_power = r_power - 1;
      analogWrite( L_PWM_PIN, l_power );
      analogWrite( R_PWM_PIN, r_power );
    }
  } while ( sensorC > thresholdC + 10 );
  l_power = 0;
  r_power = 0;
  analogWrite( L_PWM_PIN, l_power );
  analogWrite( R_PWM_PIN, r_power );
  tone( buzzer, 1000 );
  delay( 1000 );
  noTone( buzzer );
  Serial.write("Line Finished.");
  do {
    delay(50);
  } while ( returnHome == false );
} */

void loop() {
  joinLine();
  // followLine();
}

Shouldn't there be a Serial.begin() in there somewhere ?

UKHeliBob:
Shouldn't there be a Serial.begin() in there somewhere ?

That'll be it. Sleep deprivation causing some rookie errors as always!

EDIT: Scratch that, no dice. Still have the same issue, even with

void setup() {
  // Initiate Pins and Variables. 
  Serial.begin(9600);
  Serial.println("Begin Initialisation.");

As it's a Leonardo you need to wait for Serial to be available

void setup() {
  // Initiate Pins and Variables.
  Serial.begin(9600);
  while(!Serial);
  Serial.println("Begin Initialisation.");