Unofficial Nextion/TJC User Forum

Passing Data to an arduino

Hi there I would like to pass numeric date from a Nextion to an arduino I have created a “n0” as a keyboard fill and would like to send the resauling number to the arduino .
Can someone help please?
Bob

Have you installed the Nextion Library ?

If not, here the .zip file you need:
https://github.com/itead/ITEADLIB_Arduino_Nextion/archive/v0.7.0.zip

If you have installed the library, you will find some examples, like this one for Numbers:
https://github.com/itead/ITEADLIB_Arduino_Nextion/blob/master/examples/CompNumber/CompNumber_v0_32.ino#L74

Regards,
Marten

Thanks for that Marten
I will give it a try
Bob

You don’t need the library. It’s much easier to just read the serial data directly:

Nextion code in button Touch Release Event
  print "." // Ascii:46  Used in Arduino switch statement
  print pageProgram.n0.val
  printh FF // custom serial terminator

Arduino code
	// All Nextion incoming data packets are terminated with one 0xFF byte (Custom termination).
	if ((Serial1.available() > 0) || (Serial2.available() > 0)|| (Serial3.available() > 0))
	{
		incomingByte = SerialRead(serialId); // SerialRead just checks three possible serial ports for data.
    switch (incomingByte)
		{
  			case 46: // . - 
			{
				patternCount = GetSerialInteger(); // Set variable to the integer
				EEPROM.put(eePromAddress_Pattern, configPattern); // Also store in EEPROM 
				break;
			}
			...
	   }		
  
  /// <summary>
/// Parse serial input for new integer value
/// </summary>
/// <comment>
/// </comment>
/// <returns>Integer value</returns>
int GetSerialInteger()
{
	char inputHex;

	// Value will be 0 to 100
	inputHex = SerialRead(serialId);  

	int newInteger = (int)inputHex ;
	while (SerialAvailable() > 0)  //
	{
		// Discard remaining serial chars
		SerialRead(serialId);
	}

#ifdef DEBUG
	const char * int_Char = "Int:";
	Serial.print(int_Char);
	Serial.println(newInteger);
#endif // DEBUG
	return newInteger;
}

Thanks Elf i will give that a try
thanks
Bob


This forum is in no way affiliated with NEXTION®, ITEAD STUDIO®, TJC®, or anyone else really. All product names, logos, and brands are property of their respective owners. All company, product, and service names used in this website are for identification purposes only. Use of these names, logos, and brands does not imply endorsement from the respective rights holder(s).