Hello
This seems to do the filtering fine for now at least in the tests i could send a maximum of 734 values at same time from the pc with reasonable speed ,i changed the maximum size in line #define UDP_TX_PACKET_MAX_SIZE 3072 in the EthernetUdp.h
#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 2, 12);
unsigned int localPort = 10000; // local port to listen on
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
//////////////
void setup() {
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
//Serial.begin(115200);
}
void loop()
{
int packetSize = Udp.parsePacket();
if (packetSize > 0 )
{
//if (packetSize > 0 && packetSize==24 )
uint8_t input[packetSize];
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
if( packetBuffer[0]=='<' && packetBuffer[packetSize-1]=='>'){
for (int i = 0,idx=0; i < packetSize; i+=2,idx++)
{
char buf[3];
memcpy(buf,&packetBuffer[i],2);
buf[2]=0;
input[idx] = atoi(buf);
// Serial.print(packetSize);
// Serial.print(" ");
// Serial.print(packetBuffer[0]);
// Serial.print(" ");
// Serial.print(packetBuffer);
// Serial.print(" ");
// Serial.print(input[0]);
// Serial.println();
analogWrite(5,(input[1]));
analogWrite(6,(input[2]));
}
}
}
}
what is this maximum of 734 values i could send related to ? ,it,s Arduino Mega memory that runs out of mem or to the udp protocol will it help sending in 2 difference instances of udp , or other parameter i could change ?
i would need to send 512 X 5 + header and ending byte will Mega cope with it ?
i still have 2 main problems in the code
1-one is the heading and ending < >
i send from the computer <<23312310>> so i would like to get rid of the heading and ending bytes from the calculation so index 0 will be value = 23 and index 3 = 10 in this : <<23312310>> how can i do that ?
2-i have to send decimal values from the computer in the range of (10-99) for this to work. somehow it does not understand the encoding when i send ascii , right now i use utf-8 any ideas ?
tips to optimized the code very welcome.
cheers