Go Down

Topic: Problema Wifi Shield con Arduino Uno e Mega (Read 677 times) previous topic - next topic


Goodmorning everyone,

I ask you for help to solve a problem that is making me crazy.

I bought an arduino Mega R3 2560 and a WiFi Shield for a project for the creation of a midi controller. I've tried several solutions, including using the exp8266 but the arduino WiFi shield seemed to me the best, needing so many analog and digital inputs.

To send midi over WiFi, I use the AppleMidi.h library which simplifies things a lot, and the procedure is very simple:
- network connection with ssid and pass
- I create a midi session on the pc with the rtpMidi program
- I add the shield with ip and port

the problem is in this last step. When I do the peering, the connection request is rejected.

I checked that the shield was actually in the wifi network with the IP provided and it was
I checked if the shield firmware was not up to date
I also loaded the example that is found between those provided with the AppleMidi.h library (WiFiNoteOnNoteOffsec) only changing ssid and pass

everything useless ...

I think it might be a problem with the UDP or excessive latency in shield response to pc connection requests because, analyzing network traffic with wireshark, I  see PC UDP requests only  but no IP response of the shield .

Anyone know how to help me?

Thank you.


when setting up a WiFi network using micros I usually load a simple web server.  I can then see the web page from the PC - this checks the micro is connecting the the network and getting its IP address

does the Arduino serial monitor display anything?

does you router show it is allocating an IP address to the Arduino WiFi?
could you be having problems with the PC firewall blocking packets?


Hi Horace,
thanks for your reply.

I loaded a sketch of a simple web server (I have found it in example directory of wifi library) and then i checked that there was connection to the network and the server worked fine becouse I saw the web page at the IP address provided by the router for the shield.

Checking at the router IP address, I can see a correct allocation of an IP address to Arduino WiFi.

I tryed also to disable firewall but nothing change.

I load the code, it is so simple, I have found it amoung examples of the same library I have to use in order to connect to a rtp-midi session (AppleMidi.h).

I have only changed the value of "ssid" and "pass", and Wifi.begin(ssid, pass) becouse I have to connect to a network with password.

All work fine and I can see the messages on serial monitor of correct execution and connection. But when I try to connect the shield to my pc (using rtp-midi programm), a popup message says me that divice with IP:port(shield) doesn't reply to the connection request, and on the serial monitor is printed "Disconnected" that is found in "OnAppleMidiDisconnected" function at the end of the code.

As if there is an attempt of connection, but it fails and so the function OnAppleMidiDisconnected is called .

This is the code I use:

Code: [Select]

// Hardware: Mega 2560 R2 + Wifi Shield

// These need to be included when using standard Ethernet
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>

#include "AppleMidi.h"

int status = WL_IDLE_STATUS;
char ssid[] = "yourNetwork"; //  your network SSID (name)
char pass[] = "secretPassword";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

unsigned long t0 = millis();
bool isConnected = false;

APPLEMIDI_CREATE_INSTANCE(WiFiUDP, AppleMIDI); // see definition in AppleMidi_Defs.h

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void setup()
  // Serial communications and wait for port to open:
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

  Serial.print("Getting IP address...");

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);

  String fv = WiFi.firmwareVersion();
  if ( fv != "1.1.0" )
    Serial.println("Please upgrade the firmware");

  // 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);

    // wait 10 seconds for connection:

  Serial.print("IP address is ");

  Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
  Serial.print("Add device named Arduino with Host/Port ");
  Serial.println("Then press the Connect button");
  Serial.println("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes");

  // Create a session and wait for a remote host to connect to us



  Serial.println("Sending NoteOn/Off of note 45, every second");

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void loop()
  // Listen to incoming notes

  // send a note every second
  // (dont c├íll delay(1000) as it will stall the pipeline)
  if (isConnected && (millis() - t0) > 1000)
    t0 = millis();
    //   Serial.print(".");

    int note = 45;
    int velocity = 55;
    int channel = 1;

    AppleMIDI.noteOn(note, velocity, channel);
    AppleMIDI.noteOff(note, velocity, channel);

// ====================================================================================
// Event handlers for incoming MIDI messages
// ====================================================================================

// -----------------------------------------------------------------------------
// rtpMIDI session. Device connected
// -----------------------------------------------------------------------------
void OnAppleMidiConnected(uint32_t ssrc, char* name) {
  isConnected = true;
  Serial.print("Connected to session ");

// -----------------------------------------------------------------------------
// rtpMIDI session. Device disconnected
// -----------------------------------------------------------------------------
void OnAppleMidiDisconnected(uint32_t ssrc) {
  isConnected = false;

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
  Serial.print("Incoming NoteOn from channel:");
  Serial.print(" note:");
  Serial.print(" velocity:");

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
  Serial.print("Incoming NoteOff from channel:");
  Serial.print(" note:");
  Serial.print(" velocity:");


looks as though the problem is with the midi software
could you change the title of your post to reflect this
also may be worth looking at the midi forum



If the program gets stuck in the "Attempting to connect to SSID" loop, it is probably because the WiFi password is not sent. I think you need status = WiFi.begin(ssid, pass)


Thanks for reply.

The connection is ok becouse I have change the "begin" using ssid and pass. The problem is on the connection through rtp-midi. When pc send to shield the connection request, the shield refuses the request and the serial monitor display "Disconnected".

I think isn't a connection problem but a problem the involves shield use of UDP and AppleMidi.h library

Go Up