Translate

Sunday 10 August 2014

Dehumidifer datalogging...

<Deep voice over> Just when you thought it was safe to go into the attic</Deep voice over>

 Just when you thought the project was over (and it is really!) someone comes along and puts an idea in your head... "Hey, Andy, Why don't you log the data, and make some nice graphs" ... and, in reality, why would I want to .... because

a) I'm erring on the side of geeky

and

b) Because I can...

So, what's needed...

A scrappy old Windows box ... yes, this is just the ticket , 500 MB of RAM, 900MHz processor, 100MB HDD ... more than enough for the job.

A copy of Gobetwino, available here http://mikmo.dk/gobetwino.html

Another arduino board, another receiver and some code. (I suppose you could use your exisiting display, and just add the Serial.print bits to that code if you wished. Mine's all nicely boxed up, so it had to be stand alone)

// Receiver Sketch for Dehumidifier controller project
// Written by A.G.Doswell 08 Aug 2014
// Receiver connected to pin 9


#include <VirtualWire.h>
#include <VirtualWire_Config.h>

int TX_ID =10;
int Temp;
int Humidity;
int Dew;
boolean Output;
char buffer[5];
int led = 13;


void setup() {
              pinMode(led, OUTPUT);   
              //Comms set up
              Serial.begin(9600);
              // Virtualwire setup
              vw_set_tx_pin(10); // Even though it's not used, we'll define it so the default doesn't interfere with the LCD library.
              vw_set_rx_pin(9); // RX pin set to pin 9
              vw_setup(300); //sets virtualwire for a tx rate of 300 bits per second, nice and slow! 
              vw_rx_start();     
              }  
void loop()
{
typedef struct rxRemoteData //Defines the received data, this is the same as the TX struct
{
int    TX_ID; 
int    Temp;   
int    Humidity;
int    Dew;
boolean Output;

};

struct rxRemoteData receivedData;
uint8_t rcvdSize = sizeof(receivedData);

if (vw_get_message((uint8_t *)&receivedData, &rcvdSize)) 
{
  if (receivedData.TX_ID == 10)     { //Only if the TX_ID=10 do we process the data.
    int TX_ID = receivedData.TX_ID;
    int Temp = receivedData.Temp;
    int Humidity = receivedData.Humidity;
    int Dew = receivedData.Dew;
    boolean Output = receivedData.Output;
    digitalWrite(led, HIGH);
        
      // writes the received data to the serial interface
      
      Serial.print("#S|DATA|[");
      Serial.print(itoa((Humidity), buffer, 10));
      Serial.print(";");
      Serial.print(itoa((Temp), buffer, 10));
      Serial.print(";");
      Serial.print(itoa((Dew), buffer, 10));
      Serial.println("]#");
      digitalWrite(led, LOW);
 
      } 

  }
}

// End of file


So there it is. Load that into your favorite arduino, and connect a receiver to pin 9.
Now we need to tell Gobetwino what to do when it sees data from the com port. Firstly, quit the Arduino IDE. The two can't be running at the same time, or Gobetwino can't access the serial port the arduino is chatting on.

Firstly click on Commands.


Then click the New Command button. Using the drop down box , select LGFIL (Log data to file). Give it the Command name DATA (must be in capitals to match our Arduino data). Now create a blank data.txt file somewhere, using Windows explorer, just right click on a directory, click new and Text document. Name it data.txt. I chose the root of C: here for ease, but it can be anywhere....



Now back to Gobetwino. Click on the browse button, and point it to our freshly created data.txt file.


Check the Time stamp box. 

Click on save, and click on settings. Now click the serial port tab, and select the serial port our Arduino is communicating on. This is the same port the Arduino IDE was using.

Now every time the Arduino receives data from our transmitter, it will blink it's LED breifly, and send the data to Gobetwino, which will add a time stamp, and save it dutifully to the data.txt file.

You should end up (after a while) with a txt file looking a bit like this....

08/08/2014 16:13:15;28;36;14
08/08/2014 16:13:36;29;38;16
08/08/2014 16:13:58;29;38;16
08/08/2014 16:14:19;28;36;14
08/08/2014 16:14:40;28;36;14
08/08/2014 16:15:01;29;38;16
08/08/2014 16:15:22;28;36;14
08/08/2014 16:15:43;29;38;16
08/08/2014 16:16:04;29;38;16
08/08/2014 16:16:26;29;38;16
08/08/2014 16:16:47;29;38;16
08/08/2014 16:17:08;29;38;16
08/08/2014 16:17:29;29;38;16
08/08/2014 16:17:50;29;38;16
08/08/2014 16:18:11;28;36;14
08/08/2014 16:18:33;29;38;16
08/08/2014 16:18:54;29;38;16
08/08/2014 16:19:15;29;38;16
08/08/2014 16:19:36;29;38;16
08/08/2014 16:19:57;29;38;16
08/08/2014 16:20:18;29;38;16
08/08/2014 16:20:39;29;38;16
08/08/2014 16:21:01;28;36;14
08/08/2014 16:21:22;28;36;14
08/08/2014 16:21:43;28;36;14
08/08/2014 16:22:04;29;37;15


Now if we make a copy of the file, and change the extension to .csv (if windows worries about this making our file unusable, just carry on regardless!) It will then open in the spreadsheet programme of your choice (I choose OpenOffice), and with a little charting, we can create our graph...


Yes well, that's all very nice 'an 'all.... but wouldn't it be nice if the data was sent to me?

I'm not going to go into this in detail... as it took me hours to get it to work, and I'm still not really sure how I got it all to work... but there's a very useful piece of software called Sendemail available here: http://caspian.dotconf.net/menu/Software/SendEmail/ that I configured using the usual Windows task scheduler to copy the file, email me the copy, and then install a new blank in it's place... and it works a treat!

That's it for this project. It REALLY is... 



1 comment:

  1. Only a geek would suggest logging the data! ;)
    Like your use of Windows to email you the data - did you use 3.11 by any chance?
    AP

    ReplyDelete