chipKIT® Development Platform

Inspired by Arduino™

Ethernet firmware on MX7

Created Sun, 28 May 2017 02:29:24 +0000 by jools


Sun, 28 May 2017 02:29:24 +0000

I've pulled my MX7 out of hibernation and I'm trying to use the UDPSendReceiveString example in the Arduino IDE to send a UDP packet to my M/C using a Processing sketch provided. The code looks like this:

 This sketch receives UDP message strings, prints them to the serial port
 and sends an "acknowledge" string back to the sender

 A Processing sketch is included at the end of file that can be used to send
 and received messages for testing with a computer.

 created 21 Aug 2010
 by Michael Margolis

 This code is in the public domain.

#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: 12/30/2008

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
  0x00, 0x18, 0x3E, 0x01, 0x81, 0x78
IPAddress ip(192, 168, 0, 177);

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

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

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

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


void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if (packetSize)
    Serial.print("Received packet of size ");
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i = 0; i < 4; i++)
      Serial.print(remote[i], DEC);
      if (i < 3)
    Serial.print(", port ");

    // read the packet into packetBufffer, UDP_TX_PACKET_MAX_SIZE);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());

  Processing sketch to run with this example

 // Processing UDP example to send and receive string data from Arduino
 // press any key to send the "Hello Arduino" message


 UDP udp;  // define the UDP object

 void setup() {
 udp = new UDP( this, 6000 );  // create a new datagram connection on port 6000
 //udp.log( true ); 		// <-- printout the connection activity
 udp.listen( true );           // and wait for incoming message

 void draw()

 void keyPressed() {
 String ip       = "";	// the remote IP address
 int port        = 8888;		// the destination port

 udp.send("Hello World", ip, port );   // the message to send


 void receive( byte[] data ) { 			// <-- default handler
 //void receive( byte[] data, String ip, int port ) {	// <-- extended handler

 for(int i=0; i < data.length; i++)

I've got it all set up, but nothing seems to be going through. I scanned the Ethernet port on my laptop with WireShark to see if any packets were going through, but nothing is coming up. With that said, if the Ethernet port on the M/C isn't activated, I don't think the packets generated by Processing will ever even go across the NIC (on the laptop). I got into the docs for the MX7 and it said:

"In order to connect to and operate with an Ethernet network, the PIC32 microcontroller must be running network protocol stack firmware. Normally, the TCP/IP (Transmission Control Protocol/Internet Protocol) network protocol is used and “TCP/IP Stack” software must be used. The Microchip Applications Library, available for download from the Microchip web site, provides full protocol stack support compatible with the PIC32MX795 MAC and the LAN8720 PHY. Microchip also provides numerous example programs illustrating the use of their network protocol stack for various applications."

Does this mean I need to add/update the existing firmware (I have the most recent .hex file) in order for the Ethernet to work?


Sun, 28 May 2017 10:22:59 +0000

It means you have to use the right library. The one you want, which is bundled with the core, is not the Ethernet library (which is for the Arduino Ethernet shield), but the (rather cryptically named) DEIPcK library.


Sun, 28 May 2017 14:20:07 +0000

Thanks Majenko. Two things with that though, first I thought that the MX7 (and others like it) was compatible with Arduino code. The other thing, is that within the Arduino IDE, there are 3 sections, Built In Examples, Examples For Any Board, and Examples For The Cerebot MX7cK. This code came from the Examples For The Cerebot MX7cK section, so it should be good. Is that an error within the IDE (misplaced library)? Thanks again.


Sun, 28 May 2017 14:41:51 +0000

Not being a user of the Arduino IDE I can't say. I guess it's including all examples in all libraries included with the core and labelling them as "for the board".

Yes, your board is compatible with Arduino code. However your board does not have an Arduino Ethernet shield plugged into it. If you were to connect an Arduino Ethernet shield up to it (which you could do with jumper wires) then you could use Arduino code that is written for the Arduino Ethernet shield. However that is not what you are using.

This is not a question of whether the board you have is "compatible with Arduino code", but whether you are using the right library for the specific hardware peripherals you are using (namely the internal Ethernet peripheral in the MX795 chip and the ethernet PHY chip that is connected to it).


Sun, 28 May 2017 23:56:52 +0000

Yep the DEIPcK did the trick. A little confusing on the part of the Arduino IDE, but thanks for clearing it up! On a similar note, for anybody that may have issues getting it going, I had to manually assign a 192.168.x.x IP address in Windows in order to get it to work without going through a router (Comp. Ethernet port directly to MX7). With the router in the middle it assigned a NAT address itself and I didn't need to.