Hi...
I am having a strange problem.
I have a Arduino connected to 2 DC motors and a laptop via USB.
The laptop has a Gamepad controller connected to another USB and we are able to operate the DC motors using the gamepad.
Stage 1: Setup as follows which is currently working:
Gamepad <--> PC <--> USB <---> Arduino Mega<--> DC Motors
Stage 2: Now I want it to be ported on Ethernet and make it work over Ethernet.
Gamepad <--> PC <--> Ethernet <---> Ethernet Shield on Arduino <- -> Arduino Mega<--> DC Motors
I am just unable to make the Stage 1 code which is working fine port to Stage 2.
Following is Stage 1 Code:
//---------------------------------------------------------------------------
//------------------------Output port-pin assignment------------------------
// Pin assignments for motor controller section Connector C1
// GND_M1dir-2_M1pwm-3_M2dir-4_M2pwm-5_M3dir-6_M3pwm-7_M4dir-8_M4pwm-9_+5V
//
// Pin details for digital input's Connector C5:
// GND_A15_A14_A13_A12_A11_A10_A9_A8_+5v (Analog pins are to be set as digital input)
//
// Pin details for analog input's Connector C6 (The connector is on patch-board of Ethernet shield ):
// GND_A0_A1_A2_A3_A4
//-----------------------------------------------------------------------------
char command ='S';
void setup()
{
// initialize digital output pin Connector C1
pinMode(2,OUTPUT);pinMode(3,OUTPUT);pinMode(4,OUTPUT);pinMode(5,OUTPUT);
pinMode(6,OUTPUT);pinMode(7,OUTPUT);pinMode(8,OUTPUT);pinMode(9,OUTPUT);
// initialize digital output pin Connector C2
pinMode(23,OUTPUT);pinMode(25,OUTPUT);pinMode(27,OUTPUT);pinMode(29,OUTPUT);
pinMode(31,OUTPUT);pinMode(33,OUTPUT);pinMode(35,OUTPUT);pinMode(37,OUTPUT);
// initialize A8-A15 as digital input (Connector C5)
pinMode(A8,INPUT);pinMode(A9,INPUT);pinMode(A10,INPUT);pinMode(A11,INPUT);
pinMode(A12,INPUT);pinMode(A13,INPUT);pinMode(A14,INPUT);pinMode(A15,INPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0) {
command = Serial.read();
if (command == 'F')
{
//motor1 motor2 clockwise
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
}
else if (command == 'R')
{
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
else if (command == 'T')
{
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
}
else if (command == 'U')
{
digitalWrite(2, LOW);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
}
else if (command == 'V')
{
digitalWrite(23, HIGH); // Sol-1 ON
}
else if(command == 'W')
{
digitalWrite(25, HIGH);
}
else if(command == 'Y')
{
digitalWrite(27, HIGH);
}
else if(command == 'Z')
{
digitalWrite(29, HIGH);
}
else if(command == 'A')
{
digitalWrite(31, HIGH);
}
else if(command == 'B')
{
digitalWrite(33, HIGH);
}
else if(command == 'C')
{
digitalWrite(35, HIGH);
}
else if(command == 'D')
{
digitalWrite(37, HIGH);
}
else
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(23, LOW);
digitalWrite(25, LOW);
digitalWrite(27, LOW);
digitalWrite(29, LOW);
digitalWrite(31, LOW);
digitalWrite(33, LOW);
digitalWrite(35, LOW);
digitalWrite(37, LOW);
}
}
}
request help from the community on how can this code be modified to make it work over ethernet.
thanking everyone for their time!.