Help with Arduino ROS Communication

Hi, I'm abit frustrated using rosserial at the moment. my code below
Generally works fine, when i establish connection with ROS i am able to view my encoder readings from the first motor aswell. The moment i publish speed data to any of the topics the arduino node is subscribed to, the sensor readings turn to 0 as though being canceled out. Please any help will be much appreciated.

#include <Arduino.h>
#include <ros.h>
#include <std_msgs/UInt16.h>
#include <stdio.h> 
#include <stdlib.h>
#include "speedmeter.h"
#include "motor.h"
#include "brake.h"

#define roboclawRxPin1 9
#define roboclawTxPin1 8
#define roboclawRxPin2 11
#define roboclawTxPin2 10

ros::NodeHandle nh;

std_msgs::UInt16 speed_msg1;
//----------------------------------Publish Encoder readings-------------------
ros::Publisher pb_speed1("pb_speed1", &speed_msg1);
//----------------------------------Initialize motor and encoder values------------------
Motor *myMotor1;
Motor *myMotor2;
Encoder *myEncoder1;
Encoder *myEncoder2;

//----------------------------------Subscriber call back functions for R1 Speed---------------
void speedCallback1(const std_msgs::UInt16& cmd_msg) {
    myMotor1->MotorSpeed(cmd_msg.data);
}

//----------------------------------Subscriber callback functions for R2 Speed-------------
void speedCallback2(const std_msgs::UInt16& cmd_msg){
  myMotor2->MotorSpeed(cmd_msg.data);
}

//----------------------------------Create subscription instance for ROS-Subscriber-----------------
ros::Subscriber<std_msgs::UInt16> sub_speed1("pub_speed1", speedCallback1);
ros::Subscriber<std_msgs::UInt16> sub_speed2("pub_speed2", speedCallback2);

//---------------------------------Initialize ROS,motor, and encoders---------------
void setup() {
  nh.getHardware()->setBaud(115200);
  nh.initNode();
  nh.advertise(pb_speed1);

//------------------------Create new motor object for controlling rollers1&2--------------
  myMotor1 = new Motor(roboclawRxPin1, roboclawTxPin1);
  myMotor1->MotorSpeed(10);
  myMotor2 = new Motor(roboclawRxPin2, roboclawTxPin2);
  myMotor2->MotorSpeed(10);

//------------------------Subscribe to published speeds from ROS---------------
  
  nh.subscribe(sub_speed1);
  nh.subscribe(sub_speed2);

//-----------------------Creates a new encoder object for interfacing with the motor------------------------

  myEncoder1 = new Encoder(roboclawRxPin1, roboclawTxPin1);
}

//------------------------------Reads and publishes encoder value ----------------------------
void loop() {

//------------------------------Reads the encoder value---------------------------
  int speed1Value = myEncoder1->readSpeed();
  Serial.print("Encoder1: ");
  Serial.println(speed1Value);
//-------------------------------Assign encoder vvalue to message -----------------------------
  speed_msg1.data = speed1Value;
  Serial.println(speed1Value);
//-------------------------------Publish message and handle ROS communication ------------------------------
  pb_speed1.publish(&speed_msg1);
  
  nh.spinOnce();
  delay(100);
}

and the ROS topic publishing.

rostopic pub /pub_speed1 std_msgs/UInt16 'data: 20'

Read the specs for the ROS. There are for sure rules for the tasks it is made to handle. Somehow Serial.print looks like violating the rules.

Is ROS Runner On Ship or is ROS a Robot Operating System or ???. I assume it is an operating system but I Had to go through stuff to figure that one out.

yes robot operating system

Using a call of the delay() function isn´t very tricky?

hi, even without the serial print there it still carries on the same way. i only had the serial prints in there to check if i could view the data from the encoder on the serial monitor of the arduino first, which it does. poblem comes when i move over to ROS.

Okey. Still, read the ROS specification about the rules for the tasks it administrates.
Is there memory enough for the ROS and the tasks?