Go Down

Topic: optical dust sensor data to xively (Read 2716 times) previous topic - next topic

dattasaurabh82

Hello.
Recently I bought myself an optical dust sensor and I hooked it up with my Arduino and then I tested the code. It was satisfactory after consulting it's wiki page:
Here is the link:
http://www.seeedstudio.com/wiki/Grove_-_Dust_sensor
Code is there in the wiki page to read the data in serial monitor.

Now I wanted  to upload the data to xively and so I used xively's Arduino Library. (https://github.com/xively/xively_arduino)

Looking at one of the "data-stream upload example", I modified my code in this way:

Code: [Select]

//for OLED********
#include <Wire.h>
#include <SeeedOLED.h>
#include <avr/pgmspace.h>
//*****************
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>
#include <Xively.h>

//Assigning parameters for the dust sensor//same as the previous code
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 30000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
int concentration = 0;

//Xively parameters**************

// MAC address for your Ethernet shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

char xivelyKey[] = "neZYOTXMfiqD9OJD3sYiasJdmX1X5DxzyzH2IuHmhk4SLFAH"; //this is my xively API Key

char sensorId[] = "Particle_Conc:";
XivelyDatastream datastreams[] = {
XivelyDatastream(sensorId, strlen(sensorId), DATASTREAM_FLOAT),
};

// Finally, wrap the datastreams into a feed
XivelyFeed feed(1803940077, datastreams, 1); // my FEED ID is 1803940077 and single datastream

EthernetClient client;
XivelyClient xivelyclient(client);


void setup()
{
 Serial.begin(9600);
 
 Serial.println("Starting single datastream upload to Xively...");
 Serial.println();
 while (Ethernet.begin(mac) != 1)
 {
   Serial.println("Error getting IP address via DHCP, trying again...");
   delay(15000);
 }
 
// OLED stuff****************************
 //pinMode(CS_pin, OUTPUT);
 Wire.begin();
 SeeedOled.init();  //initialze SEEED OLED display
 DDRB|=0x21;        
 PORTB |= 0x21;
 SeeedOled.clearDisplay();          //clear the screen and set start position to top left corner
 SeeedOled.setNormalDisplay();      //Set display to normal mode (i.e non-inverse mode)
 SeeedOled.setPageMode();
 SeeedOled.drawBitmap(url,1024);   // 1024 = 128 Pixels * 64 Pixels / 8  //Set addressing mode to Page Mode
 SeeedOled.setTextXY(4, 10);          //Set the cursor to Xth Page, Yth Column  
 SeeedOled.putString("Hello"); //Print the String
 SeeedOled.setTextXY(6, 10);          //Set the cursor to Xth Page, Yth Column  
 SeeedOled.putString("Folks"); //Print the String
 delay(5000);
 SeeedOled.clearDisplay();
 SeeedOled.setTextXY(2, 4);
 SeeedOled.putString("Pollution");
 SeeedOled.setTextXY(4, 4);
 SeeedOled.putString("Recorder");
 delay(2000);
 SeeedOled.clearDisplay();
 SeeedOled.setTextXY(3, 0);
 SeeedOled.putString("Measuring...");
// SeeedOled.setHorizontalScrollProperties(Scroll_Right,3,0,Scroll_5Frames); //Set Scrolling properties to Scroll Right
// SeeedOled.deactivateScroll();             // Activate Scrolling

//OLED stuff finished**********************

// Dust sensor parameters*****************
 pinMode(8,INPUT);
 starttime = millis();//get the current time;
 //////******************
}

void loop()
{
//Dust sensor calculation thing********************

 duration = pulseIn(pin, LOW);
 lowpulseoccupancy = lowpulseoccupancy+duration;
 
 if ((millis()-starttime) > sampletime_ms)//if the sampel time == 30s
 {
   ratio = lowpulseoccupancy/(sampletime_ms*10.0);  // Integer percentage 0=>100
   concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
 
   Serial.print("Lowpulseoccupancy: ");
   Serial.print(lowpulseoccupancy);
   Serial.println("Ratio: ");
   Serial.print(ratio);
   Serial.println("Conc.: ");
   Serial.print(concentration);
   Serial.println();
   
   lowpulseoccupancy = 0;
   starttime = millis();
   
//Xivly upload stuff happening here
   datastreams[0].setFloat(concentration);
   int ret = xivelyclient.put(feed, xivelyKey);
   Serial.println(ret);
   Serial.println();
//   problem is here some where

   SeeedOled.clearDisplay();
   //SeeedOled.deactivateScroll();
   SeeedOled.setTextXY(0, 0);
   SeeedOled.putString("Dust Conc.");
   SeeedOled.setTextXY(2, 0);
   SeeedOled.putString("in pcs/283ml:");
   SeeedOled.setTextXY(4, 1);
   SeeedOled.putFloat(concentration);
  }
  delay(500);
 }


Now It's uploading data as expected after it's 30s sampling time, but the data's do not match. It's almost much lesser than the data I get using the previous code(Not implementing  xively alterations).

I'm confused if it has to do with delay or something?
It would be kind if any body out there can scan the code and tell me what's going wrong.

NI$HANT

Obviously when you added a cushion of around 30seconds in sampling it will run in 30seconds intervals that too with a delay(500) in there
"Real Men can Accomplish  Anything"

- skype : nishants5  

ਫ਼ਤੇਹ ਕਰੁਂ!

Go Up