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

I am considering using this PH Module from Atlas to sense Ph levels. In the second illustration they have connected the module to the analog pins of the arduino. Would the same apply for a Photon?

They also have an EC module that i want to use but will try the Ph first to see if it all works for my purpose.

@Ali, that module uses I2C so it would be connected to pins D0/D1 of the Photon. The Arduino uses different pins for I2C which are also used as Analog inputs.

ok so at the moment. I have 4 AM2302 from D0 to D3. D4 will give power to them all. RX and TX are connected to the nextion. I will need 4 more digital pins to connect botht eh EC and the TDS sensors. Can analogs be converted into Digital IO’s?

As @peekay123 said, if you want to use that Ph module, you'd need to free D0/D1 for it, but you can use A pins just the same as digital pins, but I'd not use A3 and A6/DAC if I don't need to, since these are the only non-5V-tolerant pins.
Just to stay clear of accidental feeding 5V to those pins.

Ahh! Because D0/DI are SDA/SCL. What if i want to add 2 Ph modules? Can i chain them?

I2C is a bus meant to communicate with multiple devices via these two pins.
The easiest is if your sensors allow to set individual bus addresses, but if not, you might still be able to have multiple sensors of the same kind if you can power them mutually exclusive.

You might also like to look at this thread

1 Like

Just like they say in the thread you are a gentlemen and a scholar. Thank you!! I will post back once i have it working or get stuck.

2 Likes

Im trying to set up the Photon to receive serial data from the Nextion. There is a function called sendme that sends 5 bytes of data. I can see that in the emulator but how do i receive that on the Photon. I tried doing

if (Serial.available() > 0) 
    {
   
    char1 = Serial.read();

    }

but i do not receive anything from that. Anyone have any experience with this?

If you want to do that yourself, you’d use a loop or Serial.readBytesUntil() to catch all bytes in one go.
But there is an ITEADLIB_Nextion library I ported that would do that for you.
There’s a function to send the command and its return value would be the Nextion response to that command.

Have a look at the samples

I am using your library. i have thsp and thup on every page on the touchscreen. Now once the page times out on touch press gets back to the screen it originally was. What I want is for it to go to the first page which has a passcode. What I thought was to use sendxy=1 from the touchscreen and then some way to listen for this on the photon.

Actually, I'd do that in the Nextion code on the display.
In fact I would do as much as possible on the display and only what's absolutely required in the MCU.

What would you want to get notified about this way?
I'd rather push that info from the display and only "subscribe" to that event via a dedicated callback - as you would do for any touch interaction with the display.

See i have a function setup like this right now.

void pageNumber()
{
        sendCurrentPageId(&number);
        if(number!=0)
        {
                splash.show();
        }
}

This is called by a timer. But that is not the best way to do it. In the editor there are commands for making the screen go to sleep and wake up on touch. But on wake up it goes to the page it went to sleep on. What i am doing right now is forcing the page to change to the first page based on the timer and then the function for sleep kicks in right after on the now current page. “thsp” sets a timer from last touch but the timer i have set up is active from the moment the page is loaded. What i need is the page to time out from last touch and on wake up go to another page.

I agree with putting most of the program on the touch screen itself and believe me that is what i am trying to do. The only stuff that i want to set up via MCU are the interactive texts and pictures.

In Nextion Editor you can place a Timer component and a Variable component, increment the variable via a timer script, reset the variables via any other components on-touch/on-release script and fire a page select statement in the timer script when the variable reaches a certain value.
No action required by the MCU at all.
But if you want to notify the MCU you can also use printh or several other messages from the timer script to trigger a particular callback.

I’ve no Nextion display with me at the moment, so I can’t provide you a working solution, but I might be able to send you one next week.
What type display have you got?

I am using a NX4827T043_011. To increase the timer i would have to setup the variable to increase on touch of every component on screen. Worst part is that the timer has a limit to 65000 ms and i would actually want time out to be over 2 mins. As always i appreciate your advice greatly.

If you have a timer that fires every 1000ms to increase a variable you'd have over four billion seconds to play with :wink:

How do you do the timer resetting currently on the MCU side?
No more work there than here IMHO.

As said, try to see the display as a secondary MCU and use it wherever possible.

there is a timer attached to the above function in the MCU. So the page will goto splash regardless of whether the user touched the screen or not which is not a best practice thing. I am following what you are suggesting though now.

Timer starts the moment page loaded
button press resets the timer
as long as something is pressed or touched timer keeps updating.
Only issue is i would have to put that in all the components now. I have about 24 screens as off now. That is why was looking for a shorter way to do this.

1 Like

for anyone else who tries to do the same thing.

Make 2 global variables one for holding a counter and another for a constant in the Nextion editor

then add a timer component to each page

In my case i wanted the timer to go back to a lock screen on timeout but wanted it to reset the timer if something was touched

the script in the timer events looked like this

if(splash.timerVar.val==splash.timerRepeat.val)
{
  splash.timerVar.val=0
  page splash
}else
{
  tm0.tim=60000
  splash.timerVar.val=splash.timerVar.val+1
}

timerVar is a counter that can be reset and timerRepeat is a constant in case i want to increase the timer length by 60 secs later on.

On every button enter timerVar.val=0 to reset the counter.
This way you can completely offload sleep events or page transitions off the MCU.

Thank you @ScruffR for your amazing suggestions as always.

1 Like

No need for that, just mark the one Timer and Variable component as global in the properties pane.

And hence you can omit the constant component too.

And I'd rather use

if(splash.timerVar.val>=splash.timerRepeat.val)

Just in case the one crucial check was missed or the variable got incremented otherwise.

You won't need to set tm0.tim=60000 again. The timer will just keep counting up to that, fire, reset and start again till you disable it via tm0.en=0

i could not get a global timer to work from another page. Page and timer are both declared global. Timer is enabled and i also tried to run

page0.tm0.en=1

in the pre and post initialization of the second page

I’ll have to double check with my devices.
I’m convinced I had this working with Nextion Editor 0.22 but not tried it since.