Post a new topicPost a reply Page 2 of 2   [ 16 posts ]
Go to page Previous  1, 2
Author Message
 Post subject: Re: Calibrating TGS2611 - Methane Gas
PostPosted: Thu Mar 17, 2011 4:15 pm 

Joined: Tue Mar 08, 2011 8:56 pm
Posts: 66
I am using this code
Code:
char* sinkMAC = "0013A200406A6225 "; // gateway mac
char* selfMAC = "0013A200406A62BC "; //node mac

int8_t state=0;
int g=0;

uint8_t pkt_id = 0;
long previous=0;
int GPS_Error = 1;

packetXBee* paq_sent;
char* msg = "1";
const char* sep ="@@";

void floatToStr(char* retStr,float value)
{
  int int_part = (int)value;   
  value = value-(float)int_part;
  value = value*1000;
  int decimal_part = (int)value; 

  sprintf(retStr,"%d.%d",int_part,decimal_part);
  XBee.println(retStr);
}


void getFormattedVals(char* formattedData,float atp, float CO)
{
  int int_part,decimal_part;
  char atpStr[6],co2Str[6];

  floatToStr(atpStr,atp);
  floatToStr(co2Str,CO);

  sprintf(formattedData,"%s%s%s",atpStr,sep,co2Str);
  XBee.println(formattedData);       
}

void getSensorValues(char* dataTemp)
{
  int GPS_Error=1;
  int GPS_Tries=0;

  //char GPSData[40];
  char sensorData[40];       

  SensorGas.configureSensor(SENS_SOCKET3B, 10, 1); 
  SensorGas.setSensorMode(SENS_ON, SENS_SOCKET3B);
 

  XBee.println("Online...sending Temperature");
  int temperature_value=RTC.getTemperature();
  XBee.println(temperature_value);


  XBee.println("Online...sending atmospheric pressure");
  float atp_value=SensorGas.readValue(SENS_PRESSURE);
  SensorGas.setSensorMode(SENS_OFF, SENS_PRESSURE);
  XBee.println(atp_value);

  // Printing a message, remember to open 'Serial Monitor' to be able to see this message
  XBee.println("Online...sending CO sensor data after 30 seconds");
  float CO_value = SensorGas.readValue(SENS_SOCKET3B);
  SensorGas.setSensorMode(SENS_OFF, SENS_SOCKET3B);
  XBee.println(CO_value);

  getFormattedVals(sensorData,atp_value,CO_value);
  XBee.println(sensorData);

  sprintf(dataTemp,"%d%s%d%s%s",GPS_Error,sep,temperature_value,sep,sensorData);

  XBee.print("Msg from getValueSensors: ");
  XBee.println(dataTemp);

}

void setup()
{
  SensorGas.setBoardMode(SENS_ON);

  // set GPS on
  GPS.setMode(GPS_ON); 
  XBee.println("Start WASP Deployment");
  // Inits the XBee 802.15.4 library
  xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL); 
  // Powers XBee
  xbee802.ON();   
  //xbee802.setPowerLevel(0); //ideally 0=50m and 4=500m
  XBee.flush();

}




void loop()
{

  // Adding data to the packet to be sent
  XBee.println("");
  XBee.println("COLLECT_SENSOR_DATA ");
  pkt_id = pkt_id+1;       

  char dataTemp[50];
  char data[90];

  getSensorValues(dataTemp);
  sprintf(data,"%s%s%s",msg,sep,dataTemp);

  XBee.println(data);


  // Set params to send
  paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
  paq_sent->mode=UNICAST;
  paq_sent->address_type= 0;
  paq_sent->MY_known = 0;
  paq_sent->opt=0;
  paq_sent->packetID=pkt_id;                                                   

  xbee802.setOriginParams(paq_sent, selfMAC, MAC_TYPE);
  xbee802.setDestinationParams(paq_sent, sinkMAC, data, MAC_TYPE, DATA_ABSOLUTE);


  xbee802.sendXBee(paq_sent);

  if( !xbee802.error_TX )
  {
    XBee.println("ok");
  }
  free(paq_sent);
  paq_sent=NULL;

  xbee802.pos--;
  delay(1000);
  XBee.println("FLUSHING NOW !!");
  XBee.flush();
  XBee.println("FLUSHED !!");
}

But it returns a weird output.

Here is the result: http://img855.imageshack.us/i/capturebm.jpg/

Please suggest how do I improve it.

Thanks.

Best.


Top
 Profile  
 
 Post subject: Re: Calibrating TGS2611 - Methane Gas
PostPosted: Mon Mar 21, 2011 12:15 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7491
Hi,

First of all, you should change the socket because you are using 'SOCKET3B' and you must use 'SOCKET3A'.

The code is right, I've just tested it without any modifications and it works fine.

The characters you receive on the GW are the string you create and the API header.

If you don't want to receive the API header, you can use the function 'send' instead of 'sendXBee'.

Regards


Top
 Profile  
 
 Post subject: Re: Calibrating TGS2611 - Methane Gas
