Page 1 of 1

DMD2 and Ethernet Arduino Mega Problem

Posted: Mon Jun 29, 2020 8:03 am
by dogank
Hello,

I am using dmd panels, ethernet and Arduino Mega. Ethernet connects to spi pins of arduino mega. DMD is connected to 6 7 8 9 11 13 pins. I am using ethercard and dmd2 library. I can receive string from ethernet but i can not send anything. When i try without using dmd i could be able to send and receive data but when i add dmd it does not send data. Where is my mistake? Could you help me please?

Code: Select all

#include <SPI.h>
#include <DMD2.h>
#include <EtherCard.h>
#include <IPAddress.h>

#include "SystemFont5x7.h"
#include "Arial_black_16.h"
//SoftDMD(byte panelsWide, byte panelsHigh, byte pin_noe, byte pin_a, byte pin_b, byte pin_sck,
//          byte pin_clk, byte pin_r_data);
SoftDMD dmd(2,2,9,6,7,8,13,11);

char msg1[]="DGNK";
//int srcip="192.168.1.72";

#define STATIC 1  // set to 1 to disable DHCP (adjust myip/gwip values below)

#if STATIC
// Ethernet interface IP address
static byte myip[] = { 192,168,1,175 };
// Gateway IP address
static byte gwip[] = { 192,168,1,1 };
static byte mask[] = { 255,255,255,0 };
static byte dnss[] = {  192,168,1,1 };
#endif

// Ethernet MAC address - must be unique on your network
static byte mymac[] = { 0x70,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[500]; // TCP/IP send and receive buffer

// Callback that prints received packets to the serial port
void udpSerialPrint(uint16_t dest_port, uint8_t src_ip[IP_LEN], uint16_t src_port, const char *data, uint16_t len){
  IPAddress src(src_ip[0],src_ip[1],src_ip[2],src_ip[3]);

  Serial.print("dest_port: ");
  Serial.println(dest_port);
  Serial.print("src_port: ");
  Serial.println(src_port);

  Serial.print("src_ip: ");
  ether.printIp(src_ip);
  Serial.println("data: ");
  Serial.println(data);
    char textToSend[] = "AABBCCDDEEFFGGHH";
    //digitalWrite(53, LOW);
    //ether.parseIp(src_ip, "192.168.1.72");
    ether.sendUdp(textToSend, sizeof(textToSend), 3000, src_ip, 3000 ); 

}

void setup(void)
{
  Serial.begin(115200);
  ether.begin(sizeof Ethernet::buffer, mymac, 53);
  // Change 'SS' to your Slave Select pin if you aren't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, 53) == 0)
    Serial.println(F("Failed to access Ethernet controller"));
  #if STATIC
  ether.staticSetup(myip, gwip, dnss, mask);
  #else
  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));
  #endif

  ether.printIp("IP:  ", ether.myip);
  ether.printIp("GW:  ", ether.gwip);
  ether.printIp("DNS: ", ether.dnsip);

  // Register udpSerialPrint() to port 1337
  ether.udpServerListenOnPort(&udpSerialPrint, 3000);

  dmd.begin();

  dmd.setBrightness(255);
  dmd.selectFont(SystemFont5x7);
}

void loop()
{
  ether.packetLoop(ether.packetReceive());
  //ether.sendUdp(textToSend, sizeof(textToSend), 3000, srcip, 3000 );  //bak

  for(int a=0;a<sizeof(msg1)-1;a++){
    dmd.drawString(1+6*a,1, String(msg1[a]));
  }

}
Regards,
Dogan