Help with Ethernet and Wifi

Description of the Situation:

Hello, I'm doing a car with Arduino, which is controlled by a Analog Thumbstick attached to another Arduino. I already have the code to read the analog values and send a character to the car, because previously it used to be by Bluetooth. Now, we are asked to do it by Wifi and Ethernet. The Thumbsticks will be attached to the Arduino with the Ethernet Shield and this one, connected directly to a Router. This Router creates a Wifi network. The car is over an Arduino Uno with a Wifi Wizfi210 Shield. I already made the Wifi shield connect to the network created by the Router, so the 2 Arduinos are in the same network and always with a unique IP setted by me on the Router's config.

Problem:

What I want is the code for each Arduino to communicate between them. On the Ethernet, just send a Char to the Wifi... And in the Wifi, read the Ethernet's Char. Is only that, but I have almost no knowledge about creating servers or clients.

Thanks.

The Ethernet Shield and the wifi use the internet protocols. Just sending a character without protocol is not possible.
The TCP/IP is a common protocol for the internet, like webpages and so.
For short data packages the UDP protocol can be used.

The UDP functions are on the lower-right on the Ethernet reference page : Ethernet - Arduino Reference

So, it would be the Joystick sends an UDPpacket via Ethernet and the Car reads it via Wifi. They are different Libraries and I only want that, just send from the Ethernet and read it from the Car, not reply anything... But I don't know how :stuck_out_tongue: I would be grateful if someone could give me an example code of Ethernet's and Wifi's because I don't understand the ones from the Reference Page.

This is an example to send a byte with UDP : Ethernet - Arduino Reference
The Arduino wifi shield library also supports UDP : WiFi - Arduino Reference

Is your Wizfi210 not officially supported by Arduino ? Which library do you use for it ? Many Etherent/wifi libraries have UDP implemented.

Peter_n:
Is your Wizfi210 not officially supported by Arduino ? Which library do you use for it ? Many Etherent/wifi libraries have UDP implemented.

Yes it is, and it supports the Wifi.h library.
I tried with this code for the Ethernet one:

#include <SPI.h>        
#include <Ethernet.h>
#include <EthernetUdp.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
  byte remoteIP[]={192, 168, 1, 101};
  unsigned int remotePort=8888;
  char rxChar;
  int val, val2;
  const int potpin=0;
  const int potpin2=1;


unsigned int localPort = 8888;      // local port to listen on

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac);
  Udp.begin(localPort);

}

void loop() {

  val = analogRead(potpin);
  val2= analogRead(potpin2);
  Serial.println("val1=");
  Serial.println(val);
  Serial.println("val2=");
  Serial.println(val2);
  if(val>650)
{ 
    if(val2>650)
    {
      rxChar='I';
      Serial.println('I');
    }
    else if(val2<350)
    {
      rxChar='D';
      Serial.println('D');
    }
    else
    {
      rxChar='F';
      Serial.println('F');
    }
}
  else if (val<350)
{
    if(val2>650)
    {
      rxChar='J';
      Serial.println('J');
    }
    else if(val2<350)
    {
      rxChar='K';
      Serial.println('K');
    }
    else
    {
      rxChar='B';
      Serial.println('B');
    }
}
  else if(val2>650)
{
    if(val>650)
    {
      rxChar='I';
      Serial.println('I');
    }
    else if(val<350)
    {
      rxChar='J';
      Serial.println('J');
    }
    else
    {
      rxChar='L';
      Serial.println('L');
    }
}
  else if (val2<350)
{
    if(val>650)
    {
      rxChar='D';
      Serial.println('D');
    }
    else if(val<350)
    {
      rxChar='K';
      Serial.println('K');
    }
    else
    {
      rxChar='R';
      Serial.println('R');
    }
}
  else
  {
    rxChar='S';
    Serial.println('S');
  }
  
  Udp.beginPacket(remoteIP,remotePort);
    Udp.write(rxChar);
    Udp.endPacket();

}

And this in the Wifi:

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

  byte remoteIP[]={192, 168, 1, 102};
  unsigned int remotePort=8888;
  char rxChar;
