Good day All!
I beginner XOD software. I want to take measurements with a digital sensor every 15 minutes. I spent 6 hours, but I didn’t find a solution in simple question.
Which node should I use to solve this problem?
Can you help me?
Good day All!
I beginner XOD software. I want to take measurements with a digital sensor every 15 minutes. I spent 6 hours, but I didn’t find a solution in simple question.
Which node should I use to solve this problem?
Can you help me?
Unless you are trying to write the opposite of what the sensor reads, you do not want the ‘not’ node.
The easiest way to get readings every 15 minutes is to use a delay node to trigger the digital-read-UPD instead of using loop mode. Delay-T is in seconds, so it should be set to 15 * 60. delay-SET should be triggered on boot, so connect a ‘boot’ node to it. delay-DONE would then link to digital-read-UPD. digital-read-SIG would then link to digital-write-SIG (using not if you actually want to invert the signal) and digital-read-DONE would link to digital-write-UPD.
To repeat for another read 15 minutes later, digital-write-DONE should link back up to delay-SET. Since you are looping back up, you will need to add a ‘defer’ node to the wire. Since delay-SET is already connected to the boot node, you will need to add an ‘any’ node. ‘boot’ and digital-write-DONE will both link to the ‘any’ node, and the ‘any’ node will link to the delay-SET pin.
If you want to read/write on boot without a 15 minute delay, connect the ‘boot’ node to the digital-read-UPD pin instead of the delay node (you will need to use an any node here because delay-DONE also connects to the same pin).
Many thanks! I will try to apply your instruction in few days, because now I not in home.
Good day!
I will explain my task in more detail. There is a ground humidity sensor that should take measurements every 15 minutes, the digital output of the sensor is connected to a relay that should turn on the pump when the signal changes. When the signal returns to its original value, the pump should turn off and start counting for 15 minutes. After 15 minutes, the sensor makes a measurement, if the ground is wet, which means the signal has not changed, then again the sensor waits 15 minutes and makes a measurement. As soon as the ground becomes dry during the next measurement and the signal from the sensor changes to the opposite, the pump turns on and pours, the ground becomes wet, the signal changes to the original one and turns off the pump. I present the code in c++, but I’m interested in understanding and programming my device with XOD.
Now I downloaded this program and it works, the time is set to 10 seconds, that would not wait long. Now I need to make sure that when the signal changes, that is, when watering the soil, the ground becomes wet and the signal changes, the pump should turn off immediately, and not work until the next sensor survey.
You want to skip the delay node while the pump is running, so you need the pulse to go somewhere else. The way to do this in XOD is the “branch” node. Since you took out the “not” node, I’m going to assume the sensor reads HIGH when it is dry; if sensor reads LOW when dry, you will need to put the “not” node back in and replace digital-read-SIG with the “not” output in the rest of my post.
You do NOT want to trigger the delay just because digital-read-SIG is high, so the “defer” linked to that should be deleted. You do want the new “branch” node to change what happens when the pump is running, so digital-read-SIG will connect to branch-GATE. branch-TRIG should be linked to digital-write-DONE, but you are going to loop back for both outputs, so you may as well move the branch node after the “defer” instead of before it. branch-T should link back to digital-read-UPD to immediately do another check when pump is running. branch-F will link to delay-SET. since digital-read-UPD can now be triggered from two locations, you will need an “any” node to feed into it.
In your code above, there is nothing to reliably start a pulse on boot. If digital-read-SIG is HIGH when the system is started, it will probably trigger the delay-SET, but that will not happen if soil is dry when code is started. For this, you need a “boot” node. It is up to you to decide if “boot” should link to delay-SET or to digital-read-UPD (do you want the delay before 1st reading on boot?).
Advanced coding: you now have a program whose flow is controlled by a pulse. If that pulse ever gets lost, your program “hangs” because there is never anything for it to do. With the nodes you are currently using, that should never happen, but there are other nodes (like ultra-sonic range finder) that can error out instead of finishing. There can also be random things happen that cause a pulse to get dropped. One way to handle this is to add a “watchdog reset”. The easiest way to do this in XOD is to pick a point in your program that is always getting executed (in this case, digital-read-UPD would probably be the best choice). Any time a signal is sent there, also send it to delay-SET on a new delay node that will be your watchdog. The delay time on this node should be greater than the time to get back to this location normally. In this case, that would be something greater than 15 minutes. You could make it 15.1 minutes if it was critical to run right away, but you run the risk of starting a second pulse through the system if it is too short. Watering dry soil seems a low-risk application, so you could probably use a delay of 20 minutes. delay-DONE will link to digital-read-UPD to start a new cycle if there has not been a pulse to read sensor in the last 20 minutes. Note that even with this, you still need a boot node to start the code (including the watchdog timer) the first time. If you don’t have one one part of code that is always executing, you can use an “any” node to allow multiple parts of your code to pulse delay-SET of the watchdog timer.
You right, sensor reads HIGH when it is dry.
I changed the code, now it works the way I wanted (it looks terrible but it works). I didn’t use watchdog, I don’t think it’s necessary for my schema.
Thank you very much for your help! Now I have a little more understanding of how to program with XOD.
Here is an alternate way to represent the same program.
I removed the link from digital-read-SIG>defer>delay-SET because I don’t think it should be there; it will cause a 2nd pulse to enter the system (one pulse passes directly from digital-read to digital-write; the other passes to delay and goes back to digital-read 15 seconds later. The second pulse will get “lost” again as long as the first pulse gets to the delay node within that 15 seconds—it will reset the timer without passing the second pulse, but why create a 2nd pulse and hope it doesn’t break anything?). I also added a boot node to make sure there is a pulse when the system starts.
The triangle nodes at the top & bottom are bus-to & bus-from nodes. They basically create an invisible wire to connect buses with the same name so we can cleanup the patch. Instead of the bus nodes, you could also use a “jumper” node placed to the right of the delay node so you can “pull” the wire that loops back up away from existing nodes (or in this case, you could use the defer node to do the same thing). A lot of these choices will just be personal preference.
As a styling note: your two “any” nodes at the top are positioned so that the wire from “branch” to the right “any” node passes through the output pin on the left “any” node. It does not actually attach to this pin, but that is not obvious at first glance. One of the nodes should be re-positioned to avoid this ambiguity (or bus or jumper nodes used to re-route the wire). This does not affect the function of your program, but would make it easier to read.
NOTE: I have had issues in the past where boot had to go to a defer node before going to other code so the system could stabilize after boot before starting first pulse. I haven’t tested to see if this is still an issue with newer versions of XOD.
Good! Thanks! This code also works correctly.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.