Udp Read Speed Issue

Hello
i need help regarding Udp.Read
Here is Sample Code.

initTime = micros();
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);  
finalTime= micros();     
Serial.println(finalTime-initTime);

these are the library

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>

the issue is Udp.Read need minimum 230 Micro Second for one Character Read.
for my Project this Time is too much.
like the other command digitalWrite need 12 Micro Second.

please share your experience that how i can make Ethernet communication that i can reduce
the Data Reading time in Arduino.
i can't afford the more then 100 Microsecond for at least 4 to 6 character.

if is there any other library then please share the link.

i already try the Telnet but he also need minimum 230 MicroSecond for 1 character to Read.

Thank You in Advance

I don't have an answer to your question, but I'm curious to know what type of embedded application requires thousands of packets per second.

the main goal is to control the 3 motor and 3 switch at the same time.
means they should all work independently.

Lets Make Simple just 1 motor and 1 LED

in loop i am not using delay function. i am using the Micro() function technique.
so Motor need plus signal After 700 Micro Second.
in single loop execution, i move the motor 1 step.
After moving the Motor 1 Step then i need to do some Calculation but
these calculation are not problem because they took only 4 us.

in loop this (Udp.Read ) is very exapnsive for me because he took 400 us.

he need to check every time if there is some data from computer.

i am sending command "StartMotor" ,"StopMotor" and also LEDON

so when the motor is running then during this time may be i want to Turn ON the
LED or something Like that.

please also check my code and i hope you will understand my goal.

void loop() 
          {
          
          int packetSize = Udp.parsePacket(); // Get the Packet Size  .... He took 60 Micro Second
                  
          if(packetSize)                      // If the Packet Exist ....He took 4 Micro Second 
          
                       {
                          
                      for(int i=0;i<UDP_TX_PACKET_MAX_SIZE;i++) packetBuffer[i] = 0;  // He took 12 us
                      initTime = micros();
                      Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);  
                      finalTime= micros();     
                      Serial.println(finalTime-initTime); 
                      

                      UserCommand = packetBuffer ;
                       if (UserCommand == "StartMotor")     // Here i am updating the Global Variable
                       {MotorRun =true;}
                       else if (UserCommand == "StopMotor")
                       {MotorRun =false;}
                       else if (UserCommand == "LedOn")
                       {LedOn = true;}
                       else if (UserCommand == "LedOf")
                       {LedOn = false;}
                      finalTime= micros();     
                      Serial.println(finalTime-initTime); 
                     }
                   
            if (MotorRun == true)
            {
            if (M1.IsForwardDone == false )
                 {M1.IsReverseDone = true;                  
                  M1.Start(1000,1);}    // this is function who run 1 step every time ultil 1000 is reached
                
              if (M1.IsReverseDone == false)
                 {M1.Start(-1000,1);
                  } 
            }
                            
              
              
            if (LedOn == true)
            {PORTB |= _BV(PB7);}  // He took 4 Micro Second 
            else
            {PORTB &= ~_BV(PB7);}
                      
          }

Assuming UserCommand is defined as String, thisUserCommand = packetBuffer ;could take longer than expected or even just fail.

How about checking checking the content of the packetBuffer without string copy?

Are you missing messages from the computer because of the time delay.
In other words, is the computer sensing messages faster than you can receive them?
If so, you need to implement some kind of flow control where your Arduino tells the computer that you are ready to receive another message.

Whandall:
Assuming UserCommand is defined as String, thisUserCommand = packetBuffer ;could take longer than expected or even just fail.

How about checking checking the content of the packetBuffer without string copy?

before the PacketBuffer i am already checking with the packetSize
if there is some packet size then i will go further

atifbuitms:
in loop i am not using delay function. i am using the Micro() function technique.
so Motor need plus signal After 700 Micro Second.
in single loop execution, i move the motor 1 step.
After moving the Motor 1 Step then i need to do some Calculation but
these calculation are not problem because they took only 4 us.

You cannot expect to get real time step by step control of a stepper motor using any form of communication unless the step rate is very slow.

You should plan to send a block of data for many steps to the Arduino which the Arduino can then process in parallel with the arrival of the next block of data.

...R

atifbuitms:
before the PacketBuffer i am already checking with the packetSize
if there is some packet size then i will go further

You do not understand me. Its the String class that asks for trouble.

To copy the buffer, you will have to allocate a String of the same size + some bytes.

That may not be available in one piece due to fragmentation and can just fail.
malloc will have to traverse the whole freelist to find out that it can't succeed.

thank you for guide
Now i found really nice Module Auto Driver

https://learn.sparkfun.com/tutorials/getting-started-with-the-autodriver

this Auto Driver is using the L6470.
but this is only upto 3A.

Now the Current is problem
if any one know About Same AutoDriver function Device with Large Amount of Current like 5A.

i have Nema23XL so this motor need 4,2 Amp.

There are plenty of stepper drivers that can provide 5amps or more. The only problem is their price :slight_smile: Some brands to search for include Gecko and Leadshine.

Most of these drivers just need step and direction connections from the Arduino. I think the AutoDriver is more complex to operate.

...R
Stepper Motor Basics