Arduino to unity3d & Ipad

hello all,

my project is as follows.. we have a unity3d fps app. the app has a tcpclient which connects to arduino with a wifishield.. the arduino itself is wired to a nerf gun, so when the user fires the nerf gun..the gun inside the app fires too. when i try the same app on a mac using serial cable the result is immediate. no lag between the user firing and the app responding. but when using wifi for connectivity theres a 2 sec lag..which for a fps is terrible.

is this a wifi shield related problem? can we remove the lag using some wifi firmware? should i simply use the redpqrk serial cable? should i use a different wifi shield? how about the wifly shield? or should i use the ethernet shield with some portable wireless router?

plz give your suggestions and share if you have done something similar. regards danneskjold

is this a wifi shield related problem?

Maybe. Or a coding issue. My bet would be a coding issue.

can we remove the lag using some wifi firmware?

Doesn't seem likely.

should i simply use the redpqrk serial cable?

Does that work for your application?

should i use a different wifi shield? how about the wifly shield?

What about it? What wifi shield are you using now?

hey paul,

thnx for replying... i dont think it would be a coding issue.. all im sending is a client.print on a pushbutton. i am able to use the serial.print and get immediate results when trying the same app on my i belive that the redpark would work..plz corr3ct me if im wrong. im using this wifi shield it cannot act as a ap or client. so the communication goes from arduino to router to app on ipad.

maybbe the eternet with the tplink router might speed things up regards danneskjold

i dont think it would be a coding issue.

I'd like to have a nickel for everyone who ever posted here saying that there code was perfect, when coding changes were needed to solve their problem. But, I don't have any problem with your not posting code.

dear paul, i completely agree with your thoughts... i have not said that my code is perfect.... i havent posted the code as im not on my computer.. ill do that first thing in the morning.. if anything written in post has misled you in thinking so..then im sorry and will try to make my posts more descriptive...

thnx for replying..plz have a look tomorrow and help me fix the code..

regards danneskjold

dear paul,

here is the code im using to send parameters to unity … in unity app theres a tcpclient which connects to arduino and recieves these parameters and executes corresponding events.
for ex… eq 1 fire eq 2 reload etc
plz have a look and help me correct this.



#include <SPI.h>
#include <WiFi.h>

char ssid = “WLL-1”; // your network SSID (name)
char pass = “97531”; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS;
const int shootpin = 2;
const int reloadpin = 9;
const int switchpin = 8;
const int zoompin = 5;
int led = 13;
WiFiServer server(23);

boolean alreadyConnected = false; // whether or not the client was connected previously

void setup() {
//Initialize serial and wait for port to open:





pinMode(led, OUTPUT);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only

// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println(“WiFi shield not present”);
// don’t continue:

// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
// start the server:
// you’re connected now, so print out the status:

void loop()
WiFiClient client = server.available();
if (client)
if (!alreadyConnected)
Serial.println(“We have a new client”);
client.println(“Hello, client!”);
alreadyConnected = true;
else if (digitalRead(shootpin) == LOW)
else if (digitalRead(switchpin) == LOW)
else if (digitalRead(reloadpin) == LOW)
else if (digitalRead(zoompin) == LOW)

void printWifiStatus() {
// print the SSID of the network you’re attached to:
Serial.print("SSID: ");
digitalWrite(led, HIGH);
// print your WiFi shield’s IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print(“signal strength (RSSI):”);
Serial.println(" dBm");


On every pass through loop, if no switch is pressed, send a carriage return and line feed. Why? You will be sending a lot of these.


"My program takes too long" and this call are NOT compatible.

hi paul,

if i dont send a blank print if no switch is pressed.. the shield disconnects after sometime. .like 10 secs. ill remove the delay and try..hopefully that should fix things i have tried this on 3 setups.. 7 machine with perfect 2.a mac mini over wifi. .. lags 3. on android note/ipad. ..lags almost the same as the mac mini.

regards danneskjold

if i dont send a blank print if no switch is pressed… the shield disconnects after sometime. .like 10 secs.

If you need to send something at regular intervals to keep the connection alive (seems strange to me, but may be the case) then I suggest you do it on a timed basis e.g. once per second rather than on every time through loop(). Look at the ‘blink without delay’ example to see how to do things on a timed basis.

hey peter,

thnx... just checking that out regards danneskjold

hey paul/peter,

removed the delay from the previous code.. also removed the empty client.print. still no luck..the same lag persists..

now what do i need to check??? suggestions plz..

regards danneskjold