Hello,
I am trying to put together a data acquisition system and am fairly new to Arduino's/coding. I'm sending 10-1000 Hz data via ethernet UDP to Matlab on my computer and plotting realtime. However, each packet has about a 6ms gap in data (please see images plotted in Matlab).
Have been googling for days without luck...
Here are the details and code:
- See images for plot details
- Board: DFRobot W5500 Ethernet with POE Control Board (equivalent to Leonardo Ethernet)
- Tried changing SPI_CSR_DLYBCT(1) to SPI_CSR_DLYBCT(0) in SPI.h and SPI.cpp
- Tried w5500.setRetransmissionCount(1); and w5500.setRetransmissionTime(1000);
Any tips or tricks would be greatly appreciated. Thanks!
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet2.h>
#include <EthernetUdp2.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
#define SS 10U //D10 ---- SS
#define RST 11U //D11 -----Reset
// in setup() after Ethernet.begin(), call this function.
int tempRead16;
typedef struct {
uint16_t timestamp; //make double
uint8_t temp;
uint8_t weight;
uint16_t pres[50];
uint16_t thrust[50];
uint16_t endtime;
uint16_t sendPacketTime;
} Packet;
//Include potentiometer inputs
int potPin = 1;
int tempPin = 2;
// 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 local(192, 168, 1, 177);
IPAddress remote(192, 168, 1, 5);
Packet pkt;
unsigned int port = 8888; // local port to listen on
const int sampleCount = 50;
const int sensorCount = 2;
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
pinMode(SS, OUTPUT);
pinMode(RST, OUTPUT);
digitalWrite(SS, LOW);
digitalWrite(RST, HIGH); //Reset
delay(200);
digitalWrite(RST, LOW);
delay(200);
digitalWrite(RST, HIGH);
delay(200); //Wait W5500
delay(1000);
// start the Ethernet and UDP:
Ethernet.begin(mac, local);
Udp.begin(port);
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
}
void loop() {
pkt.timestamp = millis();
pkt.temp = analogRead(tempPin) / 4; // Converts to 8 bytes
pkt.weight = analogRead(potPin) / 4; // Converts to 8 bytes
for (int i = 0; i < sampleCount; i++) {
pkt.pres[i] = analogRead(potPin);
pkt.thrust[i] = analogRead(potPin) / 2;
delayMicroseconds(650);
}
pkt.endtime = millis();
Udp.beginPacket(remote, port);
Udp.write((char*)&pkt, sizeof(pkt));
pkt.sendPacketTime = millis() - pkt.endtime;
Udp.endPacket();
}