Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Wipy sensor node

    Scheduled Pinned Locked Moved Projects
    wipy 2.0
    8 Posts 3 Posters 3.3k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      robmarkcole
      last edited by

      Hi all, creating a sensor node comprising temperature, light levels etc. to ping data to my home automation system over MQTT. Temperature is working well with a DS18B20. Now added a plan moisture sensor, and hoping someone can advise on the ADC component. Currently reading a fixed 4095 from the sensor, so presume it is saturating? Unfortunately the sensor has no documentation but I believe @bucknall has used this or a very similar sensor?

      https://www.amazon.co.uk/gp/product/B00K67Z76O/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1

      0_1492238609768_upload-508e43c4-eb4a-4f45-bf8d-fb072bf9e6dc

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @robmarkcole
        last edited by

        @robmarkcole
        i see 3V3 poverin - good
        Now question is how you declare ADC?
        And do you checked what chappened if you put some part to water? Does value changed? And what happened on digital pin from sensor (currently not connected by you)

        think about people first, then computers

        1 Reply Last reply Reply Quote 0
        • R Offline
          robmarkcole
          last edited by robmarkcole

          HI @livius when I short the two electrodes with a wire the value drops to 0, which is what I expect from the documentation which states high value for high resistance, and low for none. However when I place the electrode in water it briefly changes value (for a single reading) but then returns to 4095. Perhaps I am in differential read mode - or should use a different pin?
          I read with:

          adc = machine.ADC() # create an ADC object
          apin = adc.channel(pin='P16') # create an analog pin on P16
          analog_val = apin()

          I notice that the example (https://docs.pycom.io/pycom_esp32/pycom_esp32/tutorial/includes/adc.html) uses pin 13 but I don't see this on the board diagram (https://docs.pycom.io/pycom_esp32/_downloads/exp_v03_pinout_v13.pdf)

          robert-hhR 1 Reply Last reply Reply Quote 0
          • robert-hhR Offline
            robert-hh @robmarkcole
            last edited by robert-hh

            @robmarkcole Hello Rob,
            try something like:
            apin = adc.channel(pin='P16',attn=3) # create an analog pin on P16
            That extends the range of the adc to 0..3.5V. Then it should not overflow, and you can see the required range,

            R 1 Reply Last reply Reply Quote 0
            • R Offline
              robmarkcole @robert-hh
              last edited by

              Thanks @robert-hh I am now seeing sensible values. Bit noisy, will have to use a long integration - is there a method for that?

              Also I don't see atten=3 as an option in the docs..? https://docs.pycom.io/pycom_esp32/library/machine.ADC.html 'The supported values are: ADC.ATTN_0DB, ADC.ATTN_2_5DB, ADC.ATTN_6DB, ADC.ATTN_11DB'

              robert-hhR 1 Reply Last reply Reply Quote 0
              • robert-hhR Offline
                robert-hh @robmarkcole
                last edited by robert-hh

                @robmarkcole said in Wipy sensor node:

                ADC.ATTN_11DB

                ADC.ATTN_11DB is a constant with the value of 3. I tried it with my build, and it did not work. But I have an older build.
                The method for integration is a simple average, like:

                avg = 0
                _AVG_NUM = const(100)
                for _ in range (_AVG_NUM):
                    avg += adc.read()
                avg /= _AVG_NUM
                
                R 1 Reply Last reply Reply Quote 0
                • R Offline
                  robmarkcole @robert-hh
                  last edited by robmarkcole

                  @robert-hh OK great, is there a general optimum rate to sample the analogue reading for averaging - or is it hardware specific?

                  Taking 100 averages and sampling once a second, my values appear to oscillate when in air..

                  0_1492264650326_upload-adcd74b5-bb5a-4034-8ab5-3f43d0590d9b

                  In water, the readings initially drift upwards.

                  0_1492264826358_upload-228223c2-3c18-4fe7-934f-d329badb6923

                  After a minute or so, it appears to reach a steady state.

                  0_1492264951479_upload-51cf73d6-13a8-4dac-b7e6-32a06a2eae9d

                  0_1492264665986_upload-53e32b5e-a8cd-4577-acfe-e12b1cdfa764

                  robert-hhR 1 Reply Last reply Reply Quote 0
                  • robert-hhR Offline
                    robert-hh @robmarkcole
                    last edited by

                    @robmarkcole The frequency of sampling depends of the rate, your data changes. The sampling for averaging here can be fast, since it just deals with the intrinsic noise of the esp32 adc (which, by the way, is a very bad one). So the whole burst is to be taken as one sample.
                    The plant moisture will not change really fast. So taking a value burst like once per hour should be more than sufficient. If you want some theory about that, search for "Shannon sampling theorem".

                    1 Reply Last reply Reply Quote 0

                    Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                    Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                    With your input, this post could be even better 💗

                    Register Login
                    • 1 / 1
                    • First post
                      Last post

                    Pycom on Twitter

                    Pycom