I am trying to build this instructable but using some different components. Instead of just the ATmega chip i put in a Arduino Pro mini.
I would like to alter the way the GSM module is powered but having trouble with the code. Whatever i try to do, can’t get it right. Original code:
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#define power_pin 4 //Pin used to power GSM module on and off.
#define config_switch_pin 7 //Pin to read configuration
#define SMS_waiting_threshold 45000 //How long the module will stay on after notification in order to receive potential configured number
#define SMS_TIMEOUT_THRESHOLD 15000 //The time that the program waits for a send acknowledgement of an SMS
#define batt_pin A0 //Pin for battery level measurement
#define wake_pin 2 //Pin used for waking up
SoftwareSerial mySerial(8, 9); // RX, TX
String number = "+xxxxxxxxxxx"; //Set default number to call - in case none is programmed in the EEPROM yet
int start; //Variable used to start counting time for timeouts
String text; //Variable used for serial communication with the GSM module
float battery_level;
void setup()
{
battery_level = ((analogRead(batt_pin) / 1024.0) * 5.0); //Measure battery level before we start consuming more power and scale it to 5V
//Serial.begin(19200);
mySerial.begin(19200);
pinMode(power_pin, OUTPUT);
pinMode(wake_pin, INPUT_PULLUP); //We'll use internal pull-up resistors to simplify the breadboard layout
pinMode(config_switch_pin, INPUT);
attachInterrupt(0, wakeUpNow, HIGH); //Use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW
MCUSR = 0; //Pre-configure WDT
number = get_number(); //Obtain number from EEPROM
power_GSM(1); //Power up the GSM module
while (get_net_status()=="NC") { //Check every 1 second if the GSM module has registered in the network
//Serial.println(F("Waiting for GSM"));
delay(1000);
}
//Serial.println(get_net_status()); //Print network name that the GSM module has registered to
sendSMS(); //Send the SMS with mail notification
//receive_SMS(); //You may need to call it once to configure SMS mode on your module. Make sure to uncomment the body as well.
start = millis();
}
void loop() { //This function will loop if the SPDT switch is set to config mode.
text.reserve(100); //This saves memory on the micro
text="";
while (mySerial.available()) { //Message format is: +CMT: "+xxxxxxxxxxxx","", yy/mm/dd,12:"h:mm+ss"\r TEXT
text.concat((char) (mySerial.read()));
}
//if (text!="") {Serial.println(text);} //Print what arrived from the GSM module
mySerial.flush(); //Wait for transmissions to finish
//while (Serial.available()) { //Uncomment this if you want to be able to sent AT commands to your module in config mode
// mySerial.write(//Serial.read());
//}
mySerial.flush();
//Serial.flush();
if (text.indexOf("+CMT")!=-1) { //New text message arrived
//Serial.println("New config sms!");
String msg = text.substring(text.lastIndexOf("\"")+3, text.length()-1); //Get message content
msg.trim();
String tel_number = text.substring(text.indexOf("\"")+1, text.indexOf("\"", text.indexOf("\"")+1)); //Get phone number
tel_number.trim();
if ((msg.equals(String("PROGRAM"))) && (tel_number != number)) { //The message contains content that programs a new phone number to be used for notifications
program_number(tel_number);
} else {
//Serial.println("Unrecognized SMS");
delay(1000);
}
}
if ((millis() - start > SMS_waiting_threshold) || digitalRead(config_switch_pin) == 0) { //If SPDT switch is not in config mode, go to sleep. Otherwise wait for timeout and then sleep. Before timeout the chip awaits for a new SMS and responds to AT commands over serial
//Serial.println("Going to sleep");
power_GSM(0); //Power down the GSM module to save battery
sleepNow(); //Sleep function called here
}
delay(50);
}
Sorry, you are right. Quite new to this and i am reading and trying.
I tried many things but this is the last version.
The #define powerpin from the original should be removed i guess but it exits before that one brings me in trouble:
exit status 1
‘SIM900power’ was not declared in this scope
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <call.h>
#include <gps.h>
#include <GSM.h>
#include <HWSerial.h>
#include <LOG.h>
#include <SIM900.h>
#include <sms.h>
#include <WideTextFinder.h>
#define power_pin 4 //Pin used to power GSM module on and off.
#define config_switch_pin 7 //Pin to read configuration
#define SMS_waiting_threshold 45000 //How long the module will stay on after notification in order to receive potential configured number
#define SMS_TIMEOUT_THRESHOLD 15000 //The time that the program waits for a send acknowledgement of an SMS
#define batt_pin A0 //Pin for battery level measurement
#define wake_pin 2 //Pin used for waking up
SoftwareSerial mySerial(8, 9); // RX, TX
String number = "+xxxxxxxxxxxxx"; //Set default number to call - in case none is programmed in the EEPROM yet
int start; //Variable used to start counting time for timeouts
String text; //Variable used for serial communication with the GSM module
float battery_level;
void setup()
{
battery_level = ((analogRead(batt_pin) / 1024.0) * 5.0); //Measure battery level before we start consuming more power and scale it to 5V
//Serial.begin(19200);
mySerial.begin(19200);
SIM900power();
delay(20000); // give time to log on to network.
void SIM900power()
// software equivalent of pressing the GSM shield "power" button
{
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(4, LOW);
delay(5000);
}
pinMode(power_pin, OUTPUT);
pinMode(wake_pin, INPUT_PULLUP); //We'll use internal pull-up resistors to simplify the breadboard layout
pinMode(config_switch_pin, INPUT);
attachInterrupt(0, wakeUpNow, HIGH); //Use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW
MCUSR = 0; //Pre-configure WDT
number = get_number(); //Obtain number from EEPROM
power_GSM(1); //Power up the GSM module
while (get_net_status()=="NC") { //Check every 1 second if the GSM module has registered in the network
//Serial.println(F("Waiting for GSM"));
delay(1000);
}
//Serial.println(get_net_status()); //Print network name that the GSM module has registered to
sendSMS(); //Send the SMS with mail notification
//receive_SMS(); //You may need to call it once to configure SMS mode on your module. Make sure to uncomment the body as well.
start = millis();
}
void loop() {
Did some reading, reading and some more reading. Got rid of the earlier error.
It probably it’s all beginners errors but hey…the Instructable just didn’t look that difficult and i want it to work a bit cleaner than just hard power off/on the GSM module.
The error: exit status 1 expected constructor, destructor, or type conversion before ‘(’ token
I compared it to some other sketch examples but don’t see why its wrong:
#include <SoftwareSerial.h>
#include <EEPROM.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include <call.h>
#include <GSM.h>
#include <SIM900.h>
#include <sms.h>
#include <WideTextFinder.h>
#define power_pin 4
#define config_switch_pin 7 //Pin to read configuration
#define SMS_waiting_threshold 45000 //How long the module will stay on after notification in order to receive potential configured number
#define SMS_TIMEOUT_THRESHOLD 15000 //The time that the program waits for a send acknowledgement of an SMS
#define batt_pin A0 //Pin for battery level measurement
#define wake_pin 2 //Pin used for waking up
SoftwareSerial mySerial(8, 9); // RX, TX
String number = "+xxxxxxxxxxxx"; //Set default number to call - in case none is programmed in the EEPROM yet
int start; //Variable used to start counting time for timeouts
String text; //Variable used for serial communication with the GSM module
float battery_level;
void setup()
{
battery_level = ((analogRead(batt_pin) / 1024.0) * 5.0); //Measure battery level before we start consuming more power and scale it to 5V
//Serial.begin(19200);
mySerial.begin(19200);
}
void SIM900power() // software equivalent of pressing the GSM shield "power" button
{
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(4, LOW);
delay(5000);
}
pinMode(power_pin, OUTPUT);
pinMode(wake_pin, INPUT_PULLUP); //We'll use internal pull-up resistors to simplify the breadboard layout
pinMode(config_switch_pin, INPUT);
attachInterrupt(0, wakeUpNow, HIGH); //Use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW
MCUSR = 0; //Pre-configure WDT
number = get_number(); //Obtain number from EEPROM
SIM900power(); //Power up the GSM module
[color=red]delay(20000); // give time to log on to network.[/color]
}
while (get_net_status()=="NC") { //Check every 1 second if the GSM module has registered in the network
//Serial.println(F("Waiting for GSM"));
delay(1000);
}
void setup()
{
battery_level = ((analogRead(batt_pin) / 1024.0) * 5.0); //Measure battery level before we start consuming more power and scale it to 5V
//Serial.begin(19200);
mySerial.begin(19200);
pinMode(power_pin, OUTPUT);
pinMode(wake_pin, INPUT_PULLUP); //We'll use internal pull-up resistors to simplify the breadboard layout
pinMode(config_switch_pin, INPUT);
attachInterrupt(0, wakeUpNow, HIGH); //Use interrupt 0 (pin 2) and run function wakeUpNow when pin 2 gets LOW
MCUSR = 0; //Pre-configure WDT
number = get_number(); //Obtain number from EEPROM
SIM900power(); //Power up the GSM module
delay(20000);
while (get_net_status()=="NC") { //Check every 1 second if the GSM module has registered in the network
//Serial.println(F("Waiting for GSM"));
delay(1000);
}
//Serial.println(get_net_status()); //Print network name that the GSM module has registered to
sendSMS(); //Send the SMS with mail notification
//receive_SMS(); //You may need to call it once to configure SMS mode on your module. Make sure to uncomment the body as well.
start = millis();
}
void SIM900power()
{
digitalWrite(4, HIGH);
delay(1000);
digitalWrite(4, LOW);
delay(5000);
}
Now only find out if i place things in the right order....
Thx for all the kind help.