Sending 10 bytes from one Uno to another and keeping them ordered

Hey guys, im a bit stuck. What i want to do is to receive 10 DMX channels one an Arduino Uno with a DMX shield. Then i want to send them to an Mega where those 10 Channels should controll motors. The DMX shield uses the Serial Port so i send them over Software Serial. DMX Values only go from 0 to 255 so a byte should be allright and faster than sending INTs as i understand. I allready read like all the Infos on serial receiving and parsing but like all examples i found receive strings which are then parsed into different sections. Is there a way how to send them as a array between start and end markers and then reading them on the Mega in the same order? Or should i send them as a string and then parse them out of that?

#include <SoftwareSerial.h>

#include <DMXSerial.h>
#define rxpin 10
#define txpin 11

SoftwareSerial mySerial(rxpin,txpin, true); //RX,TX 
// Values for Motors

int MOTORX ;
int MOTORY ;
int MOTORZ ;
int MOTORE ;
int MOTORQ ;
int MOTORX1 ;
int MOTORY1 ;
int MOTORZ1 ;
int MOTORE1 ;
int MOTORQ1 ;
const int SPEED1 = 1000;
const int SPEED2 = 100;
const int MID = 122;
const int SPEED_SEND = 200;

void setup () {
  DMXSerial.init(DMXReceiver);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(rxpin, INPUT);
  pinMode(txpin, OUTPUT);
  mySerial.begin(9600); //begin myserial transmission
  
  // set the values to 0 by default
  DMXSerial.write(1, 0);
  DMXSerial.write(2, 0);
  DMXSerial.write(3, 0);
  DMXSerial.write(4, 0);
  DMXSerial.write(5, 0);
  DMXSerial.write(6, 0);
  DMXSerial.write(7, 0);
  DMXSerial.write(8, 0);
  DMXSerial.write(9, 0);
  DMXSerial.write(10, 0);   

}


void loop() {
  // Calculate how long no data backet was received
  unsigned long lastPacket = DMXSerial.noDataSince();
  
 if (lastPacket < 5000) {
    // read recent DMX values and order them to Motors 

    digitalWrite(LED_BUILTIN, HIGH); //to show DMX is received
    
    MOTORX =  (DMXSerial.read(1));
    MOTORY =  (DMXSerial.read(2));
    MOTORZ =  (DMXSerial.read(3));
    MOTORE =  (DMXSerial.read(4));
    MOTORQ =  (DMXSerial.read(5));
    MOTORX1 =  (DMXSerial.read(6));
    MOTORY1 =  (DMXSerial.read(7));
    MOTORZ1 =  (DMXSerial.read(8));
    MOTORE1 =  (DMXSerial.read(9));
    MOTORQ1 =  (DMXSerial.read(10));
    
    mySerial.write(MOTORX); // Here i dont know how to pack those values right. 
    
  } else {
    
    // Blink Arduino LED if no signal
  digitalWrite(LED_BUILTIN, HIGH);   
  delay(500);                       
  digitalWrite(LED_BUILTIN, LOW);    
  delay(500);   
 }
  } // if




//}

// End.

I think that the DMX values are send more often from the lighting desk, than the Arduino can read them, should be no problem. The DMX part is allread working fine, tried with Leds for testing.

To receive it i want to order the 10 values back to motor 1 to 10. And here i have no clue how.
Any hints are welcomed. Sry if i throw arround words wrongly, first time working with serial and more than one value. I guess this should be a easy task but i cant get my head arround. Thanks in advance, Mateo

Is it a problem to define MOTORX etc. as an INT instead of a uint8_t or Byte?

Give me a numerical example of the set of data bytes that you are receiving from DMX and then wish to send them to MEGA using UART Port.

No its not a problem to use INT. Anyway i thought this is slower than using it as a byte. With

MOTORX = (DMXSerial.read(1));

i get the real value of the first channel from the DMX signal. so something between 0 and 255. Dependent on what i send from my lighting desk. If i understood your question correctly. Then i want to send the values over to the Mega and use them again as MotorX, MotorY and so on. Greets.

mateoman:
No its not a problem to use INT. Anyway i thought this is slower than using it as a byte. With

MOTORX = (DMXSerial.read(1));

i get the real value of the first channel from the DMX signal. so something between 0 and 255. Dependent on what i send from my lighting desk. If i understood your question correctly. Then i want to send the values over to the Mega and use them again as MotorX, MotorY and so on. Greets.

1. Let us assume that you have 10 Motors with these designations: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
The data for the Motors are respectively: 0x30, 0x31, 0x32, 0x33, 0x24, 0x35, 0x36, 0x37, and 0x39.

