Author Topic: Moteino + Spark Core gateway instead of Pi - Solar Powered Weather Station  (Read 20304 times)

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
When I started working on my own indoor/outdoor weather station I first thought I would use a PI for the internal gateway between the Moteino and the Internet.  Having worked a lot with the Spark Core (and my Photon just arrived) I thought I would use it instead.  I looked around and didn't see any mention of anyone doing this so I started working on it this past weekend.

The h/w connections were easy....the standard GND->GND and crossing TX and RX on the Moteino and the Spark Core.  Both devices are 3.3v so that makes it nice and easy to interconnect.  My outdoor unit consists of an anemometer, BME280 (temp/humidity/pressure), solar panel and LIPO battery.  With the lower current drain of the Moteino and the solar/battery setup, the unit should run without intervention indefinitely (or at least until some catastrophic h/w failure).  The outdoor Moteino is pushing 10 variables of data to the indoor Moteino which also has an indoor temp/humidity sensor.  Once I have my case I will connect the 16x2 LCD and display both indoor and outdoor weather data.

The indoor Moteino will connect via the Spark Core which will act as the gateway to the Internet.  From there I can use any number of available dashboards to display the data in any format I choose.   Currently I'm using POSTMAN to view the data through a browser.

« Last Edit: June 30, 2015, 11:26:00 AM by Felix »

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Moteino using Spark Core as gateway instead of PI
« Reply #1 on: June 15, 2015, 08:18:17 AM »
Interesting combination, thanks for sharing, more details/photos/code are welcome.

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #2 on: June 15, 2015, 09:16:35 AM »
Felix.....it's an honor.  I am a huge fan of what you're doing with the Moteino products.  I had pretty much standardized on the Spark/Particle family but the first time I worked with your board I fell in love.  I now own 7 boards and will undoubtedly order more!

Attached is a picture of the breadboard with the Moteino and the Spark core.  The blue wires connect GND on both devices.  The yellow wires connect TX on the Moteino to RX on the Spark.  The orange wires connect RX on the Moteino to TX on the Spark.  I had to break out the orange wires so I could temporarily disconnect from the Moteino since I can't upload code while it's connected.  I don't have to disconnect when uploading code to the Spark since all connectivity is done over wireless to the cloud.

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #3 on: June 15, 2015, 09:56:03 AM »
Here are a couple of pictures of the external unit.  One picture shows the anemometer from Adafruit.  It runs on 7-24v so I used an internal board that increases the voltage from 5v-7v.  One picture shows the back of the unit.  I installed two 2" vents (front/back) to let the whole unit breathe a little.  One of the cables is for the anemometer and the other is for the temp/humidity/pressure sensor.  I still need to build the heat shield which will house the temp sensor. 

Another picture shows the solar panel (Adafruit).  It's a 6v, 3.4W solar panel.  The final pic shows the internal guts of the unit.  There is a Moteino running the whole show.  I am using a INA 3221 which gives me voltage and current readings on the LIPO (4400mAh), the solar panel and the load (Moteino and accessories).  I installed a main power switch and a reset button.  There is a recharge board which keeps the LIPO charging when the sun is out.

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #4 on: June 15, 2015, 10:02:22 AM »
The back....

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #5 on: June 15, 2015, 10:02:52 AM »
The solar panel...

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #6 on: June 15, 2015, 10:03:23 AM »
The internals....

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #7 on: June 15, 2015, 10:09:28 AM »
Spark code.  The "Spark.variable" code is used to push these variables up into the cloud so they can be monitored using any available dashboard service.  I'm sending three different types of packets from the Moteino to the Spark:  1) THP - temp, humidity, pressure, 2) - WND - windspeed in MPH, 3) ELC - electrical, voltage and current for the LIPO, Solar panel and the Moteino.  I'm using a C union on the sending side so I only send one data type and the Spark end figures it out by the first token in the string.  Not my most elegant coding but it seems to work OK.

Code: [Select]
// Global variables
char buf[64];                                           // buffer for incoming data
double temp=0,
       humidity=0,
       pressure=0,
       windspeed=0,
       lipoVoltage=0,
       lipoCurrent=0,
       solarVoltage=0,
       solarCurrent=0,
       loadVoltage=0,
       loadCurrent=0;


