Hey Guys, This is another quick update on the Nextion Interface Setup and I will also demonstrate it in the video below.
As I have Blogged in my previous blogs that the RX Interrupt on Nextion display was not working and I had planned for a Parallel bus handshake between STM32 and Arduino Nano while leaving the Rx decoding part with Arduino Nano.
The primary reason of the Rx Interrupt failure was lack of Buffered Serial Library implementation for STM32L476R Nucleo. After couple of failed attempts of implementation myself I had to fall back on the previously mentioned method.
So, The way to approach was to Decode the incoming messages from the Nextion Display in Arduino and convert the data into Parallel bus oaf Arduino which we can further poll in Perodic Routine of STM32.
Arduino Code - For Converting the Nextion messages to Parallel bus For Arduino NANO
NOTE : I am using Official Nextion Libraries
Nextion messages look something like This
0X65 0X00 0X02 0X01 0XFF 0XFF 0XFF
and details on each subsection can be found on the Nextion Instruction Set Page
#include #include "Timer.h" #include SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps Timer t; void setup() { Serial.begin(9600); myNextion.init(); pinMode(4,OUTPUT); // Display Boot Successful digitalWrite(4,LOW); pinMode(5,OUTPUT); // Ride Screen digitalWrite(5,LOW); pinMode(6,OUTPUT); // Bump Pressed digitalWrite(6,LOW); pinMode(7,OUTPUT); // Self Check Screen digitalWrite(7,LOW); pinMode(8,OUTPUT); // Music Screen digitalWrite(8,LOW); pinMode(9,OUTPUT); // Music Left digitalWrite(9,LOW); pinMode(10,OUTPUT); // Music Play Pause digitalWrite(10,LOW); pinMode(11,OUTPUT); // Music Right digitalWrite(11,LOW); t.every(1000, resetAll); } void loop() { String message = myNextion.listen(); //check for message if(message != ""){ // if a message is received... if( message == "6"){ Serial.println("Booted"); digitalWrite(6,HIGH); }else if (message == '0xFF'){ Serial.println("Off"); digitalWrite(4,LOW); // Ride Screen digitalWrite(5,LOW); // Options Screen digitalWrite(6,LOW); // Self Check Screen digitalWrite(7,LOW); // Music Screen digitalWrite(8,LOW); // Music Left digitalWrite(9,LOW); // Music Play Pause digitalWrite(10,LOW); // Music Right digitalWrite(11,LOW); }else if (message == "7"){ Serial.println("Riding Screen"); digitalWrite(5,HIGH); }else if (message == "65 7 6 0 ffff ffff ffff"){ Serial.println("Bump Pressed"); digitalWrite(6,HIGH); }else if (message == "8"){ Serial.println("Music Controls"); digitalWrite(8,HIGH); }else if (message == "65 8 4 0 ffff ffff ffff"){ Serial.println("Left Button"); digitalWrite(9,HIGH); }else if (message == "65 8 5 0 ffff ffff ffff"){ Serial.println("Play Pause Button"); digitalWrite(10,HIGH); }else if (message == "65 8 3 0 ffff ffff ffff"){ Serial.println("Right Button"); digitalWrite(11,HIGH); }else if (message == "3"){ Serial.println("Self Check Page"); digitalWrite(7,HIGH); }else { Serial.println("INVALID INPUT"); digitalWrite(4,LOW); // Ride Screen digitalWrite(5,LOW); // Options Screen digitalWrite(6,LOW); // Self Check Screen digitalWrite(7,LOW); // Music Screen digitalWrite(8,LOW); // Music Left digitalWrite(9,LOW); // Music Play Pause digitalWrite(10,LOW); // Music Right digitalWrite(11,LOW); } Serial.println(message); //...print it out } } void resetAll(void){ digitalWrite(4,LOW); // Ride Screen digitalWrite(5,LOW); // Options Screen digitalWrite(6,LOW); // Self Check Screen digitalWrite(7,LOW); // Music Screen digitalWrite(8,LOW); // Music Left digitalWrite(9,LOW); // Music Play Pause digitalWrite(10,LOW); // Music Right digitalWrite(11,LOW); Serial.println("Reset All Lines"); }
Further Here are some Code snippets for my Perodic function checking the Arduino Lines
DEFINING THE BUS
DigitalIn dispBoot(PC_4); // Connected to D4 :: Display Boot Sucessful DigitalIn mPnP(PB_1); // Connected to D10 :: Music PLay n Pause DigitalIn mRt(PB_2); // Connected to D11 :: Music Rt DigitalIn rideS(PB_11); // Connected to D5 :: Ride Screen DigitalIn bumpP(PB_12); // Connected to D6 :: Bump Pressed DigitalIn scS(PB_13); // Connected to D7 :: Self Check Screen DigitalIn musicS(PB_14); // Connected to D8 :: Music Screen DigitalIn mLt(PB_15); // Connected to D9 :: Music Left
Checking the bus in Preodic()
// Screen and Controlls Checks if(dispBoot){ nextionBoot = true; nextionScreen ='B'; }else if(rideS){ nextionScreen ='R'; }else if(bumpP){ nextionScreen ='B'; }else if(musicS){ nextionScreen ='M'; }else if(scS){ nextionScreen ='S'; } if(mPnP){ nextionMusic ='P'; }else if(mLt){ nextionMusic ='L'; }else if(mRt){ nextionMusic ='R'; } //Update the Display Screen if(nextionScreen =='R') { // checking if nextio display is on rise screen nextion.printf(dispSpeed); // updating Speed Value on Nextion Display nextion.printf("%d",(int)(ridingSpeed)); nextion.printf("%c%c%c",terminator,terminator,terminator); nextion.printf(dispAvg); // updating Avg Speed Value on Nextion Display nextion.printf("%d",(int)(avgSpeedF)); nextion.printf("%c%c%c",terminator,terminator,terminator); nextion.printf(dispDist); // updating Distance Value on Nextion Display nextion.printf("%d",(int)(totalDist)); nextion.printf("%c%c%c",terminator,terminator,terminator); }else if(nextionScreen =='S' && scS){ if(hum_temp->read_id(&id)){ nextion.printf(hx_check); nextion.printf(pass); nextion.printf("%c%c%c",terminator,terminator,terminator); }else { nextion.printf(hx_check); nextion.printf(fail); nextion.printf("%c%c%c",terminator,terminator,terminator); nextion.printf(temp_check); nextion.printf(fail); nextion.printf("%c%c%c",terminator,terminator,terminator); } if(press_temp->read_id(&id)){ nextion.printf(bx_check); nextion.printf(pass); nextion.printf("%c%c%c",terminator,terminator,terminator); }else{ nextion.printf(bx_check); nextion.printf(fail); nextion.printf("%c%c%c",terminator,terminator,terminator); } if(magnetometer->read_id(&id)){ nextion.printf(temp_check); nextion.printf(pass); nextion.printf("%c%c%c",terminator,terminator,terminator); }else { nextion.printf(temp_check); nextion.printf(fail); nextion.printf("%c%c%c",terminator,terminator,terminator); } if(accelerometer->read_id(&id)){ nextion.printf(accl_check); nextion.printf(pass); nextion.printf("%c%c%c",terminator,terminator,terminator); }else { nextion.printf(accl_check); nextion.printf(fail); nextion.printf("%c%c%c",terminator,terminator,terminator); } if(acc_gyro->read_id(&id)){ nextion.printf(gyro_check); nextion.printf(pass); nextion.printf("%c%c%c",terminator,terminator,terminator); }else{ nextion.printf(gyro_check); nextion.printf(fail); nextion.printf("%c%c%c",terminator,terminator,terminator); } if(BLEStat){ nextion.printf(ble_check); nextion.printf(pass); nextion.printf("%c%c%c",terminator,terminator,terminator); }else{ nextion.printf(ble_check); nextion.printf(fail); nextion.printf("%c%c%c",terminator,terminator,terminator); } while(scS); }
Thanks For Watching
Regards,
GS Gill