2. You can send the above message of Step-1 to MEGA in ASCII UART Frame as follows using print() method:
<030,131,232,333,434,535,636,737,838,939,\n
where:
< is the START mark of the frame.
\n is the END mark of frame.

3. The transmitted frame of Step-2 will contain the following signals:
3C3033302C...........................3933390A where, the characters/digits are sent in ASCII codes.

You need to employ appropriate processing scheme at the receiver side to extract information: MotorNumber, MotorData.

The charcaters/digits are coded to their ASCII values as per following Table (Fig-1):


Figure-1:

4. You can send the message of Step-1 to MEGA in Binary UART Frame. The transmitted frame will contain the following signals:
3C0030....................09390A where, characters/digits are sent as natural binary codes

You need to employ appropriate processing scheme at the receiver side to extract information: MotorNumber, MotorData.

Take a look at Serial input basics - updated to see how to receive and parse data over Serial

...and look at some serial transfer libraries like this one

"The DMX shield uses the Serial Port so i send them over Software Serial. DMX Values only go from 0 to 255 so a byte should be allright and faster than sending INTs as i understand."

In the real world, your motors will probably respond slower than either way that you send the data.

For anyone having similar problems:
So ive got it working thanks to a nice and simple explanation from a Facebook Arduino-forums user. He gave me that link with explanations of him:

I modded the code so i can send multiple bytes directly instead as he did as Ints send in 2 bytes. My code to send them now looks like this:

#include <SoftwareSerial.h>

#include <DMXSerial.h>
#define rxpin 10
#define txpin 11

SoftwareSerial mySerial(rxpin,txpin); //RX,TX 
// Values for Motors

byte MOTORX ;
byte MOTORY ;
byte MOTORZ ;
byte MOTORE ;
byte MOTORQ ;
byte MOTORX1 ;
byte MOTORY1 ;
byte MOTORZ1 ;
byte MOTORE1 ;
byte MOTORQ1 ;

/*byte byteArray[10];
byteArray[0]=MOTORX;
const int SPEED1 = 1000;
const int SPEED2 = 100;
const int MID = 122;
const int SPEED_SEND = 200;*/

void setup () {
  DMXSerial.init(DMXReceiver);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(rxpin, INPUT);
  pinMode(txpin, OUTPUT);
  mySerial.begin(9600); //begin myserial transmission
  
  // set the values to 0 by default
  DMXSerial.write(1, 0);
  DMXSerial.write(2, 0);
  DMXSerial.write(3, 0);
  DMXSerial.write(4, 0);
  DMXSerial.write(5, 0);
  DMXSerial.write(6, 0);
  DMXSerial.write(7, 0);
  DMXSerial.write(8, 0);
  DMXSerial.write(9, 0);
  DMXSerial.write(10, 0);   

}


void loop() {
  // Calculate how long no data backet was received
  unsigned long lastPacket = DMXSerial.noDataSince();
  
 if (lastPacket < 5000) {
    // read recent DMX values and order them to Motors 

    digitalWrite(LED_BUILTIN, HIGH); //to show DMX is received
    
    MOTORX =  (DMXSerial.read(1));
    MOTORY =  (DMXSerial.read(2));
    MOTORZ =  (DMXSerial.read(3));
    MOTORE =  (DMXSerial.read(4));
    MOTORQ =  (DMXSerial.read(5));
    MOTORX1 =  (DMXSerial.read(6));
    MOTORY1 =  (DMXSerial.read(7));
    MOTORZ1 =  (DMXSerial.read(8));
    MOTORE1 =  (DMXSerial.read(9));
    MOTORQ1 =  (DMXSerial.read(10));

 byte checksum = 0;
 checksum += (byte) MOTORX;
 checksum += (byte) MOTORY;
 checksum += (byte) MOTORZ;
 checksum += (byte) MOTORE;
 checksum += (byte) MOTORQ;

 mySerial.write(253); // start 
 mySerial.write(255); // start 
 mySerial.write(MOTORX); // write x byte
 mySerial.write(MOTORY); // write y byte
 mySerial.write(MOTORZ);
 mySerial.write(MOTORE);
 mySerial.write(MOTORQ);
 mySerial.write(checksum); //check if together
 delay(100);

    
  } else {
    
    // Blink Arduino LED if no signal
  digitalWrite(LED_BUILTIN, HIGH);   
  delay(500);                       
  digitalWrite(LED_BUILTIN, LOW);    
  delay(500);   
 }
  } // if




//}

// End.