void setup()
{
    Serial1.begin(115200);
    Spark.variable("temp", &temp, DOUBLE);
    Spark.variable("humidity", &humidity, DOUBLE);
    Spark.variable("pressure", &pressure, DOUBLE);
    Spark.variable("windspeed", &windspeed, DOUBLE);
    Spark.variable("lipoVoltage", &lipoVoltage, DOUBLE);
    Spark.variable("lipoCurrent", &lipoCurrent, DOUBLE);
    Spark.variable("solarVoltage", &solarVoltage, DOUBLE);
    Spark.variable("solarCurrent", &solarCurrent, DOUBLE);
    Spark.variable("loadVoltage", &loadVoltage, DOUBLE);
    Spark.variable("loadCurrent", &loadCurrent, DOUBLE);
}


void loop()
{
    int x, avail;
    char *token;
    const char sep[2] = ",";

    if ((avail = Serial1.available()) >= 20)            // wait until we get a full buffer
    {
        for (x=0; x < avail; x++)
            buf[x] = Serial1.read();
        buf[x] = '\0';                                  // string must be null terminated
       
        token = strtok(buf, sep);                       // pick off first token = packet type
        if (token != NULL)
        {
            if (strncmp(token, "WND", 3) == 0)          // windspeed packet
            {
                token = strtok(NULL, sep);
                if (token != NULL)
                    windspeed = (float) atof(token);    // extract windspeed
                Serial1.print("wind");
            }
            else if (strncmp(token, "THP", 3) == 0)     // temperature, humidity, pressure packet
            {
                token = strtok(NULL, sep);
                if (token != NULL)
                    temp = (float) atof(token);         // extract temperature
                token = strtok(NULL, sep);
                if (token != NULL)               
                    humidity = (float) atof(token);     // extract humidity
                token = strtok(NULL, sep);
                if (token != NULL)               
                    pressure = (float) atof(token);     // extract pressure
            }
            else if (strncmp(token, "ELC", 3) == 0)     // electrical packet
            {
                token = strtok(NULL, sep);
                if (token != NULL)
                    lipoVoltage = (float) atof(token);  // extract lipoVoltage
                token = strtok(NULL, sep);
                if (token != NULL)               
                    lipoCurrent = (float) atof(token);  // extract lipoCurrent
                token = strtok(NULL, sep);
                if (token != NULL)               
                    solarVoltage = (float) atof(token); // extract solarVoltage
                token = strtok(NULL, sep);
                if (token != NULL)
                    solarCurrent = (float) atof(token); // extract solarCurrent
                token = strtok(NULL, sep);
                if (token != NULL)               
                    loadVoltage = (float) atof(token);  // extract loadVoltage
                token = strtok(NULL, sep);
                if (token != NULL)               
                    loadCurrent = (float) atof(token);  // extract loadCurrent
            }
        }
    }
}

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #8 on: June 15, 2015, 10:23:08 AM »
Here is the code running on the Moteino in the outdoor unit.  Every second it reports the windspeed to the internal unit.  Every 60 seconds it sends temp/humidity/pressure and the 6 electrical readings to the indoor unit.

I had to attach the INO file and the header file since it was longer than 5K.

Here is what the output looks like coming from the outdoor unit:

WND,0.00
WND,0.00
WND,0.00
WND,0.00
WND,0.00
WND,0.00
WND,0.00
WND,0.00
WND,0.00
WND,0.00
THP,90.91,55.89,29.73
ELC,4.12,116.80,4.81,157.60,4.55,40.00

TomWS

  • Hero Member
  • *****
  • Posts: 1888
Re: Moteino using Spark Core as gateway instead of PI
« Reply #9 on: June 15, 2015, 11:28:13 AM »
Are you using software serial port?  Your code is using Serial1 but your photos show a Moteino, not a Moteino Mega.

Tom

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5939
  • Country: us
    • LowPowerLab
Re: Moteino using Spark Core as gateway instead of PI
« Reply #10 on: June 15, 2015, 12:14:20 PM »
Nice detailed and labeled photos syrinxtech!
I see you're using adafruit's solar charger, how's that working? How did you determine the size of the cell you need, or did you just pick one you thought would give plenty of juice?
Maybe I'm missing something but I wonder why you are using the step-up? Do you need 5V/more for one of the sensors/boards/Spark?

EloyP

  • Jr. Member
  • **
  • Posts: 58
