Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, a web toolkit designed to help citizens, conservation practitioners, municipal decision-makers, researchers, educators, and students advance knowledge and stewardship of fresh water. New to EnviroDIY? Start here

Water level monitor with a Mayfly.

Home Forums Mayfly Data Logger Water level monitor with a Mayfly.

This topic contains 12 replies, has 4 voices, and was last updated by  Richard 1 year, 12 months ago.

  • Author
    Posts
  • #1646

    Richard
    Participant

    Hi
    After all the brilliant support I have received from you all regarding my attempts to build this water level monitor using a stalker V3 and finding the shortfalls that came along with it I have just had 2 Mayfly data loggers arrive here in New Zealand and I am looking forward to getting them into the wild.
    From reading the other forums here I am hoping you could give me a kick start as it seems I am plugging in with similar equipment to what you use for your projects.
    To start with I want to use my Mayfly with a serial connection from a Maxbotix 7360 and then report data using a gprsbee with a sim 900 chip.
    any chance you could help me get started with this, the coding side of these projects is quite daunting for me so anything would be a great help.
    Cheers
    Rich

  • #1672

    Shannon Hicks
    Keymaster

    Check out this ultrasonic sensor example I just posted. It shows how to read the serial output of a Maxbotix sensor. I like to use the MB7386 and MB7389 sensors because they have the TTL output that can be read directly by the Mayfly. The MB7360 you mentioned only has RS232 output, so you’ll need a RS232-to-TTL converter between the sensor and the Mayfly.

  • #1675

    Richard
    Participant

    Hi
    As usual Thanks for the support, I have added an RS232-to-TTL converter inline between the board and the mayfly and have had a go with the code you posted with only average success I seemed to be getting every second measurement as a 0 reading and some unreliable repeat-ability.
    As I was dubious about the cheap converter I had added to the circuit I decided to try some code that worked well as a software serial option and just turned off the software converter. It seemed to be really good so I’ll go with that. I’ll attach it below for anyone else that may be playing around with these things. I agree the other 2 sensors you mention would be better for the job but I guess I’ll make do with what I have for now.
    The example below can be used with a RS232 or TTL just by changing the true/false statement. true if you are using an RS232, false for TTL.

  • #1676

    Danny Waz
    Participant

    According to the datasheet, the “RS232” models MB736x are 0-Vcc (typical RS232 is -13V to +13V). Of course, it will be inverted from TTL, but if you account for that in your softwareSerial constructor, I do not see why you should need an external converter (MAX232 or similar). In fact, the converter might cause problems if it’s shifting the logic levels on the sensor side. Disclaimer: I haven’t done this myself; I’ve only used the true-TTL MB7389 and the I2C versions. Feel free to correct me if you have experience with it.

    On the subject of sensor selection for future reference, the 7369/7389 might be preferable for water surface detection because they report the “largest” return rather than the “nearest” return. I can attest that the MB7389 does a good job of ignoring small objects partially obstructing its field of view. If the sensor field of view is relatively clear it’s probably a non-issue.

  • #1677

    Danny Waz
    Participant

    Pardon the somewhat off-topic response, but regarding reading serial data I have found this post extremely helpful. Both of the examples above hold the loop() hostage until the whole string comes in. That’s okay in a small, single-sensor sketch, but it is susceptible to (a) truncating the string if the arduino gets ahead of the incoming data and (b) getting hung in the serial.read() “while” loop. It’s more robust (although, admittedly, more complicated) to add a single byte per loop() iteration.

  • #1714

    Richard
    Participant

    Hi
    It’s been a little while since I have had a chance to spend any time on this project but over the last few days I made some time.
    Thank you to Danny Waz for your suggestions as they confirmed my suspicions and I have removed the TTL-232 from the Circuit and I am just inverting in code.
    I currently have just fudged together all the code that has been provided in the Mayfly software page and have been able to get a file written to the sd card on the Mayfly that contains Sample Number, Battery volts, Temperature from RTC, Millimeters from Maxbotix 7360 Serial( I know this is not the best choice and will change in the next iteration), Year, Month, Day, Time.
    I have attached the code below for anyone who may want to use it and to hopefully get some ideas on how to improve it, (I dont really know how to code and cant take any credit for the code good or bad)
    Now that I have the data I want coming in,my next goal is to send it using a GPRSbee, any advice or help here would be really appreciated as it’s something I have never had any experience with.
    Cheers
    Rich

  • #1769

    Arnoud
    Participant

    Dear all,

    I have the same set-up of Maxbotix sonar with Mayfly as Steven. I did some trials first with my arduino and analog signal reading which was succesfull.

    Now I trying the serial code available on the enviroDIY website, but readings are 0 mm. I hope following questions may help me to get succesfull measurements:
    1) In the code the pin 5 is D5 of the mayfly?
    2) The GND and 3.3V of the D pins is used?
    3) To the pin 5 of the mayfly I connect the signal of output 2 (PulseWidth) of the maxbotix?

    Any other checks I can make to resolve this issue? Thanks in advance.

    Have a nice weekend.

    Arnoud

    • #1771

      Shannon Hicks
      Keymaster

      ArnoudC, I’m not sure which Maxbotix sensor you’re using, but on the models we usually use, it’s pin 5 on the sensor that gets connected to the Mayfly digital pin (pin 5 in my example code above, but you can make it whatever you want). I think on most of the Maxbotix sensors, Pin 6 and 7 are the power and ground pins, and pin 5 is the serial TTL or RS232 output pin that you can easily read with the Mayfly using the capture code above. Sensor pin2 is the PWM output and pin3 is the analog signal, but I prefer the serial output. The code above only works for capturing the sensor serial output. Check the datasheet for your sensor model to verify that these are the correct pin numbers.

      You can connect the sensor power and ground pins to any power or ground pin on the Mayfly or any other Arduino board. The Maxbotix sensors draw just a few milliamps of current so I usually just connect the sensor power pin to an available Mayfly digital pin and switch it high or low to control the on-off cycle of the sensor, which is handy for situations where the logger is programmed for sleeping between measurements. However, I have found that some of the sensors don’t like having their power pin connected to the switched 3.3v bus on the Mayfly. So if you’re running the Mayfly without sleeping, just connect the sensor power to the 3.3v constant bus. If you’re sleeping the Mayfly between sensor readings and you want to shut off power to the sensor, then use a digital pin to provide the power.

  • #1772

    Arnoud
    Participant

    Thanks for the quick reply. Indeed, I was probably erroneously connecting the PWM output (2) instead of the serial (5) to the Mayfly. I will give it a try this week and keep you informed. Thanks for the help…

  • #1779

    Arnoud
    Participant

    Dear all,

    OK. I have correct distance readings right now of my sonar. Thanks for helping. Next step is to save the readings into the SD card. I tried the code of Rich abuve, but in my case it is not working. Steve, can I ´incorporate´ the sonar scetch into the´simple filé´ example posted on the forum? Any tips on how do that ? I was able to save analogue measurement values of temperatures with the mayfly earlier with the simple file code, but no clue on how and where to include the section of sonar.

    Thanks in advance,

    Many greetings from Asuncion, Paraguay

  • #1824

    Shannon Hicks
    Keymaster

    ArnoudC, the second half of the Ultrasonic sensor example now has sample code for recording the data to a memory card and also puts the logger to sleep between readings.

    • #2292

      Richard
      Participant

      Hi
      I tried to use this code but it wouldn’t compile due to the #include <Sodaq_PcInt_Mod.h>

      #include <SoftwareSerialMod.h> libraries not being found. I looked and dowloaded the entire package of libraries from the GITHUB page but still couldn’t find it. any ideas??

      • #2293

        Richard
        Participant

        Hi
        Further to my last little input I have managed to get the code to compile and run on my MAYFLY with a MB7389 sonar by changing the #include <Sodaq_PcInt_Mod.h> to #include <Sodaq_PcInt_PCINT0.h> and
        #include <SoftwareSerialMod.h> to #include <SoftwareSerial_PCINT12.h>
        also a few lines down form there I changed
        SoftwareSerialMod sonarSerial(11, -1); to SoftwareSerial sonarSerial(11, -1);
        It all seems to be working fine after making these changes but wonder if I may be doing it wrong or potentially going to have problems.
        Also the way I have it now seems to make the samples get taken every two minutes and I got the impression from the code it would be every minute, am I missing something??

You must be logged in to reply to this topic.