Welcome to EnviroDIY, a community for do-it-yourself environmental science and monitoring. EnviroDIY is part of WikiWatershed, an initiative of Stroud Water Research Center designed to help people advance knowledge and stewardship of fresh water.
New to EnviroDIY? Start here

Reply To: Newbie Mayfly Setup for RS485 sensor to internet

Home Forums Mayfly Data Logger Newbie Mayfly Setup for RS485 sensor to internet Reply To: Newbie Mayfly Setup for RS485 sensor to internet

Sara Damiano

    I’m sorry for not chiming in earlier.

    PlatformIO is definitely a much, much better system for programming than the Arduino IDE. It’s much more powerful and the library manager is very good. I’m running it on Atom (instead of VSCode) but it’s the same beast underneath.

    The ModularSensors library is designed to be able to communicate with a whole bunch of sensors and to get the data from them onto an SD card and up to the network. I’ve spent a lot of time optimizing the timing of the variables in the arrays to make it very flexible while minimizing power and data consumption. I decided when I started building the library to create it so that the library itself would not need to be modified by users (ie, no library config file) but that unfortunately does mean that you must have the sub-libraries for every supported sensor installed on your computer in order to compile the library.

    The example programs are gigantic and scary because they contain the code for every single sensor that’s supported and a lot of extra notes about each one. You’d never want to really run the examples as they stand.

    Ok, so to get going in VSCode/PlatformIO:

    – Open VSCode, wait for it to load up. Make sure PlatformIO is installed.
    – Click on the little house on the left in the bottom blue bar (open PlatformIO home)
    – In the PlatformIO home window, click “New Project”
    – A window should pop up – give your project a name, select “EnviroDIY Mayfly” as your board, “Arduino” as your framework, and put it wherever you want on your PC, preferably in a brand new folder all of its own.
    – Be patient while the new project is set up.
    – Now, look at the new folders that were created (using windows explorer or VSCode). Find the folder named “src”. It will have a file “main.cpp” in it. Delete “main.cpp” (HINT: By right clicking on a file in VSCode and picking “Reveal in Explorer” you can get right to the folder.)
    – Download the example you want from the modular sensors library by navigating to it and then clicking “raw” and saving the page as a ino file. Put that ino file in the “src” directory where main.cpp used to be.
    – Now, in the folder above the src file, a platformio.ini file should have been created. Open that platformio.ini in VSCode.
    – Go back to GitHub and find the platformio.ini from the example and open it up.
    – Copy the section under the heading [env:mayfly] from the platformio.ini file on GitHub into the one on your computer. Save the file.
    – Gears should start turning as soon as you save the platformio.ini. A .piolibdeps folder should appear and more libraries should appear inside of it. If this doesn’t happen within a minute or so, force it by clicking on the “clean” button that looks like a trash can on the bottom left blue bar. (The clean functionality both removes any pre-compiled library files (these are usually hidden) and downloads any new libraries and their dependencies as listed in the platformio.ini file.
    – Go to your ino program. Scroll through it and delete the chunks for sensors that don’t apply to you. Change the sensor addresses and pins to what you really have. Save.
    – Click on the check mark in the bottom blue bar. This does “platformio run” – ie, it compiles everything but does not upload. Look for any compiler errors. Hopefully you don’t have any. If you do.. first check for missing semi-colons that you accidentally deleted when customizing your pins. Dig deeper from there.
    – To upload to your board, attach it to the computer and click on the arrow button between the check mark and the cloud. If you only have one serial device connected, the upload will automatically try to go to that. If you have more than one connected, you can make sure it goes to the right one by adding the line “upload_port = COM##” in the [env:mayfly] section of your platformio.ini file.
    – Check that everything is running smoothly by watching from a serial monitor. You can access the one built in with VSCode/PlatformIO by clicking the button that looks like a power cord in the blue bar. I think all of the examples have the serial port running at 115200 baud.

    That’s kind-of whirl wind and not very detailed, but I hope that gets you going, if you haven’t gotten farther than that already on your own!