Re: Moteino using Spark Core as gateway instead of PI
« Reply #11 on: June 15, 2015, 02:35:28 PM »
Hi syrinxtech,

Thanks for sharing; very nice project!

I am curious about power usage and conservation on the outdoor unit... I took a quick look at WeatherStation2.ino and don't see any code to put the radio to sleep, or for the ATmega itself to go into deep sleep mode, and at the same time the unit is sending sensor data every 60 seconds. Would this not cause the outdoor unit to stop working if you have a couple of cloudy days? Or asked a different way, how long can the LiPo battery keep the outdoor unit running without being recharged?

Cheers!

Eloy Paris.-

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #12 on: June 15, 2015, 02:50:11 PM »
Tom, the code using Serial1 is for the Spark Core.  On the Core, Serial is the USB port while Serial1 is the TX/RX serial port.

Felix, that charger is working fantastic.  My brother-in-law and I spent several days over a period of about 3 weeks deciding on the best (at that moment in time) charger, LIPO, solar cell and microcontroller for the project.  As I mentioned earlier, my initial plan was to use a Arduino UNO for the outside unit and the inside unit.  Once I ordered my first Moteino that plan went out the window so all specifications on the charging combo (LIPO/charger/solar cell) were for the UNO.  We did extensive testing with the UNO and found that without sensors it was running around 120-130 mA while the Moteino was running around 30-40mA.  I spent a couple of days working with the various methods to put the Moteino to sleep and got it down to the uA levels.  Then, of course I changed my specs and decided that instead of sending all data from the outside unit to the inside unit every minute I would send the windspeed every second and the rest of the data (which grew to include the 6 electrical measurements once I found the INA3221 board) every minute.  That negated the ability to put anything to sleep since I was sending data constantly.

We have lots of days of data gathering and many Excel spreadsheets that show the various ways we have structured the box.  I'm attaching one of the samples we did this past weekend.  You can watch the graph and see exactly when the sun starts coming up and when it eventually goes over my house and the box is in the shade. 

The step-up is for the anemometer.  The one I picked from Adafruit requires 7-24 VDC and the solar cell only puts out 6V and the LIPO tops out at 3.7v.  We originally tuned this board to output 9V which worked fine for the anemometer but of course drew more current.  We found that tuning it to 7VDC was optimum for both the anemometer and the current draw.  Once we switched to the Moteino we found that we had basically built a box that will run forever (unless the sun doesn't come out for at least a week).  Take a look at the chart in the attached Excel file.

Eloyp, the windspeed is being sent every second and the the temp/pressure/humidity and 6 electrical measurements are sent every minutes.  Therefore I can't put anything to sleep.  I originally coded everything to sleep when all measurements were being sent once a minute (~54 seconds of sleep per minute).  Once I changed the requirements I had to take out the sleep code.  But, given the size of the solar panel, the capacity of the LIPO and the minimal current draw of the Moteino and attached sensors, I can't see a situation where it would ever run out of power unless the sun wasn't out for at least 5-7 days.

syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #13 on: June 15, 2015, 02:57:27 PM »
If you're into the power side of things, take a look at the chart in the attached Excel spreadsheet.  This one was measuring just the load voltage from a little after 8pm until later the next day.

You can clearly see the affects of the sun.  Notice the lowest voltage levels....


syrinxtech

  • Sr. Member
  • ****
  • Posts: 306
  • Country: us
    • Syrinx Technologies
Re: Moteino using Spark Core as gateway instead of PI
« Reply #14 on: June 16, 2015, 10:03:27 PM »
Finished mocking up the internal weather unit today.  Basically there is another Moteino with a DHT11 providing internal temperature and humidity.  It's connected serially to a Spark Core which is pushing 10 variables of data to the Internet for graphing and analysis.  The internal unit is also driving a 16x2 LCD screen which is currently displaying internal temperature, humidity and the external heat index.  When I'm done it will display a total of 3 different screens:

1) External temp/humidity/pressure/heat index
2) Current windspeed/max windspeed/average windspeed over last 30 minutes
3) Internal temp/humidity

Just ordered the case to hold all this stuff so once it gets here it will take a day or two to assemble.  Will include a reset pushbutton switch just in case something weird happens in the code.  I am also going to use a LDR to regulate the intensity of the backlight for nighttime purposes.

Stay tuned.