Post a new topicPost a reply Page 1 of 1   [ 9 posts ]
Author Message
 Post subject: Gas Sensor Waspmote crashing
PostPosted: Sat Mar 27, 2010 11:51 am 

Joined: Mon Mar 22, 2010 12:28 pm
Posts: 10
Hi

We've been experimenting with a Gas Board connected to a Waspmote with also a GPS and GPRS module attached. Generally we've found it to be quite unstable, particulary during the Gas Sensor Section - see the code below:

Code:
 char data[250];
 int state;
 int node_id;
 int count;
 int humidity, pressure, c02, n02, temperature;
 boolean errorFlag = false;
 
void setup()
{
  //** Start the clock **
  RTC.begin(); // Executes the init process
  //USB.begin();
   
  //** Set up the GPS **
 
   // set GPS on
  GPS.setMode(GPS_ON);
 
  // open the uart
  GPS.begin();
 
  // Inits the GPS module
  GPS.init();
 
  // waiting for GPS is connected to satellites
  //while( !GPS.check() ) delay(1000);
  Utils.blinkLEDs(1000); //1 blink shows that node is on and GPS is working
  //USB.println("GPS Setup");
 
  //Set up params
  node_id = 55;
  count = 0;
 
  //** Set up the gas board **
  SensorGas.setBoardMode(SENS_ON);

  // setup for GPRS seial port
  GPRS.begin();
  GPRS.setMode(GPRS_ON);
  //USB.println("GPRS Setup");
   
  // waiting while GPRS connects to the network
  while(!GPRS.check());
  //USB.println("GPRS Connected to the network");
 
  // configure SMS and Incoming Calls
  if(!GPRS.setInfoIncomingCall()) errorFlag = true;
  if(!GPRS.setInfoIncomingSMS()) errorFlag = true;
  if(!GPRS.setTextModeSMS()) errorFlag = true;
 
  Utils.blinkLEDs(1000); //2 blinks shows that the GPRS is connected and setup
  Utils.blinkLEDs(1000);
 
  delay(1000);
}

void loop()
{
  //USB.println("Start Loop");
  Utils.blinkLEDs(500); //3 blinks indicate start of loop
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);
 
  //** Obtain GPS coords **
  GPS.getLatitude();
  GPS.getLongitude();

  Utils.blinkLEDs(500); //4 blinks for getting GPS Coords
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);

  //** Take gas readings **
  humidity = (int)(1000*SensorGas.readValue(SENS_HUMIDITY));
  delay(500);

  SensorGas.setSensorMode(SENS_ON, SENS_PRESSURE);
  delay(30);
  pressure = (int)(1000*SensorGas.readValue(SENS_PRESSURE));
 
  delay(500);
  SensorGas.configureSensor(SENS_CO2, 100);
  SensorGas.setSensorMode(SENS_ON, SENS_CO2);
  delay(500);
  c02 = (int)(1000*SensorGas.readValue(SENS_CO2));

  SensorGas.setSensorMode(SENS_ON, SENS_NO2);
  delay(500);
  n02 = (int)(1000*SensorGas.readValue(SENS_NO2));
 
  delay(500);
  temperature = (int) (1000*SensorGas.readValue(SENS_TEMPERATURE));
  //USB.println("Data gathered");
 
  Utils.blinkLEDs(500); //5 blinks = sensor reading gathered
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);
   
  sprintf(data,"@@%d,C%d,T%d,B%d,X%s,Y%s,H%d,P%d,A%d,N%d##", node_id, count, temperature, PWR.getBatteryLevel(), GPS.longitude, GPS.latitude, humidity, pressure, c02, n02);
 
  Utils.blinkLEDs(500); //6 blinks indicate data formatted correctly
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);
  Utils.blinkLEDs(500);

  if(GPRS.sendSMS(data,"0783234137"))
  //USB.println("Sending SMS");
  { //Send message to gateway
    Utils.blinkLEDs(500); //7 blinks indicate that SMS was sent
    Utils.blinkLEDs(500);
    Utils.blinkLEDs(500);
    Utils.blinkLEDs(500);
    Utils.blinkLEDs(500);
    Utils.blinkLEDs(500);
    Utils.blinkLEDs(500);
    //USB.println("SMS sent");
  }
 
  delay(20000);
  count++;
}


