HMI Display won't control relays with Arduino Nano 33 IoT

Hi all,

I'm brand new to the forum, and Arduino, so I do apologize in advance if my topic is in the wrong category, or if I happen to not include something in this first post. Please let me know if something should be added or removed.

Anyway, I'm currently working on a project that uses an HMI touchscreen specifically a DWIN touchscreen to control a couple of relays. When using an Arduino UNO I've had no issues with controlling the relays from the screen, however, once I tried to upload the code to my new Nano 33 IoT, no luck. I'm not sure if something needs to be adjusted in my code to make it compatible or not.

Here is the code:

unsigned char Buffer[10];
#define Relay1 6
#define Relay2 7
#define Relay3 8
#define Relay4 9

void setup() {
  Serial.begin(115200);
  pinMode(Relay1, OUTPUT); digitalWrite(Relay1,HIGH);
  pinMode(Relay2, OUTPUT); digitalWrite(Relay2,HIGH);
  pinMode(Relay3, OUTPUT); digitalWrite(Relay3,HIGH);
  pinMode(Relay4, OUTPUT); digitalWrite(Relay4,HIGH);
 }
 
void loop() 
 {
  if (Serial.available())
  {
    for (int i = 0; i <= 8; i++) //5A A5 06 83 55 00 01 00 01 frame sample received
    {
      Buffer[i] = Serial.read();
    }

    if (Buffer[0] == 0X5A)
    {
      switch (Buffer[4])
      {
        case 0x25:   //for Relay1
          if (Buffer[8] == 1)
          {
            digitalWrite(Relay1, LOW);  // switch ON relay1 , low enabled
            Serial.println("Relay1 ON");
          }
          else
          {
            digitalWrite(Relay1, HIGH);
            Serial.println("Relay1 OFF");            
          }
          break;

        case 0x56:   //for Relay2
          if (Buffer[8] == 1)
          {
            digitalWrite(Relay2, LOW);
            Serial.println("Relay2 ON");            
          }
          else
          {
            digitalWrite(Relay2, HIGH);
            Serial.println("Relay2 Off");              
          }
          break;

        case 0x57:   //for Relay3
          if (Buffer[8] == 1)
          {
            digitalWrite(Relay3, LOW);
            Serial.println("Relay3 ON");
          }
          else
          {
            digitalWrite(Relay3, HIGH);
            Serial.println("Relay3 OFF");
          }
          break;


        case 0x58:   //for Relay4
          if (Buffer[8] == 1)
          {
            digitalWrite(Relay4, LOW);
            Serial.println("Relay4 ON");
          }
          else
          {
            digitalWrite(Relay4, HIGH);
            Serial.println("Relay4 OFF");
          }
          break;

        default:
          Serial.println("No data..");
      }
    }
  }
  delay(10);  //must include delay
 }  
 

The following code is from a project using the same concept I found online and was not written by myself.

I did write a program that turns the relay on and off every 5 seconds that does work with the Nano, so I do know that the functionality of the Nano is at least working to the point that it can switch the relay on and off. From my beginner judgment, it seems like the serial is not correctly functioning (probably the obvious case).

When the display is plugged into my computer using a Serial Monitoring tool I can see that the hex displayed does match the code using VP address 2500.

Below is the schematic that I am using (Apologies for the poorly done schematic that I made in Paint)

I'm using [SunFounder Lab 4 Relay Module 5V 4 Channels Relay Module] Relays.

Once again just to restate my issue...

I have code written that functions on an Arduino Uno but doesn't on the Nano 33 IoT. Is there something skewed with the code that needs to be adjusted for the Nano?

Perhaps to just add at the end, I did try to use an ESP32 as well, and was performing almost identically to how the Nano 33 IoT is acting with the inability to retrieve the information from the display to control the relays, but when making a simple program to cycle the relays every 5 seconds I had no issues.

Thanks in advance,

Warren

Well, I solved it myself by adding Serial1.

Thanks anyways!

1 Like

You do realize that the Nano IoT is a 3.3V device that can't tolerate 5V, yes? That is important for the HMI serial input if the display is running at 5V

1 Like

Hello sir , i have same issue with dwin hmi and neno .... please help me ... how do you solve this thanks

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