This tool is capable of measuring the System Latency, excluding mouse.(PC+Monitor+USB Port Latency)
DIY ARDUINO LATENCY TOOL
This is a Prototype, which contains the most important parts. Provisionally, I put tape around the sensor to shield it against incoming ambient light.
Additionally I will built 2 boxes, one for the arduino and one for the light sensor with a mount to fixate the sensor on the monitor.
But at the moment, cosmetics are secondary.
All in all, it cost me only ~40 Dollar to built it. This is really affordable, compared to other latency tools, which cost well over 100 dollar.
Here is a List of the Parts:
- Arduino Micro
- LM393 Light Sensor
- Toggle Switch
- Breadboard
- Male to Female Jumper Wires
- Male to Male Jumper Wires
- Micro USB Cable 1m
- Tape (to shield the sensor against incoming Light or for fixating Wires)
CODE
This is the more complicated part of the project. Luckily I found a guy that made the same latency tool and provided the code for it.
You need to upload and compile the code in the Arduino IDE. To display the results, open the Serial Monitor inside IDE.
Code:
Code: Select all
// Mouse - Version: Latest
#include <Mouse.h>
// light sensor pin
const byte lightSensorPin = 11;
// the number of the pushbutton pin
const byte buttonPin = 2;
// used in tests to get time when test starts
unsigned long startTime;
// used in tests to get time when sensor responded to pixel changes
unsigned long endTime;
// variable for reading the pushbutton state
bool buttonState = 0;
// variable for reading the light sensor state
bool newLightSensorState = 0;
// variable for storing previous state of light sensor
bool oldLightSensorState = 0;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize mouse
Mouse.begin();
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
// initialize light sensor pin as an input
pinMode(lightSensorPin, INPUT);
// initialize the LED pin as an output:
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
// read the state of the pushbutton value:
int buttonState = digitalRead(buttonPin);
// check if the button is pressed. If it is, the buttonState is LOW:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(LED_BUILTIN, HIGH);
oldLightSensorState = newLightSensorState; // store previous state of light sensor
newLightSensorState = digitalRead(lightSensorPin); // get new state of light sensor
//Serial.println(newLightSensorState);
Mouse.press();
startTime = micros();
delay(0);
// wait until sensor's state is changed
while(newLightSensorState == 1 && buttonState == LOW)
{
oldLightSensorState = newLightSensorState; // store previous state of light sensor
newLightSensorState = digitalRead(lightSensorPin); // get new state of light sensor
buttonState = digitalRead(buttonPin);
delay(0);
}
endTime = micros();
Mouse.release();
float responseTime = (endTime - startTime)/1000.0;
Serial.print("startTime: ");
Serial.print(startTime);
Serial.print(", ");
Serial.print("endTime: ");
Serial.print(endTime);
Serial.print(", ");
Serial.print("responseTime: ");
Serial.println(responseTime);
delay(random(400, 600));
} else {
// turn LED off:
digitalWrite(LED_BUILTIN, LOW);
}
}
1. Arduino sends a emulated mouse click every 400-600ms to the PC
2. The mouse click will trigger a light change on the monitor
3. The lightsensor will detect the light change
4. Arduino calculates the delay between the emulated mouse click and the light change on the monitor.
I already made some tests. I used a simple HTML Website, which turns from white to black when a arduino mouse click get triggered.
http://plnkr.co/edit/Q8CzgCo451XKKFbdmJAH?p=preview
I calculated the delay of 100 measurements
Results:
Maximum: 44.05 ms
Minimum : 36.22 ms
Average : 39.98 ms
I think these values are realistic, given then fact I have a low end PC (GTX1070, R5 2600, 144hz Monitor) and Chrome Hardware Acceleration turned OFF.
As a little experimental test, I repeated my measurment with Chrome Hardware Acceleration turned ON.
Results:
Maximum: 41.95 ms
Minimum : 28.21 ms
Average : 33.16 ms
Chrome Hardware Acceleration ON gave me around 7ms Latency reduction compared to disabling it.
I would say this behavior is expected. Of course the reduction only applies to web browsing, not for games! As clarification, this is just a test, of how well the tool can detect changes, that got applied to the system.
Of course I need a Validation Method.I will repeat the test with a 240fps camera and see if I get similar results, updates will get posted in this thread.
Can't wait to test bunch of settings and tweaks. Especially Optimized vs Unoptomized windows.
If anyone have questions or if someone can tell me what I can improve, please write it in here!