Are we trying too much? Is there something we're doing wrong in the code?


Top
 Profile  
 
 Post subject: Re: Gas Sensor Waspmote crashing
PostPosted: Sat Mar 27, 2010 12:42 pm 

Joined: Mon Mar 22, 2010 12:28 pm
Posts: 10
OK, with a few more tests, I found that the GPS get methods seemed to be the culprit (even with two GPS modules). Looking at the GPS API documentation, it mentions that the GPS module could time out during these methods. So I've modified the code, as shown below:

Code:

//** Obtain GPS coords **
  if(GPS.flag != GPS_TIMEOUT) GPS.getLatitude();
  if(GPS.flag != GPS_TIMEOUT) GPS.getLongitude();



So if the error flag is set, the Waspmote doesn't try and access the GPS module. Is this correct way to handle the error? Should I rather try and reset the GPS Module if the error flag is set?


Top
 Profile  
 
 Post subject: Re: Gas Sensor Waspmote crashing
PostPosted: Sun Mar 28, 2010 11:41 am 

Joined: Wed Sep 30, 2009 8:48 pm
Posts: 13
Can you try to uncomment this line:

Code:
  // waiting for GPS is connected to satellites
//while( !GPS.check() ) delay(1000);
Utils.blinkLEDs(1000); //1 blink shows that node is on and GPS is working


To this

Code:
  // waiting for GPS is connected to satellites
while( !GPS.check() ) delay(1000);
Utils.blinkLEDs(1000); //1 blink shows that node is on and GPS is working


Maybe your GPS is not propertly ready when you try to use it.


Top
 Profile  
 
 Post subject: Re: Gas Sensor Waspmote crashing
PostPosted: Sun Mar 28, 2010 4:51 pm 

Joined: Mon Mar 22, 2010 12:28 pm
Posts: 10
Hi Marc

Thanks for your suggestion. I did try that, unfortunately with no luck (and hence it got commented out).

As far as I know, that check() method queries the GPS module to see if there is lock with the satellites, which shouldn't be essential for the GPS module responding to the getLatitude and getLongitude modules - if there isn't lock, it should respond with nonsensical coordinates or "0.0".

Cheers,
Gordon


Top
 Profile  
 
 Post subject: Re: Gas Sensor Waspmote crashing
PostPosted: Mon Mar 29, 2010 8:28 am 

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

I've been looking at your code and there is a problem: you are opening UART1 without closing it before opening it.

GPS module and GPRS module share the same UART (UART1) so they can't be used at the same time. You should use one module, and afterwards, use the other one.

So, please try to close 'GPS' before using GPRS to avoid problems.

Best regards


Top
 Profile  
 
 Post subject: Re: Gas Sensor Waspmote crashing
PostPosted: Mon Mar 29, 2010 2:41 pm 

Joined: Mon Mar 22, 2010 12:28 pm
Posts: 10
Hi

Thanks!

Unfortunately the Waspmotes I was working on have gone back to Italy, so I wont be able to test your solution as of yet :( We should be receiving our own soon, so I'll do that when we get it.

Cheers,
Gordon


Top
 Profile  
 
 Post subject: Re: Gas Sensor Waspmote crashing
PostPosted: Sun May 23, 2010 11:47 pm 

Joined: Mon Mar 22, 2010 12:28 pm
Posts: 10
OK, so I am back on the case, after our Waspmotes have finally arrived, and I now have time to work with them:)