PostPosted: Tue Mar 22, 2011 3:30 am 

Joined: Tue Mar 08, 2011 8:56 pm
Posts: 66
Hi,

1.
In the same code (I modified a bit again) I want to get readings of GPS. Since I don't have much programming experience and also that I am new to waspmote, I am not able to plug-in GPS functions properly. If you can help then I would be thankful.
Code:
char* sinkMAC = "0013A200406A6225 "; // gateway mac
char* selfMAC = "0013A200406A62BC "; //node mac

int8_t state=0;
int g=0;

uint8_t pkt_id = 0;
long previous=0;
int GPS_Error = 1;

packetXBee* paq_sent;
char* msg = "1";
const char* sep ="@@";

void floatToStr(char* retStr,float value)
{
  int int_part = (int)value;   
  value = value-(float)int_part;
  value = value*1000;
  int decimal_part = (int)value; 

  sprintf(retStr,"%d.%d",int_part,decimal_part);
  XBee.println(retStr);
}


void getFormattedVals(char* formattedData,float atp, float CO, float VOC, float NO2)
{
  int int_part,decimal_part;
  char atpStr[6],coStr[6],vocStr[6],no2Str[6];
 
  floatToStr(atpStr,atp);

  sprintf(formattedData,"%s%s",atpStr,sep);
  XBee.println(formattedData);     
}

void getSensorValues(char* dataTemp)
{
  int GPS_Error=1;
  int GPS_Tries=0;

  //char GPSData[40];
  char sensorData[40];       

  SensorGas.configureSensor(SENS_SOCKET3A, 1, 1); 
  SensorGas.setSensorMode(SENS_ON, SENS_SOCKET3A);
 
  SensorGas.configureSensor(SENS_SOCKET2A,1,1);
  SensorGas.setSensorMode(SENS_ON, SENS_SOCKET2A);
  delay(30000);
 
  SensorGas.configureSensor(SENS_SOCKET2B, 1, 1);
  SensorGas.setSensorMode(SENS_ON, SENS_SOCKET2B);
  delay(30000);
 
  XBee.println("Sending Temperature");
  int temperature_value=RTC.getTemperature();
  XBee.println(temperature_value);


  XBee.println("Sending atmospheric pressure");
  float atp_value=SensorGas.readValue(SENS_PRESSURE);
  SensorGas.setSensorMode(SENS_OFF, SENS_PRESSURE);
  XBee.println(atp_value);

  // Printing a message, remember to open 'Serial Monitor' to be able to see this message
  XBee.println("Sending CO sensor data after 30 seconds");
  float CO_value = SensorGas.readValue(SENS_SOCKET3A);
  SensorGas.setSensorMode(SENS_OFF, SENS_SOCKET3A);
  XBee.println(CO_value);
 
  XBee.println("Sending VOC sensor data after 30 seconds");
  float VOC_value = SensorGas.readValue(SENS_SOCKET2A);
  SensorGas.setSensorMode(SENS_OFF, SENS_SOCKET2A);
  XBee.println(VOC_value);
 
  XBee.println("Sending NO2 sensor data after 30 seconds");
  float NO2_value = SensorGas.readValue(SENS_SOCKET2B);
  SensorGas.setSensorMode(SENS_OFF, SENS_SOCKET2B);
  XBee.println(NO2_value);

  getFormattedVals(sensorData,atp_value,CO_value,VOC_value,NO2_value);
  XBee.println(sensorData);

  sprintf(dataTemp,"%d%s%d%s%s",GPS_Error,sep,temperature_value,sep,sensorData);

  XBee.print("Msg from getValueSensors: ");
  XBee.println(dataTemp);

}

void setup()
{
  SensorGas.setBoardMode(SENS_ON);

  // set GPS on
  GPS.setMode(GPS_ON); 
  XBee.println("Start WASP Deployment");
  // Inits the XBee 802.15.4 library
  xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL); 
  // Powers XBee
  xbee802.ON();   
  //xbee802.setPowerLevel(0); //ideally 0=50m and 4=500m
  XBee.flush();

}

void loop()
{

  // Adding data to the packet to be sent
  XBee.println("");
  XBee.println("COLLECT_SENSOR_DATA ");
  pkt_id = pkt_id+1;       

  char dataTemp[50];
  char data[90];

  getSensorValues(dataTemp);
  sprintf(data,"%s%s%s",msg,sep,dataTemp);

  XBee.println(data);


  // Set params to send
  paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
  paq_sent->mode=UNICAST;
  paq_sent->address_type= 0;
  paq_sent->MY_known = 0;
  paq_sent->opt=0;
  paq_sent->packetID=pkt_id;                                                   

  xbee802.setOriginParams(paq_sent, selfMAC, MAC_TYPE);
  xbee802.setDestinationParams(paq_sent, sinkMAC, data, MAC_TYPE, DATA_ABSOLUTE);


  xbee802.sendXBee(paq_sent);

  if( !xbee802.error_TX )
  {
    XBee.println("ok");
  }
  free(paq_sent);
  paq_sent=NULL;

  xbee802.pos--;
  delay(1000);
  XBee.println("FLUSHING NOW !!");
  XBee.flush();
  XBee.println("FLUSHED !!");
}