And the code for receiving the values, remapping them to right valueholders from the buffer, and mappin x to a new range, which will be the range from one endstop to another:

#include <Stepper.h>


 boolean messageStarted = false;
 byte dataBuffer[12];
 byte dataBufferIndex = 0;

//X Motor Pins  
  #define X_STEP_PIN         54
  #define X_DIR_PIN          55
  #define X_ENABLE_PIN       38
  #define X_MIN_PIN           3
  #define X_MAX_PIN           2
  byte MOTORX;
  int stepsX = 20000;
  int posi = 0;
  byte multi = 5;
  
//Y Motor Pins 
  #define Y_STEP_PIN         60
  #define Y_DIR_PIN          61
  #define Y_ENABLE_PIN       56
  #define Y_MIN_PIN          14
  #define Y_MAX_PIN          15
  byte stepsY = 0;
  byte MOTORY;
  
//Z Motor Pins 
  #define Z_STEP_PIN         46
  #define Z_DIR_PIN          48
  #define Z_ENABLE_PIN       62
  #define Z_MIN_PIN          18
  #define Z_MAX_PIN          19
  int stepsZ ;
  byte MOTORZ;
  
//E Motor Pins 
  #define E_STEP_PIN         26
  #define E_DIR_PIN          28
  #define E_ENABLE_PIN       24
  int stepsE ;
  byte MOTORE;
  
//Q Motor Pins 
  #define Q_STEP_PIN         36
  #define Q_DIR_PIN          34
  #define Q_ENABLE_PIN       30
  int stepsQ ;
  byte MOTORQ;
  
//? Pins 
  #define SDPOWER            -1
  #define SDSS               53
  #define LED_PIN            13
  
//X Motor Pins 
  #define FAN_PIN            9
//? Pins 
  #define PS_ON_PIN          12
  #define KILL_PIN           -1
  
//? Pins 
  #define HEATER_0_PIN       10
  #define HEATER_1_PIN       8
  #define TEMP_0_PIN          13   // ANALOG NUMBERING
  #define TEMP_1_PIN          14   // ANALOG NUMBERING
  
// Motor_Specs
const int STEPS_PER_REVOLUTION = 3200;
const int MAX_MOTOR_SPEED = 50;
const int MED_MOTOR_SPEED = 500;
int MOTOR_SPEED_SEND ;


void setup() {

  Serial.begin(9600);
  Serial2.begin(9600);
 // mySerial.begin(9600);
  
  pinMode(FAN_PIN , OUTPUT);
  pinMode(HEATER_0_PIN , OUTPUT);
  pinMode(HEATER_1_PIN , OUTPUT);
  pinMode(LED_PIN  , OUTPUT);
  
  pinMode(X_STEP_PIN  , OUTPUT);
  pinMode(X_DIR_PIN    , OUTPUT);
  pinMode(X_ENABLE_PIN    , OUTPUT);
  pinMode(X_MIN_PIN   ,INPUT_PULLUP);
  pinMode(X_MAX_PIN   ,INPUT_PULLUP);
  
  pinMode(Y_STEP_PIN  , OUTPUT);
  pinMode(Y_DIR_PIN    , OUTPUT);
  pinMode(Y_ENABLE_PIN    , OUTPUT);
  pinMode(Y_MIN_PIN   ,INPUT_PULLUP);
  pinMode(Y_MAX_PIN   ,INPUT_PULLUP);
  
  pinMode(Z_STEP_PIN  , OUTPUT);
  pinMode(Z_DIR_PIN    , OUTPUT);
  pinMode(Z_ENABLE_PIN    , OUTPUT);
  pinMode(Z_MIN_PIN   ,INPUT_PULLUP);
  pinMode(Z_MAX_PIN   ,INPUT_PULLUP);
  
  pinMode(E_STEP_PIN  , OUTPUT);
  pinMode(E_DIR_PIN    , OUTPUT);
  pinMode(E_ENABLE_PIN    , OUTPUT);
  
  pinMode(Q_STEP_PIN  , OUTPUT);
  pinMode(Q_DIR_PIN    , OUTPUT);
  pinMode(Q_ENABLE_PIN    , OUTPUT);


//Enable all Motors  
   digitalWrite(X_ENABLE_PIN    , LOW);
   digitalWrite(Y_ENABLE_PIN    , LOW);
   digitalWrite(Z_ENABLE_PIN    , LOW);
   digitalWrite(E_ENABLE_PIN    , LOW);
   digitalWrite(Q_ENABLE_PIN    , LOW);

//Begin receiving values
   // Wire.begin(9);
// Attach a function to trigger when something is received.
  //  Wire.onReceive(receiveEvent);
//while (!mySerial)
//{
  //nothing and wait for connection
//}
   
//Home the Motor
   while (digitalRead(X_MIN_PIN)) {  // Do this until the switch is activated 
    Serial.print("+")  ;
    digitalWrite(X_DIR_PIN, HIGH);      // (HIGH = anti-clockwise / LOW = clockwise)
    digitalWrite(X_STEP_PIN , HIGH);
    delayMicroseconds(MAX_MOTOR_SPEED);                      // Delay to slow down speed of Stepper
    digitalWrite(X_STEP_PIN, LOW);
    delayMicroseconds(MAX_MOTOR_SPEED);
      
}

  while (!digitalRead(X_MIN_PIN)) { // Do this until the switch is not activated
    Serial.print("-")  ;
    digitalWrite(X_DIR_PIN, LOW); 
    digitalWrite(X_STEP_PIN, HIGH);
    delayMicroseconds(MAX_MOTOR_SPEED);                    // More delay to slow even more while moving away from switch
    digitalWrite(X_STEP_PIN, LOW);
    delayMicroseconds(MAX_MOTOR_SPEED);
    //stepsX++ ;
  }
    Serial.print(stepsX) ;

}




