Can't use I2C with ENC28J60


I am building a controller with a small OLED display that is controlled over ethernet.


  • Arduino Nano v3
  • ENC28J60, PINS:D10,D11,D12,D13
  • Generic I2C OLED128x32, PINS:A4,A5

My code works with either the ENC28J60 or the I2C OLED but not with both at the same time.

I can use the W5500 shield c/w Ethernet.h and EthernetUdp.h libraries to solve this problem but ENC8J60 is more suited for my purpose since it fits my pcb and the arduino nano fits on top of it.

Hopefully someone can help sort this out.

The following code has been edited to keep things simple. Basically, if I comment out the 8x8lib items I get ethernet comms.

FYI I also tried adafruit SSD_1306 and got the same results.

#include <UIPEthernet.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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xA0 };
IPAddress ip(192,168,2,4);
unsigned int localPort = 1244;              // local port to listen on
IPAddress OutIP(192,168,2,1);
int OutPort = 1242;

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];  //buffer to hold incoming packet,

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

#include <U8x8lib.h>
U8X8_SSD1306_128X32_UNIVISION_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE);
char Line1[11];
char Line2[11];

void setup() {
  // start the Ethernet and UDP

  LCDRefreshTimer = millis(); //must be put at the end of the setup to start the refresh timer

void loop() {

//This procedure updates the OLED text
void updateDisplay() {
   if ((millis()-LCDRefreshTimer) > 2000) {
    LCDRefreshTimer = millis();


void ReadNetwork() {
  String MyString;
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
    MyString = GetHashtag("#STOP");
    if (MyString != "Null"){

  } //if(packetSize)


void SendString() {
    if ((millis()-LCDRefreshTimer) > 50) {
      String MyString;
      LCDRefreshTimer = millis();
      lMotorPosition =;
      MyString = "{,#SEND,SOMETHING,}";
      char  ReplyBuffer[MyString.length()+1];
      MyString.toCharArray(ReplyBuffer, MyString.length()+1);

      Udp.beginPacket(OutIP, OutPort);

String GetHashtag(String Hashtag) {      // Get the string next to the hashtag
  char MyChars[numChars];
  char * myPointer; // this is used by strtok() as an index
  char cHashtag[sizeof(Hashtag)]; //this char is used to pass the Hashtag to Strstr function

    strcpy(MyChars, packetBuffer); //copy the received chars to allow manipulation
    Hashtag.toCharArray(cHashtag, sizeof(cHashtag)); //load the hashtag into chashtag

    myPointer = 0; //ensures the pointer is at 0
    myPointer = strstr(MyChars,cHashtag); //look for hashtag
    if (myPointer != 0) { //if the strstr finds something proceed
      myPointer = strtok(myPointer,","); //load the pointer with strtok
      myPointer = strtok(NULL, ",");  //skip to the next value past the comma
      strcpy(MyChars, myPointer); // copy the pointer to a char array
      return MyChars; //return the char array and convert it to a string
    else {return "Null";} //if all fails return null

you run out of memory

Thanks, tested it with minimal code and it worked.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.