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

    Creating a library for DF Robot - Water Level Transmitter

    Scheduled Pinned Locked Moved Guides
    2 Posts 2 Posters 30 Views 2 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
      Roberto De Oliveira
      last edited by Roberto De Oliveira

      Hi there,
      I am Master's Student currently working on remote monitoring with IoT.

      I bought an Industrial water level sensor - DF robot Throw-in Type Water Level Transmitter coupled with an Analog Current to Voltage Converter.

      Find the Product Wiki below:

      • Throw-in Type Water Level Transmitter - https://wiki.dfrobot.com/Throw-in_Type_Liquid_Level_Transmitter_SKU_KIT0139

      • Analog Current to Voltage Converter - https://wiki.dfrobot.com/Gravity__Analog_Current_to_Voltage_Converter_for_4~20mA_Application__SKU_SEN0262

      Let me start off with saying I am very new to this field and to micropython. I have scoured the internet for a library for this sensor but I can't seem to find one.

      I understand that this sensor would use both the ADC and I2C functions on my pycom board but I am struggling to integrate these two function in order to develop a new library for this sensor. I am also aware that developing an entire library for this sensor is far above where my level of python coding is at in this moment. I was hoping that someone could help me with this as I have somewhat hit a brick wall. Any example code I could use as a guide or any pointer on how to begin writing the library would help so much.

      Below is sample code given in the product wiki but as you will see, this code is in C/C++ language.

      /***********************************************************
        DFRobot Gravity: Analog Current to Voltage Converter(For 4~20mA Application)
        SKU:SEN0262
      
        GNU Lesser General Public License.
        See <http://www.gnu.org/licenses/> for details.
        All above must be included in any redistribution
       ****************************************************/
      
      #define ANALOG_PIN A1
      #define RANGE 5000 // Depth measuring range 5000mm (for water)
      #define CURRENT_INIT 4.00 // Current @ 0mm (uint: mA)
      #define DENSITY_WATER 1  // Pure water density normalized to 1
      #define DENSITY_GASOLINE 0.74  // Gasoline density
      #define PRINT_INTERVAL 1000
      
      int16_t dataVoltage;
      float dataCurrent, depth; //unit:mA
      unsigned long timepoint_measure;
      
      void setup()
      {
        Serial.begin(9600);
        pinMode(ANALOG_PIN, INPUT);
        timepoint_measure = millis();
      }
      
      void loop()
      {
        if (millis() - timepoint_measure > PRINT_INTERVAL) {
          timepoint_measure = millis();
      
          dataVoltage = analogRead(ANALOG_PIN);
          dataCurrent = dataVoltage / 120.0; //Sense Resistor:120ohm
          depth = (dataCurrent - CURRENT_INIT) * (RANGE/ DENSITY_WATER / 16.0); //Calculate depth from current readings
      
          if (depth < 0) depth = 0.0;
      
          //Serial print results
          Serial.print("depth:");
          Serial.print(depth);
          Serial.println("mm");
        }
      }```
      

      Your help would be greatly appreciated.

      Best wishes
      Roberto

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @Roberto De Oliveira
        last edited by livius

        @Roberto-De-Oliveira said in Creating a library for DF Robot - Water Level Transmitter:

        I understand that this sensor would use both the ADC and I2C

        This sensor use only ADC.
        Look into docs how to use ADC:
        https://docs.pycom.io/firmwareapi/pycom/machine/adc/#app

        do not have this sensor then you must test it self. Below code can contain errors but should be good for start:

        import machine
        from time import sleep_ms
        
        ANALOG_PIN = 'P16'
        RANGE = 5000 # Depth measuring range 5000mm (for water)
        CURRENT_INIT=4.00 # Current @ 0mm (uint: mA)
        DENSITY_WATER=1  # Pure water density normalized to 1
        DENSITY_GASOLINE = 0.74  # Gasoline density
        PRINT_INTERVAL = 1000
        
        adc = machine.ADC()             # create an ADC object
        apin = adc.channel(pin=ANALOG_PIN, attn=ADC.ATTN_11DB)   # create an analog pin on P16
        
        while True:
            dataVoltage = apin()
        
            dataCurrent = dataVoltage / 120.0 # Sense Resistor:120ohm
            depth = (dataCurrent - CURRENT_INIT) * (RANGE/ DENSITY_WATER / 16.0) #Calculate depth from current readings
        
            if (depth < 0):
                depth = 0.0;
        
            #Serial print results
            print('depth:', depth, 'mm')
        
            sleep_ms(PRINT_INTERVAL)
        

        Above your sensor is connected to pin P16 - you can choose different one.
        look also at attenuation - i choose ADC.ATTN_11DB but maybe different should be used.
        Remember also that all pins work on 3V3. Excceeding it can damage the board.

        think about people first, then computers

        1 Reply Last reply Reply Quote 1

        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