const int motorPin = 2;
const int motorPin2 = 3;
const int motorPin3 = 4;
const int motorPin4 = 5;
const int ledrojo = 1;
const int ledsadelante= 12;
const int ledsatras= 13;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
unsigned int localPort = 8888;      // local port to listen on
WiFiUDP Udp;

void setup() {
  pinMode(motorPin, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
  pinMode(ledrojo, OUTPUT);
  pinMode(ledsadelante, OUTPUT);
  pinMode(ledsatras, OUTPUT);
  
  char ssid[] = "pp123";      // your network SSID (name)
  char pass[] = "asdf1234";   // your network password
  int keyIndex = 0;                 // your network key Index number (needed only for WEP)
  int status = WL_IDLE_STATUS;
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(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:
    delay(10000);
  }

  Udp.begin(localPort);
  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:
    while (true);
  }
}

void loop() {

  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
    rxChar=Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
  }
  switch (rxChar)
    {
      case 'F':
      digitalWrite(motorPin,HIGH);
      digitalWrite(ledrojo, LOW);
      digitalWrite(ledsadelante, HIGH);
      digitalWrite(ledsatras, LOW);
      break;
      case 'L':
      digitalWrite(motorPin3,HIGH);
      digitalWrite(ledrojo, LOW);
      digitalWrite(ledsadelante, LOW);
      digitalWrite(ledsatras, LOW);
      break;
      case 'R':
      digitalWrite(motorPin4,HIGH);
      digitalWrite(ledrojo, LOW);
      digitalWrite(ledsadelante, LOW);
      digitalWrite(ledsatras, LOW);
      break;
      case 'B':
      digitalWrite(motorPin2,HIGH);
      digitalWrite(ledrojo, LOW);
      digitalWrite(ledsadelante, LOW);
      digitalWrite(ledsatras, HIGH);
      break;
      case 'I':
      digitalWrite(motorPin,HIGH);
      digitalWrite(motorPin3,HIGH);
      digitalWrite(ledrojo, LOW);
      digitalWrite(ledsadelante, HIGH);
      digitalWrite(ledsatras, LOW);
      break;
      case 'D':
      digitalWrite(motorPin,HIGH);
      digitalWrite(motorPin4,HIGH);
      digitalWrite(ledrojo, LOW);
      digitalWrite(ledsadelante, HIGH);
      digitalWrite(ledsatras, LOW);
      break;
      case 'J':
      digitalWrite(motorPin2,HIGH);
      digitalWrite(motorPin3,HIGH);
      digitalWrite(ledrojo, LOW);
      digitalWrite(ledsadelante, LOW);
      digitalWrite(ledsatras, HIGH);
      break;
      case 'K':
      digitalWrite(motorPin2,HIGH);
      digitalWrite(motorPin4,HIGH);
      digitalWrite(ledrojo, LOW);
      digitalWrite(ledsadelante, LOW);
      digitalWrite(ledsatras, HIGH);
      break;
      default:
      digitalWrite(motorPin,LOW);
      digitalWrite(motorPin2,LOW);
      digitalWrite(motorPin3,LOW);
      digitalWrite(motorPin4,LOW);
      digitalWrite(ledrojo,HIGH);
      digitalWrite(ledsadelante, LOW);
      digitalWrite(ledsatras, LOW);
      break;
    } 
    
}

What I am doing wrong? because it doesn't work... I think the Ethernet's is fine, but I'm in doubt with the Wifi's. The Ethernet's IP is 192.168.1.102 and the Wifi's Ip 192.168.1.101, that's why the Remote Ip are the opposite in each sketch.
Thanks

The Arduino wifi library works with your chip ? How is that possible ?

Arduino with Ethernet
You could add more messages. For example the return value of beginPacket Ethernet - Arduino Reference

The UDP messages are sent at an extremely high rate, please add a delay of 500ms or so at the end of the loop().

Arduino with wifi
This example is not the same as your sketch : https://www.arduino.cc/en/Tutorial/WiFiSendReceiveUDPString

If you are going to do Udp.read(), print a message that a packet was received. Print a message when the connection was made. And so on.