Just by including this import the sketch fails to compile:
#include "Nextion.h"
Output:
D:\Documents\Arduino\libraries\ITEADLIB_Arduino_Nextion-master\NexUpload.cpp:17:28: fatal error: SoftwareSerial.h: No such file or directory
#include <SoftwareSerial.h>
^
compilation terminated.
exit status 1
Error compiling for board Arduino Due (Programming Port).
My NextConfig.h:
/**
* @file NexConfig.h
*
* Options for user can be found here.
*
* @author Wu Pengfei (email:<pengfei.wu@itead.cc>)
* @date 2015/8/13
* @copyright
* Copyright (C) 2014-2015 ITEAD Intelligent Systems Co., Ltd. \n
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
#ifndef __NEXCONFIG_H__
#define __NEXCONFIG_H__
/**
* @addtogroup Configuration
* @{
*/
/**
* Define DEBUG_SERIAL_ENABLE to enable debug serial.
* Comment it to disable debug serial.
*/
//#define DEBUG_SERIAL_ENABLE
/**
* Define dbSerial for the output of debug messages.
*/
//#define dbSerial Serial
/**
* Define nexSerial for communicate with Nextion touch panel.
*/
/#define nexSerial Serial2
#define nexSerial Serial
#ifdef DEBUG_SERIAL_ENABLE
#define dbSerialPrint(a) dbSerial.print(a)
#define dbSerialPrintln(a) dbSerial.println(a)
#define dbSerialBegin(a) dbSerial.begin(a)
#else
#define dbSerialPrint(a) do{}while(0)
#define dbSerialPrintln(a) do{}while(0)
#define dbSerialBegin(a) do{}while(0)
#endif
/**
* @}
*/
#endif /* #ifndef __NEXCONFIG_H__ */
ard_newbie:
There is no SoftwareSerial library for the DUE since there are hardware Serial1,2,3 and 4.
If I undo the changes from NexConfig.h and restart the IDE the same compilation error happens,
what is required to tweak on the official nextion library to get it compiling for the DUE?
You'll probably need to change the #if defined stuff to check for Due's processor and change the pin numbers in the constructor.
Also delete the transmit-only code in SoftwareSerial::write(), keeping only the first line which calls "port->write(b)", and delete the last part of the constructor which sets up the transmit-only pins. Or go back in the github history for that file and get a version before that transmit-only stuff was added.
The idea behind this SoftwareSerialscode is to just use a real serial port, depending on which pins are chosen, but does so under the name "SoftwareSerial" for compatibility sake. When you have some Arduino library that is hard-coded to require SoftwareSerial, just saying "use one of the real ports" is a terrible answer, because some library (in this case "NexConfig") that you didn't write is written to depend on SoftwareSerial. Maybe NexConfig is simple and easy to edit, but maybe not? Many of the very old libs needing SoftwareSerial have some horrendously complex code, often to get around the extreme limits of 8 bit AVR while also using the CPU to emulate serial.
So this code gives you a SoftwareSerial library that lets you have compatibility with stuff that's hard-coded with the SoftwareSerial names, but in turn it just uses one of the real serial ports. Simple, right? Or at least it was simple until I tried to actually start adding real SoftwareSerial for the cases where 2 pins are chosen where there isn't a real serial port.