I´m trying to configure the DWIN display with touch control on the Dgus software and I ran into some problem when communication/controlling functions on an Arduino Nano.
The communication is ok, and the output is setting without any problem, but the it´s a toggle output, I need a momentary output only.
I see that there is a string sent through the serial interface when I press the display, but when releasing the display there are no communication sent, so therefore the output will remain high, until I press a reset button or similar
Is there a function that trigger a string, both when I press the touch panel AND genereate a new string the I´m releasing it, or is it another way to solve this problem to obtain a momentary (no toggle) output
Here is the code, but please have in mind that this code just toggle the output, not reseting it.
My problem is that the display dont send a string through the serial line when I´m remove my finger from the screen, only when i´m pressing it. I would like to get a trig bot on the 0->1 and 1->0 function.
unsigned char Buffer[9];
int relay1 = 6;
int relay2 = 7;
int relay3 = 9;
int relay4 = 10;
void setup()
{
Serial.begin(115200);
pinMode(relay1, OUTPUT);
digitalWrite(relay1, LOW);
pinMode(relay2, OUTPUT);
digitalWrite(relay2, LOW);
pinMode(relay3, OUTPUT);
digitalWrite(relay3, LOW);
pinMode(relay4, OUTPUT);
digitalWrite(relay4, LOW);
}
void loop()
{
if (Serial.available())
{
for (int i = 0; i <= 8; i++) //this loop will store whole frame in buffer array. 5A A5 06 83 55 00 01 00 01 frame sample received
{
Buffer[i] = Serial.read();
}
if (Buffer[0] == 0X5A)
{
switch (Buffer[4])
{
case 0x50: //for relay
if (Buffer[8] == 0)
{ digitalWrite(relay1, HIGH);
Serial.println("relay 1 on");
}
if (Buffer[8] == 1)
{ digitalWrite(relay2, HIGH);
Serial.println("relay 3 on");
}
if (Buffer[8] == 2)
{ digitalWrite(relay3, HIGH);
Serial.println("relay 3 on");
}
if (Buffer[8] == 3)
{ digitalWrite(relay4, HIGH);
Serial.println("relay 4 on");
}
else
{
digitalWrite(relay4, LOW);
Serial.println("All relay off");
}
break;
default:
Serial.println("Nothing");
break;
}
}
}
delay(10);
}```
Without more info I’m guessing, but let’s assume there’s one part of the display for each of four relays. What currently happens if you briefly tap say the Relay 1 part? Is relay 1 activated? Does it remain in that condition when you remove your finger? Does it affect the states of any of the other relays? And what do you want to happen instead?
Meanwhile, I think it’s likely that all you need is to detect a high going edge from one or more of your cases and generate whatever duration of signal you need from that condition. You imply a brief pulse? But what do you want it do do?
Is true when you touch the screen.
Have an else associated with the above if to reverse whatever you did. Say you want relay1 closed only when you press the screen in relay1 region. In the 'else' have
If (Buffer[8] == 0)
{ digitalWrite(relay1, LOW);
Serial.println("relay 1 off");
You can have a case structure to capture several.
You can change Buffer[8] to FF afterwards so it just falls through.
Using the DWIN Synchrodata control.
Use the setting from the dwin v2.8 doc. page 108
Not tried by me on a nano (I dont have one) but works fine on a uno.
#include <Arduino.h>
#include <DWIN_Arduino.h>
//https://github.com/satspares/DWIN_DGUS_HMI
//doc: T5L_DGUSII-Application-Development-Guide-V2.8-0901.pdf from my github
// Settings as page 108
#define myDebug
// Soft Serial pins 2 and 3
DWIN hmi(2, 3, 115200);
void onHMIEvent(String address, int lastBytes, String message, String response);
void setup()
{
Serial.begin(9600);
// register callback
hmi.hmiCallBack(onHMIEvent);
// set our starting page
hmi.setPage(0);
// fill up some data in the vp's
hmi.setVPByte(0x5610,0x10);
hmi.setVPByte(0x5620,0x20);
hmi.setVPByte(0x5630,0x30);
delay(3000);
#ifdef myDebug // serial test should return 10 hex
Serial.println(hmi.readVPByte(0x5610),HEX);
#endif
}
void loop()
{
hmi.listen();
}
void onHMIEvent(String address, int lastBytes, String message, String response)
{
#ifdef myDebug
Serial.println("OnEvent : [ A : " + address + " | D : " + String(lastBytes, HEX) + " | M : " + message + " | R : " + response + " ]");
#endif
if (address == "5600"){
switch (lastBytes) {
case 0x10:
Serial.println("First Press");
break;
case 0x20:
Serial.println("Pressing Held");
break;
case 0x30:
Serial.println("Press Release");
break;
}
}
}