Moisture Sensor Polarity

Discussion in 'General Discussion' started by ColinCamSmith, Jul 17, 2021.

  1. ColinCamSmith

    bmerrick

    Joined:
    Jun 13, 2007
    Messages:
    434
    Likes Received:
    34
    Location:
    Sydney

    With greatest deference to Ashley's logic coding solution which is great, (and is almost always the best 'go to' solution in most situations), I am wondering if in this instance from a simplicity of purpose viewpoint that the 'Library Curve' function of the general input unit channel might suit you here?

    From my recollection, it can convert and invert an input of 0-5V to read 5-0V by just using the 'Flip Graph Direction' button when setting up the user curve. You can also add and adjust input 'voltage' points to output 'voltage' points and can even enable output as a percentage like 'mositure %' etc with the right scaling.

    There's a tutorial about doing just that in the 'Help' 'General Input' 'Tutorials' being 'Configuring General input unit to broadcast percentage output' but in that it is using a 4-20ma input but same idea.

    My general input is out of my board at the moment so can't check it easily myself unless I set it up on the bench, but I used to do similar to resistance based soil moisture sensors and thermistors a few years ago.

    I suppose you could give it a try?

    Cheers,

    Brad


    :eek::cool::cool::cool::cool::cool::cool:
     
    bmerrick, Jul 20, 2021
    #21
  2. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Ashley,

    See Screen shots. Tools does not show "Logic Options" Whee else would it be?
    Running the new code results in errors as seen on attached.

    Regards,

    Colin
     

    Attached Files:

    ColinCamSmith, Jul 20, 2021
    #22
  3. ColinCamSmith

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    It's TOOLS in the logic engine, not the main menu.

    Sorry. Typo. Delete the last end; statement
     
    Ashley, Jul 20, 2021
    #23
  4. ColinCamSmith

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    @bmerrick: I also don't have a general input available currently so I couldn't go down that path. Colin said he had tried -ve values in the gi unit without success. If you have a chance it would be interesting to see if you can get it to work.
     
    Ashley, Jul 20, 2021
    #24
  5. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    OK, activated "Send writeln output to Log" and fixed code which is now running.
    Log activated every 2 seconds as you suggest.
    See Screenshot
     

    Attached Files:

    ColinCamSmith, Jul 20, 2021
    #25
  6. ColinCamSmith

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    So is that the same value the measurement app shows, and does it change with the moisture?
     
    Ashley, Jul 20, 2021
    #26
  7. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    It is the same number that is shown in the Measurement Application.
    At the moment of course.

    The Sensor is currently quite wet and will dry out over about 48 hours so we will see a very gradual change in the readings. Both the System I/O and the Measurement Manager are on 0.0400000089 etc. and 0.04 volts respectively. Sometime in the next few hours a little more drying should take place and if the code works we should see the Text Box reading jump to about 80%.

    I need patience I guess.

    Regards,

    Colin
     
    ColinCamSmith, Jul 20, 2021
    #27
  8. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Ashley,

    For to ease the load on the Homegate, maybe I should shift the delay out to say 30 seconds.
    What say you?

    CCS
     
    ColinCamSmith, Jul 20, 2021
    #28
  9. ColinCamSmith

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    So the logic is reading the correct value. It's not changing at the moment so the hasChanged code won't be triggered. Wait until the value changes, then see if the 'Value Changed' message is logged.

    Logging every 2 seconds isn't really an issue, but change it to 30 seconds if you want to limit the number of items in the log.
     
    Ashley, Jul 20, 2021
    #29
  10. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Ashley,
    Yes, I have shifted it to 30 seconds. What with the Main Dam Pulse Meter & Bore Meter going every day the log will become very large I would imagine. I reflection, I also note that the Gen Input unit only puts out a reading about every 30 minutes or so and this can be used as a baseline later on.

    Regards,

    Colin
     
    ColinCamSmith, Jul 20, 2021
    #30
  11. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Ashley,
    Bad news. Just caught a flash from the Text Box on the Tablet when it jumped to 5%. Checked System I/O and it is reading 0.04999999. Cbus Log showing 0.050000023478 volts
     
    ColinCamSmith, Jul 20, 2021
    #31
  12. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Should I maybe reverse the Constants?
     
    ColinCamSmith, Jul 20, 2021
    #32
  13. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Another thought. I have never noted a differenced between the System I/O and the CBus Log voltages.
    Maybe it is because the code is working but the calculations may need adjustment?
    What do you think?
     
    ColinCamSmith, Jul 20, 2021
    #33
  14. ColinCamSmith

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    I'm getting a bit confused about what variables you are talking about.
    Which system i/o are you talking about, and what variable is the log showing?

    The calculation works fine in a spreadsheet, so I don't think that's the problem.
    According to me a value of .05 should give a reading of about 15%. Is that what you think?

    Did the log show the function was called? (i.e. Logged 'value changed').

    I suggest you add another debugging line to print out the calculated percentage.

    Just add the following line before the delay statement:

    writeLn('Percentage=', getRealSystemIO("Moisture Sensor")
     
    Ashley, Jul 20, 2021
    #34
  15. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    The variables I am referring to are:
    The Moisture Sensor in the System I/O reading 0.04999etc and the CBus Log from the Cbus Toolkit.

    The Homegate log is attached as a Screenshot.
    Note the Value change at 3:7:58PM

    If the Sensor is very Wet, the reading should be at least 80% and not 15%.

    Will add your extra code
     

    Attached Files:

    ColinCamSmith, Jul 20, 2021
    #35
  16. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Ashley,
    I am afraid my skill set does not run to a deep understanding of the Pascal coding required.
    Please see another error with your suggested code.
    For simplicity, it would help if you simply pasted the new code on one of my llogic screenshot.
    That way I will not keep coming up with errors due to my lack of understanding exactly where to place certain words.

    Regards,

    Colin
     

    Attached Files:

    ColinCamSmith, Jul 20, 2021
    #36
  17. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Ashley,
    Just did a calculation.
    Constant Dry = 0.001
    Constant Wet =0.059
    So Wet - Dry = 0.058

    Say Global Variable is now 0.05000
    So Global Variable of 0.05000 minus Constant Dry of 0.001 = 0.049
    Then, 0.049/0.058 * 100 = .8448 or 84%
    The conversion from the hard .8448 to a percentage needs work I think.
    Maybe your new code will fix that.

    Regards,

    CCS
     
    ColinCamSmith, Jul 20, 2021
    #37
  18. ColinCamSmith

    bmerrick

    Joined:
    Jun 13, 2007
    Messages:
    434
    Likes Received:
    34
    Location:
    Sydney
    Ashley, Colin

    I have attached an image showing the General Input unit settings to send an inverse voltage broadcast on a 0-5V input setup.

    If you see the log on the right, the first 3 are when I had a half flat old duracell attached that measures 1.45 volts. As you can see, it give a correct 5v - 1.45v = 3.55v, The next three are with no input, so it's reading 5V

    I do note that by adjusting the voltage points on the library curve, you should be able to make it broadcast the 2.8V max output of the moisture sensor as 0v and when its 0v make it broadcast 2.8v.

    I was about to change it to broadcast percentage to get that going, but dinner is served ;) so I'll set it up for percentage tomorrow as a test.

    Cheers,

    Brad



    :eek::cool::cool::cool::cool::cool::cool:
     

    Attached Files:

    bmerrick, Jul 20, 2021
    #38
  19. ColinCamSmith

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    In your code you have the constants the other way around. Which is correct? You said you needed to invert it because you wanted to display 100% wet when the constant was at a minimum and 0% dry when the constant was at a maximum.

    The error is it needs another closing bracket. Typo on my part.

    writeLn('Percentage=', getRealSystemIO("Moisture Sensor"));
     
    Ashley, Jul 20, 2021
    #39
  20. ColinCamSmith

    ColinCamSmith

    Joined:
    Nov 25, 2004
    Messages:
    84
    Likes Received:
    0
    Ashley & Brad.
    The graphing of the Gen input unit is again a little above my head but let me give you the latest state of play.
    During the night as the Moisture Sensor progressively dried out the voltage in the CBus Log and the Home Gate log (Moisture Sensor raw) rose in stages to 0.013 and the Homegate log identifies the "Value Changed".
    This is also reflected in the Moisture System I/O.

    Now, a look at the issues. Let's assume the code is working and if so why is it not replacing the Moisture Sensor System I/O?
    Is it because the Gen Input Unit through the Measurement Application Manager is over-riding the actions of the code and preventing the code from making the change?
    I tried setting up a dummy Moisture Adjust unit in the System I/O and changing the code to direct the readings to that unit. It did not work.

    And by the way Ashley, I fixed the percentage code and when the value changed to 0.013 the Homegate log read Percentage = 0.150000

    Regards,

    Colin
     
    ColinCamSmith, Jul 20, 2021
    #40
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.