2. Apart from this code I am also trying an another code for the same purpose. Here I have managed to use GPS functions properly (Not getting compilation error) and also that GPS starts to initialize but it doesn't work. I see "Setting up GPS..." message and it hangs afterwards.
Another problem with this code is that I don't get any output on wifi whereas USB works well.

Code:
void setup()
{
    // Inits the XBee 802.15.4 library

//USB.begin();

SensorGas.setBoardMode(SENS_ON);
SensorGas.configureSensor(SENS_SOCKET2A,1,1);
SensorGas.setSensorMode(SENS_ON, SENS_SOCKET2A);

SensorGas.setBoardMode(SENS_ON);
SensorGas.configureSensor(SENS_SOCKET2B, 4, 2);
SensorGas.setSensorMode(SENS_ON, SENS_SOCKET2B);

SensorGas.setBoardMode(SENS_ON);
SensorGas.configureSensor(SENS_SOCKET3A,2,3);


}

void loop()
{
  xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL);
 
  // Powers XBee
  xbee802.ON();
XBee.println("The Concentration of CH4 Gas measured is equal to:");
delay(30000);
float val_1 = SensorGas.readValue(SENS_SOCKET2A);
XBee.println(val_1);

XBee.println("The Concentration of No2 Gas measured is equal to:");
delay(30000);
float val_2 = SensorGas.readValue(SENS_SOCKET2B);
XBee.println(val_2);

XBee.println("The Concentration of CO Gas measured is equal to:");
delay(30000);
float val_3 = SensorGas.readValue(SENS_SOCKET3A);
XBee.println(val_3);

XBee.println("Setting up GPS...");
 
  GPS.ON();
 
  // waiting for GPS is connected to satellites
  while( !GPS.check() ) delay(1000);
 
  XBee.println("Connected");

GPS.getPosition(); 
  XBee.println("---------------");
  XBee.print("Time: ");
  XBee.println(GPS.timeGPS);
  XBee.print("Date: ");
  XBee.println(GPS.dateGPS);
  XBee.print("Latitude: ");
  XBee.println(GPS.latitude);
  XBee.print("Longitude: ");
  XBee.println(GPS.longitude);
  XBee.print("Altitude: ");
  XBee.println(GPS.altitude);
  XBee.print("Speed: ");
  XBee.println(GPS.speed);
  XBee.print("Course: ");
  XBee.println(GPS.course);
  XBee.println("---------------");

packetXBee* paq_sent;
int8_t state=0;
long previous=0;
char data[90];
sprintf(data,"%s%s%s%s%s%s%s",val_1,val_2,val_3,GPS.timeGPS,GPS.dateGPS,GPS.latitude,GPS.longitude,GPS.altitude,GPS.speed,GPS.course);
XBee.println(data);

  // Set params to send
  paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
  paq_sent->mode=UNICAST;
  paq_sent->MY_known=0;
  paq_sent->packetID=0x52;
  paq_sent->opt=0;
  xbee802.hops=0;
  xbee802.setOriginParams(paq_sent, "0013A200406A62BC", MAC_TYPE);
  xbee802.setDestinationParams(paq_sent, "0013A200406A6225", data, MAC_TYPE, DATA_ABSOLUTE);
  state=xbee802.sendXBee(paq_sent);
  if(state==0)
  {
    XBee.println("ok");
  }
  free(paq_sent);
  paq_sent=NULL;
  delay (5000);
}


3. I tried to edit AP = 0 but I am getting library error when I run my codes. If you can then please email me the modified WaspXbeeCore.cpp file.
zeus2kx@gmail.com

Sorry for this mess but I must understand how to use it properly before I enjoy working with your device.

Thanks.

Best,


Top
 Profile  
 
 Post subject: Re: Calibrating TGS2611 - Methane Gas
PostPosted: Wed Mar 30, 2011 8:58 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7491
Hi,

First of all, I recommend you to try the GPS examples alone and if they work then mix them with your code.

If you change the API mode from '2' (default) to '0', then it is normal the examples and code fail because the XBee have to be set at '2' to work with our API.

Regards


Top
 Profile  
 
 Post subject: Re: Calibrating TGS2611 - Methane Gas
PostPosted: Sat Mar 30, 2013 10:55 am 

Joined: Mon Mar 11, 2013 1:03 pm
Posts: 5
may i ask will the concentration usually decrease with increase Voutput across RL or otherwise? I ask so I may know the possible correct outcomes... will be heading to the field to get some data.... regards


Top
 Profile  
 
 Post subject: Re: Calibrating TGS2611 - Methane Gas
PostPosted: Mon Apr 01, 2013 9:36 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7491
Hi lee_jun,

TGS2611's resistance decreases with gas concentration, so you'll have an increasing output voltage with an increasing concentration.

Regards.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 2 of 2   [ 16 posts ]
Go to page Previous  1, 2


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use