Converting to serial communication instead of Ethernet

Hello All,

Quick question for the forums. Have help great help from everyone getting to a working code for our project. It currently runs over ethernet between two arduinos. This is all great. However, have a new project that it has to go over serial instead (we have the luxury of a serial bridge on this project) so instead of ethernet, its just serial Rx/Tx either end (plus the ground reference of course).

Anyway, the below codes (heavily striped except for some basics to get across what we are currently doing) are working as intended, and using ethernet protocol for the network modules.

My question is, is it as simple as opeing a software serial, getting rid of all the thernet references, and where we write the array to client currently, we just write it to serial. Then the other end is reading from serial?

I have done a bit of research, things link sync issues, or data being out of order, or the data not being in packets are all things i have noticed on various threads.

So is it not as simple as i think to go over to serial comms to send and receive this array of values. Any guidance would be great. Thank you

Ground

#include <UIPEthernet.h>
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x06,0x05};
EthernetClient client;

signed long next;
int flag=0 , flag1=0;


int Arry_to_send[8]={0};

int focusPin = A3;    
int zoomPin = A2;    
int tiltPin = A0;    
int panPin = A1;    
int focusspeedPin = A8;    
int zoomspeedPin = A7;    
int tiltspeedPin = A5;    
int panspeedPin = A6;  
int pancompPin = A4;  

int focusVal = 0;    
int zoomVal = 0;    
int tiltVal = 0;    
int panVal = 0;    
int focusspeedVal = 0;    
int zoomspeedVal = 0;    
int tiltspeedVal = 0;    
int panspeedVal = 0;
int pancompVal = 0;    

void setup() {

  
  Serial.begin(9600);

    IPAddress myIP(192,168,1,8); 
    Ethernet.begin(mac,myIP);
}

void loop() 
{

  
  if (((signed long)(millis() - next)) > 0)
    {
      next = millis() + 5000;
     Serial.println("Client Try connect");
     if (client.connect(IPAddress(192,168,1,9),1000))
        {
          Serial.println("Client connected ");
          while(1)
          {
            if (client.connect(IPAddress(192,168,1,9),1000))
        {


focusVal = analogRead(focusPin);    
zoomVal = analogRead(zoomPin);    
tiltVal = analogRead(tiltPin);    
panVal = analogRead(panPin);     
zoomspeedVal = analogRead(zoomspeedPin); 
focusspeedVal = analogRead(focusspeedPin);   
tiltspeedVal = analogRead(tiltspeedPin);    
panspeedVal = analogRead(panspeedPin);  
pancompVal = analogRead(pancompPin);  

Arry_to_send[0]=focusVal;
Arry_to_send[1]=zoomVal;
Arry_to_send[2]=tiltVal;
Arry_to_send[3]=panVal;
Arry_to_send[4]=focusspeedVal;
Arry_to_send[5]=zoomspeedVal;
Arry_to_send[6]=tiltspeedVal;
Arry_to_send[7]=panspeedVal;
Arry_to_send[8]=pancompVal;

for( int x=0 ; x<9 ;x++)
 {
  client.print(Arry_to_send[x]);
  client.print("\n");
 
          }
         }
        }
       }
       }
    UIPEthernet.maintain();
}

Air

#include <UIPEthernet.h>
EthernetServer server = EthernetServer(1000);
uint8_t mac[6] = {0x00,0x01,0x02,0x03,0x04,0x05};
int array_index=0;


int flag=0;
byte intBuffer[12];
String intData = "";
int delimiter = (int) '\n';
int old=1;
int i=0;

#define CHANNEL_NUMBER 12  
#define CHANNEL_DEFAULT_VALUE 1500  
#define FRAME_LENGTH 22500  
#define PULSE_LENGTH 300  
#define onState 1  
#define sigPin 32  

int ppm[CHANNEL_NUMBER];
int received_Array[8]={0};


void setup() {

  for(int i=0; i<CHANNEL_NUMBER; i++){

      ppm[i]= CHANNEL_DEFAULT_VALUE;

  }

  pinMode(sigPin, OUTPUT);
  digitalWrite(sigPin, !onState);  

  cli();
  TCCR1A = 0; 
  TCCR1B = 0;
  OCR1A = 100;  
  TCCR1B |= (1 << WGM12);  
  TCCR1B |= (1 << CS11);  
  TIMSK1 |= (1 << OCIE1A); 
  sei();

  Serial.begin(9600); 

    IPAddress myIP(192,168,1,9);
    Ethernet.begin(mac,myIP);
    
    server.begin();

}

void loop()

{

 if (EthernetClient client = server.available())
    {
      
      while((client.available()) > 0)
       {
          flag=1;
          char ch= client.read();
           if (ch == -1) 
           {
        
           }
          else if (ch == delimiter) 
           {
             break;
           }
           
           else 
            {
               intData += (char) ch;
            }
         }
     
    int intLength = intData.length() + 1;
    intData.toCharArray(intBuffer, intLength);
    intData = "";
    int i = atoi(intBuffer);
    received_Array[array_index]=i;
    array_index++;
    
    if(array_index >=8)
    {
         array_index=0;

focusVal= received_Array[0];
zoomVal= received_Array[1];
tiltVal= received_Array[2];
panVal= received_Array[3];
focusspeedVal= received_Array[4];
zoomspeedVal= received_Array[5];
tiltspeedVal= received_Array[6];
panspeedVal= received_Array[7];
pancompVal= received_Array[8];


     client.stop();
     }

     }

ISR(TIMER1_COMPA_vect){  

  static boolean state = true;

  TCNT1 = 0;

  if (state) {  //start pulse

    digitalWrite(sigPin, onState);

    OCR1A = PULSE_LENGTH * 2;

    state = false;

  } else{  

    static byte cur_chan_numb;

    static unsigned int calc_rest;

  
    digitalWrite(sigPin, !onState);

    state = true;


    if(cur_chan_numb >= CHANNEL_NUMBER){

      cur_chan_numb = 0;

      calc_rest = calc_rest + PULSE_LENGTH;// 

      OCR1A = (FRAME_LENGTH - calc_rest) * 2;

      calc_rest = 0;

    }

    else{

      OCR1A = (ppm[cur_chan_numb] - PULSE_LENGTH) * 2;

      calc_rest = calc_rest + ppm[cur_chan_numb];

      cur_chan_numb++;

    }     

  }

}

https://forum.arduino.cc/index.php?topic=396450.0

Thanks for the link. Will have a look through it properly. Had come across it before, however couldn't see it addressing direct links between Arduinos.

Is there going to be any noticeable differences running it directly on serial rather than ethernet. Lag etc?

Serial is relatevely slow but it will make no practical difference for your project.