Photon,Relay Shield and Nextion Touchscreen Based Aquaponics/Indoor Greenhouse

@Ali,that switch is designed for high voltage applications though it will work fine for yours. You could use the switch with two GPIO pins or simply connect one side of the switch to GND and the other to GPIO pin set as pinMode(pin, INPUT_PULLUP). When the switch trips, the pin will go LOW. Don’t forget to do some debouncing to prevent multiple triggers. :wink:

2 Likes

You are correct! It is magnetically operated i was just confused with the High Voltage ratings. Thanks for the quick reply.

I googled debouncing and came up with this. .
So i would have to put a resistor after the input to prevent it from reading more than once.

@Ali, no need for the resistor since it is build into the GPIO pin when you specify INPUT_PULLUP. The debounce is done by your code to make sure the floater contacts are closed properly. Take a look at this post for guidance on debounding:

:smile:

1 Like

Got it! Thank you.

1 Like

I need to send a “rest” command from the photon to the Nextion that runs in setup so everytime the unit reboots it resets the screen. There is no documentation in the instruction set on Nextion beyond the “rest” command. Serial.write(“rest”) does not work. Any thoughts?

I’d have to check my lib as I think I’ve implemented a way to call any known command, but Serial.write("rest") would not suffice, since you need to terminate each command with three 0xFF bytes too.
Try

Serial.write("rest\xFF\xFF\xFF");

Does not work! I will look into your library. Are you refering to this

int NexSendCommand(const char *cmdPattern, ...);
1 Like

:thumbsup: for the ClickButton library.

1 Like

The rest command was not part of your library along with a few others. I added those. We could add them to your library also.

Thanks for checking.
Do you want to file a PR or can you send me the list of missing commands?

I have not experimented with PR’s yet.

Here are the added instructions

#define NexREST       "rest%s"          // resets touchscreen
#define NexDIM        "dim=%d%s"        // 1.dim=50 2.dim=dim+l0 3.dim=dim-l0, Current value of backlight brightness
#define NexDIMS       "dims=%d%s"       // 1.dim=50 2.dim=dim+l0 3.dim=dim-l0, default backlight brightness when Nextion power on
#define NexBAUD       "baud=%d%s"       // Current value of baud, baud=2400 to baud=115200
#define NexBAUDS      "bauds=%d%s"      // Default value of baud when Nextion power on, baud=2400 to baud=115200
#define NexSYS0       "sys0=%d%s"       // Numeric system variables,ex sys0=10
#define NexSYS1       "sys1=%d%s"       // Numeric system variables,ex sys1=10
#define NexSYS2       "sys2=%d%s"       // Numeric system variables,ex sys2=10

For these there are already dedicated functions in NexHardware

bool      setCurrentBrightness(uint8_t dimValue, bool setDefault = false);
bool      setDefaultBaudrate(uint32_t baudRate);
bool      setBaudrate(uint32_t baudrate);

And the sys variables got added to the Nextion API after I ported the lib.

I see them now! You can add the rest and the sys variables though! There is also a rand function which i did not add.

I didn’t see any use in adding the rand and randseed (or so :blush:) function since the Photon can do that too (maybe even better).
It might be useful in skripts running on the display but not to be used between the µC and the display IMHO.

An FYI in case some one else asks, if Sleep=1 and µC is reset, display will remain in sleep mode. rest can be called at setup to reset the display but it will remain in sleep,regardless of calling sleep=0 on page0 listener, until its touched. Workaround is to use dim=0 instead of sleep and call setCurrentBrightness in the listener.

5 posts were split to a new topic: Software Timers stop to work after time

I need to add a relay that can be triggered by a pin. This pin will be activated when reset is called either through software or through the reset button. I have a button connected to RST which is exposed. The relay will be connected to 110 AC at the input and will be normally closed. On calling sysem rest through software or if the reset button is pushed it should break the circuit momentarily and reset the entire system. I have the code for the software part figured out. Can anyone suggest a good relay and base i can use for this purpose?

Hi there… Nextion has a new feature upload of tft files via the mcu. I see that its missing #include <SD.h>. I have tried looking in the forums and i find references to SdFat.h. Would that library work?

I’ve tried that with a mere “Serial<->Serial1” passthrough sketch which worked but was numbskullingly slooooooooow.

The SDFat lib is not what you need or would work either.

1 Like