I see to be making progress - I'm using the GPS and GPRS begin and close methods to switch between the UART1 mux between the GPS and GPRS modules, and change the baud rate easily. Both modules now respond correctly to their respective status/query messages.

I am still however getting problems with the two of them playing nicely together :( I generally find that I can mutually exclusively get the modules working - either the GPS gets satellite lock, or the GPRS connects to the network, but never both. Having neither working (i.e. no satellite lock and not connected to the cell network), is by far the most common case.

I'm using the following code (modification of the WaspGPS_getCoordinates example):
Code:
void setup(){
  //setup for Serial port
  USB.begin();
 
  // setup the GPS module
  USB.println("Setting up GPS...");
 
  // set GPS on
  GPS.setMode(GPS_ON);
 
  // open the uart
  GPS.begin();
 
  // Inits the GPS module
  GPS.init();
 
  // waiting for GPS is connected to satellites
  //while( !GPS.check() ) delay(1000);
 
  GPS.close();
 
  //GPRS setup
  GPRS.begin();
  GPRS.setMode(GPRS_ON);
  USB.println("Setting up GPRS...");
   
  // waiting while GPRS connects to the network
  //while(!GPRS.check());
  //USB.println("GPRS Connected to the network");
 
  // configure SMS and Incoming Calls
  GPRS.setInfoIncomingCall();
  GPRS.setInfoIncomingSMS();
  GPRS.setTextModeSMS();
  USB.println("GPRS setup");
 
  GPRS.close();
 
}

void loop(){

  // Getting Time
  USB.println("GPS part of Loop");
  GPS.begin();
 
  if (GPS.check()) USB.println("GPS Connected to the network"); //Checks if GPS has satellite lock
 
  GPS.getTime(); 
  USB.print("Time: ");
  USB.println(GPS.timeGPS);

  // Getting Date 
  GPS.getDate();
  USB.print("Date: ");
  USB.println(GPS.dateGPS);
 
  // Getting Latitude 
  GPS.getLatitude();
  USB.print("Latitude: ");
  USB.println(GPS.latitude);

  // Getting Longitude
  GPS.getLongitude();
  USB.print("Longitude: ");
  USB.println(GPS.longitude);

  // Getting Altitude
  GPS.getAltitude();
  USB.print("Altitude: ");
  USB.println(GPS.altitude);
 
  // Getting Speed
  GPS.getSpeed();
  USB.print("Speed: ");
  USB.println(GPS.speed);
 
  // Getting Course 
  GPS.getCourse();
  USB.print("Course: ");
  USB.println(GPS.course);
  GPS.close();
 
 //GPRS Operation
  USB.println("GPRS part of Loop");
  GPRS.begin();
 
  if (GPRS.check()) USB.println("GPRS Connected to the network"); //Tests if GPRS Module is connected to the Network
 
  GPRS.close();
 
}




I suspect that the battery level does play a role - when the battery is at about ~45% things fall apart. Anything I'm doing wrong that is clearly very wrong?


Top
 Profile  
 
 Post subject: Re: Gas Sensor Waspmote crashing
PostPosted: Mon May 24, 2010 9:56 am 

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

GPS and GPRS modules share the same UART so they can't work at the same time.

As you say, the battery is a important matter when we are working with these modules because GPRS is connected directly to the battery and its power consumption is high. It is normal the behavior you mention when the battery is lowly charged.

On the other hand, your code is right, it doesn't seem to be any mistake.

Regards


Top
 Profile  
 
 Post subject: Re: Gas Sensor Waspmote crashing
PostPosted: Mon May 24, 2010 10:10 pm 

Joined: Mon Mar 22, 2010 12:28 pm
Posts: 10
OK, I've charged the battery fully, and the code I posted above seems to be working now. The GPS does take about 15 minutes to get lock.

I'm trying now with some code which actually takes measurements with the GPS and Gas board, and SMSs the results in. I'll report on how it goes.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 9 posts ]


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:
cron


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