Serial Communication issue with Dwin Display

Hello all, I'm currently building a controller with a touchpad interface using a Dwin display. without boring you with all the details i have minimised some test code as an example to show my issue.

I have a touch button output from the touchpad that is sending 9 bytes of data ( have confirmed this is working through serial monitor and i get the following hex data:
5A A5 06 83 11 02 01 00 01

i have sent hex data from the mega to the dwin display with no issues ( the display reacts to an analog read that i updated in hex) but i cant get any serial coming back to the arduino from this button press.

I was using serial1 initially but thought that may have an issue so then used software serial for the same pins on my pcb and same thing.

Then i thought maybe its something to do with the case scenario so decided to check if i could get any serial available and blink the built in led

Hoping someone can briefly check my code to make sure its not something small i have done or missed. Otherwise i'm assuming its a faulty wire between etc as touchpad is fine still works if i go direct to pc over serial using the HDL662B converter to check serial over usb ?

Please find the code below, Thanks for your time

// Library Inclusions
#include <SoftwareSerial.h>

// Data Receiving and sending parameters 
unsigned char Buffer[9];
const byte rxPin = 19;
const byte txPin =18;
SoftwareSerial TouchpadSerial(rxPin, txPin);

void setup() {
  // put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
RecvData();
}

void RecvData(){
  if(TouchpadSerial.available() )
  {
    //debug if serial is being received
    digitalWrite(LED_BUILTIN,HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN,LOW);
    // end debug

    
    for(int i=0;i<=8;i++)   //TO store whole frame in buffer array. (5A A5 06 83 11 02 01 00 01)
    {
    Buffer[i]= TouchpadSerial.read();
    }
    if(Buffer[0]== 0x5A)
      {
        digitalWrite(LED_BUILTIN,HIGH);
        switch(Buffer[4])
        {
          case 0x11:  //Change Settings
            if(Buffer[8] == 1) // Handbrake (5A A5 06 83 11 02 01 00 01)
            { 
                Serial.println("Handbrake Mode Activated");
                digitalWrite(LED_BUILTIN,HIGH);
            }
               else
               {
                Serial.println("Handbrake Mode Deactivated");
                digitalWrite(LED_BUILTIN,LOW);
               }
            
            break;
            
          default:
           Serial.println("No Data");
           break;
        }
    }
  }
}

*UPDATE -

I must have had a mistake somewhere i got the led to light up now if serial available so i have deleted it so now onto the net issue with the following code the builtin led wont light up when button pressed ( sending 5A A5 06 83 11 02 01 00 01)

for(int i=0;i<=8;i++)   //TO store whole frame in buffer array. (5A A5 06 83 11 02 01 00 01)
    {
    Buffer[i]= TouchpadSerial.read();
    }
    if(Buffer[0]== 0x5A)
      {
        digitalWrite(LED_BUILTIN,HIGH);
        switch(Buffer[4])
        {

Use the hardware UARTs on the Mega rather than SoftwareSerial

Have you tried printing the values received in buffer to see what they are ?

When dealing with HEX values there is always the possibility of confusing data sent as characters representing the HEX value rather than binary data sent that can be represented as HEX values. The two are not the same

Thanks for the reply!

I haven't tried that yet its something on my to do list although i wasn't quite sure how it will all go as the 5v supplies the mega and the touchpad as a whole assembly and usb connected only doesn't have enough current to power the touchpad i'm assuming ( the touchpad turns on and off repeatedly) as in my pcb its powered externally via a 5v regulator.

I'm not sure if i can power it externally and have the pc connected i suppose i could disconnect the 5v on the usb side and leave ground common for data transfer and then test?

Printing values that you are testing is a very obvious step in debugging so please try it

So doing the following code

void setup() {
  // put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
Serial1.begin(115200);
Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
RecvData();
}

void RecvData(){
  if(Serial1.available() )
  {
    Serial.println(Serial1.read());
  }
}

I get the following on the serial monitor:

i get the following on the output: 
90
6
17
1
1

So 90 is correct for 0X5A but then after that its not right for 5A A5 06 83 11 02 01 00 01

it appears its printing every second line?

5A= 90
06 = 6
11 =17
01 =1
01=1

Please post complete code after you modify something, not snippets. There is always a risk that we integrate it incorrectly.

Because you're working with characters, don't you think that replacing 0x5A by the letter that it actually represents makes your code more readable?

if(Buffer[0]== 'Z')

Previously you said

What sketch did you use to do this ?

Sorry will do that from now on,

I have watched quite a few videos with dwin display integration and they all used 0x5A rather than any conversion or letters etc so i just stuck with that terminology and its easier for me personally when looking through my button press output hex data and lining it up with the code.

No sketch just using the ultraview serial monitor on hexinput mode through serial port and pressing the buttons to see what the output is

So I have updated a new sketch to see what is happening and I don't quite understand. This is my code:

unsigned char Buffer[9];
long CurrentTime = millis();
long LastTime = 0;
const int DelayTime=1000;
void setup() {
  // put your setup code here, to run once:
Serial.begin(115200);
Serial1.begin(115200);

}

void loop() {
  // put your main code here, to run repeatedly:
Clock();
RecvData();

}

void Clock(){
  CurrentTime = millis();
  if(CurrentTime-DelayTime > LastTime){
    LastTime=CurrentTime;
    Serial.print("Clock Data: ");
    SendData();
  }
}

void RecvData(){
  if(Serial1.available() )
  {
    for(int i=0;i<=8;i++)   //TO store whole frame in buffer array. 5A A5 06 83 11 02 01 00 01  
    {
    Buffer[i]= Serial1.read();
    }
    Serial.print("Button Press Data: ");
    SendData(); 
  }
}

void SendData(){
  Serial.print("Current Time: ");
  Serial.print(CurrentTime);
  Serial.print("    Buffer: ");
  Serial.print(Buffer[0],HEX);
  Serial.print(", ");
  Serial.print(Buffer[1],HEX);
  Serial.print(", ");
  Serial.print(Buffer[2],HEX);
  Serial.print(", ");
  Serial.print(Buffer[3],HEX);
  Serial.print(", ");
  Serial.print(Buffer[4],HEX);
  Serial.print(", ");
  Serial.print(Buffer[5], HEX);
  Serial.print(", ");
  Serial.print(Buffer[6], HEX);
  Serial.print(", ");
  Serial.print(Buffer[7],HEX);
  Serial.print(", ");
  Serial.print(Buffer[8],HEX);
  Serial.println();
    
}

What i get on the serial when a button is pushed:

Clock Data: Current Time: 3003    Buffer: 0, 0, 0, 0, 0, 0, 0, 0, 0
Button Press Data: Current Time: 3329    Buffer: 5A, FF, FF, FF, FF, FF, FF, FF, FF
Button Press Data: Current Time: 3331    Buffer: A5, 6, 83, 11, 2, 1, 0, 1, FF
Clock Data: Current Time: 4004    Buffer: A5, 6, 83, 11, 2, 1, 0, 1, FF
Clock Data: Current Time: 5005    Buffer: A5, 6, 83, 11, 2, 1, 0, 1, FF

So the initial button press has the header 5A in it and no other data then after that the rest of the data is pushed to the array and that's all that's retained.

Any ideas why this would happen?

not sure why this is happening first byte gets taken out in the array

Hello everyone. I need your help. @darcy_d @sterretje
I've followed this post.
I've received this results in my arduino ide console.

22:40:52.455 -> Clock Data: Current Time: 569978 Buffer: 0, 0, 0, FF, FF, FF, FF, FF, FF

I should have received for example this one.
5A A5 06 83 55 00 01 00 00
5A A5 06 83 55 00 01 00 01

Please, can you help me?

@darcy_d did you solved the issue ??
i also have same issue with my mega board i have used my all hardware serial i want to connect more display so im using software serial but it's giving me sometime wrong value in serial monitor but same code works perfectly in arduino uno

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