void loop () {//if we have serial data
  if (Serial2.available() >0) {
    // read one more data into the buffer
    dataBuffer[dataBufferIndex] = Serial2.read();
    // if no message start yet
    if (!messageStarted) {
      boolean dataBufferIndexIndrease = true;
      // if message is at lesat 2 byte long
      if (dataBufferIndex > 1) {
        if (dataBuffer[dataBufferIndex - 1] == 253 && dataBuffer[dataBufferIndex] == 255) {
          // we set the flag
          messageStarted = true;
          // reset the index
          dataBufferIndex = 0;
          dataBufferIndexIndrease = false;
        } //end if
      } //end if (dataBufferIndex > 1)

      // check if we need to increase the index
      if (dataBufferIndexIndrease)
        dataBufferIndex++;
      //  Serial.print(dataBufferIndex);
    }
    // if message is started
    else
    {
      // if we got to the last byte of the message
      if (dataBufferIndex == 6)
      {
        // check the checksum
        if ((byte) (dataBuffer[0] +  dataBuffer[1] +  dataBuffer[2] +  dataBuffer[3] +  dataBuffer[4]) == dataBuffer[5]) {
 
         int MOTORX = dataBuffer[0] ;
         MOTORX = map(MOTORX, 0, 255, 0, stepsX);
         byte MOTORY = dataBuffer[1] ;
         byte MOTORZ = dataBuffer[2] ;
         byte MOTORE = dataBuffer[3] ;
         byte MOTORQ = dataBuffer[4] ;
         
          Serial.print("MOTORX - "); // for debugging
          Serial.print(MOTORX);
          Serial.print("posi - "); // to see if it follows mortorx
          Serial.print(posi);
          
          while (posi < MOTORX){
            for (int i=posi; i < MOTORX ; i ++){
              digitalWrite(X_DIR_PIN, HIGH);      // (HIGH = anti-clockwise / LOW = clockwise)
              digitalWrite(X_STEP_PIN , HIGH);
              delayMicroseconds(MAX_MOTOR_SPEED);                      // Delay to slow down speed of Stepper
              digitalWrite(X_STEP_PIN, LOW);
              delayMicroseconds(MAX_MOTOR_SPEED);
              posi = posi + 1;
              } 
              }
          while (posi > MOTORX){
            for (int i=posi; i > MOTORX ; i --){
              digitalWrite(X_DIR_PIN, LOW);      // (HIGH = anti-clockwise / LOW = clockwise)
              digitalWrite(X_STEP_PIN , HIGH);
              delayMicroseconds(MAX_MOTOR_SPEED);                      // Delay to slow down speed of Stepper
              digitalWrite(X_STEP_PIN, LOW);
              delayMicroseconds(MAX_MOTOR_SPEED);
              posi = posi - 1;
              }
              }

         
        } else {
          Serial.println("Error reading data - fail on check sum");
        } //end if

        // reset the flag
        messageStarted = false;
      } //end if (dataBufferIndex == 3)

      // increase the buffer index
      dataBufferIndex++;
    } //end if (!messageStarted)
  } //end if Serial1.available()
}

Now the steppers are controllable by the DMX input. When i pull the fader up and down it also like buffers this and lets the motor ride up and down afterwards as fast as the motor can. That is allright for me but i dont understand why it does.