Dear Hisham,
Yes my other equipment have no problem handling 4ms (or less). I was thinking of using the Stimtracker as a “relay” to instantaneously send the signal to the other devices.
Thus I only need to send a 5V square-wave signal with a 4 ms period to the TTL input on Stimtracker trough an Ethernet cable (RJ45). I have an Arduino MEGA 2560 and an Ethernet Shield W5100 to plug the Ethernet cable.
I am not very familiar with Arduino and sending signal through Ethernet, but can I send this square signal through UDP (User Diagram Protocol)? Or should I send it using TCP/IP?
I have written this code so far:
// Arduino is the client, it will send requests to the Stimtracker (the server)
#include <Ethernet.h> // Load Ethernet library: work with Arduino Ethernet Shield W5100
#include <EthernetUdp.h> // Load UDP (User Datagram Protocol) library: to send and receive packets over UDP
//unlike TCP, it is connectionless, meaning that it doesn’t require any waiting for acknowledgement of a successful data transmission
// potential problem: failed transmissions will go undetected --> “fire and forget” protocol
#include <SPI.h> // Load the SPI library: to communicate with Serial Peripheral Interface (synchronous serial data protocol),
// with the Arduino as the master device
// might need to change the mac and the ip address, I’m not even sure we really need it…
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE}; // Assign a mac address: physical address of the Arduino
IPAddress ip(10, 1, 15, 243); // Assign an IP address, might need modification
unsigned int localPort = 5000; // Assign a Port to talk over
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // array to send data,
// the dimension is the maximum size of odd packet that I can send
String datReq; // easier to work with strings, but don’t know how to send string through UDP, so using the array of characters
// string for our data
int packetSize; // Size of the packet
EthernetUDP Udp; // object to interact with the UDP functions
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); // Turn on Serial Port
Ethernet.begin(mac, ip); // Initialize Ethernet
Udp.begin(localPort); // Initialize Udp
delay(1500); //delay to make sure everything has time to get initialized before we move on
}
void loop() {
// put your main code here, to run repeatedly:
int state = 0;
// By default we start at 0V
while(1){
if(state ==0){
// everytime we are at state=0, it means that the PIN sends 0V or is at LOW
// digitalWrite(PIN, LOW); // that was for sending through PIN
Udp.beginPacket(Udp,remoteIP(),Udp.remotePort()); //Initialize packet send
Udp.print("I am sending a string that says 0V, but I want to send a value"); // send string to Stimtracker
Udp.endPacket(); // packet has been sent
// then we change the state to 1
state = 1;
}
else {
// everytime we are at state=1, it means that the PIN sends 5V or is at HIGH
// digitalWrite(PIN, HIGH); // that was for sending through PIN
Udp.beginPacket(Udp, remoteIP(), Udp.remotePort()); //Initialize packet send
Udp.print("I am sending a string that says 5V, but I want to send a value"); // send string to Stimtracker
Udp.endPacket(); // packet has been sent
// then we change back the state to 0
state = 0;
}
memset(packetBuffer, 0, UDP_TX_PACKET_MAX_SIZE); // to clear the array
delay(4);
// The delay corresponds to the period of the square-wave, meaning time at 0v + time at 5V
// For controlling the high-speed camera, this period is 4 ms
}
As I said, I am not very familiar with sending signal as a voltage value through an Ethernet cable. If instead of:
Udp.print(“I am sending a string that says 5V, but I want to send a value”);
I write:
Udp.print(“5”);
Will Stimtracker detect it as a valid input?
Thank you for your answer,
If you have any suggestions, please let me know.