Pages: [1]   Go Down
Author Topic: If not working, whats misiing  (Read 499 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I only want my gsm to send a text if "stereo" is not found in the buffer.

the LCD is working ok.

is it because my if and sms is not in the same curly brackets as the " stereo = Radio.stereo(buf);"

Code:
if (Radio.read_status(buf) == 1) {
          current_freq =  floor (Radio.frequency_available (buf) / 100000 + .5) / 10;
          stereo = Radio.stereo(buf);
          signal_level = Radio.signal_level(buf);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(current_freq);
          lcd.setCursor(13,0);
          if (stereo) lcd.print(" ST ");
          else lcd.print("MO");
          lcd.setCursor(8,0);
          lcd.print(signal_level *  100 / 16);
          lcd.setCursor(11,0);
          lcd.print("%");
          //lcd.print("/15 " * 100 / 15));
        }

delay(1000);
          if((stereo)&&(smsmuteState == LOW))
         {
           lcd.setCursor(12,1);
          lcd.print("OK"); }
else
         {
        sms.beginSMS("phone number");
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print(" SITE FAULT ! ");
        delay(1000);
        lcd.clear();
        lcd.print("SMS SENDING");
        sms.print("a\xFEgmail.com ");
        sms.print(Names[NameIndex]);
        sms.print("  ");
        sms.print(channel);
        sms.print(" SHUT DOWN");
        sms.endSMS(); 
        lcd.clear();
        lcd.setCursor(0, 1);
        lcd.print("SMS SENT OK");
        delay(5000);
        lcd.clear();
      }
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12062
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Without seeing all the code its pure guesswork, but have you initialized stereo before the first if?
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is my full slightly neater code.

I only want an sms when "stereo" and "smsmute==low"

At the moment it is ignoring the "stereo" bit.

Thanks
Code:
// libraries
#include <GSM.h>
#include <LiquidCrystal.h>
// //#include <Si4703_Breakout.h>
#include <Wire.h>
#include <TEA5767.h>
// from https://github.com/andykarpov/TEA5767
#include <Button.h>
// from http://arduino-info.wikispaces.com/HAL-LibrariesUpdates

// PIN Number
#define PINNUMBER ""
///////////////////////////////  GSM  //////////////////////

// initialize the library instance
GSM gsmAccess;     // include a 'true' parameter to enable debugging
GSM_SMS sms;
GSMVoiceCall vcs;
// Array to hold the number for the incoming call
char numtel[20];


////////////////////////////// TEA5767 /////////////////////
TEA5767 Radio;
double old_frequency;
double frequency;
int search_mode = 0;
int search_direction;
unsigned long last_pressed;
///////////////////////////// LCD //////////////////////////
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 9, 8);

// This section descibes button connection.
const int buttonPin = A0;
const int upbuttPin = A2;
const int downbuttPin = A3;
const int selectPin =  A1;
const int smsmutePin = 6;

///////////freq map//////////////////////

float Freq[][5] ={
  {
    99.5, 89.9 , 91.4, 104.7, 93.6                      }
  ,//Aberdare
  {
    98.3 , 88.7, 90.9, 93.1, 103.5                      }

  ,//Abergavenny
  {
    99.5 , 89.9, 92.1, 94.3, 101.7                   }
  ,//Wenvoe
  {
    98.6 , 89.0, 91.2, 93.4, 104.3                   }
  ,//Abertillery
  {
    98.1 , 88.5, 90.7, 92.9, 104.0                   }
  ,//Blaenavon
  {
    98.5 , 88.9, 91.1, 104.7, 93.3                    }
  ,//Brecon
  {
    98.0 , 88.4, 90.6, 104.6, 92.8                    }
  ,//Carmel
  {
    89.5 , 91.7, 93.9, 96.4, 0                    }
  ,//kvh
  {
    89.5 , 91.7, 93.9, 96.4, 0                    }
  ,//kvh
  {
    89.5 , 91.7, 93.9, 96.4, 0                    }
  ,//kvh
  {
    89.5 , 91.7, 93.9, 96.4, 0                    }
  ,//kvh
  {
    89.5 , 91.7, 93.9, 96.4, 0                    }
  ,//kvh

};
const int NUM_FREQS = sizeof Freq[0]/sizeof Freq[0][0];


// variables will change:
int buttonState = 0;         
int upbuttState = 0;         
int downbuttState = 0;
int selectbuttState = 0;
int smsmuteState = 0;
int select = 0;
float channel;
// Save data variables
String IMEI = "";

// serial monitor result messages
String errortext = "ERROR";


///////////////////////// NAME INDEX ////////////////////////////////
char * Names[] = {
  "Aberdare  ", "Abergavenny  ", "Wenvoe", "Abertillery", "Blaenavon", "Brecon", "Carmel" };
const int NAME_COUNT = sizeof Names / sizeof Names[0];
int NameIndex = 0;

void setup()
{
  { 
    Wire.begin();
    Radio.init();
    //Radio.set_frequency(99.5);
  }

  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   
  pinMode(upbuttPin, INPUT);
  pinMode(downbuttPin, INPUT);
  pinMode(selectPin, INPUT);
  pinMode(smsmutePin, INPUT);

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  Serial.println("Receive Voice Call");
  /////////////////////// LCD BOOT  turn on display? ////////////////////
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("FM Rover by DM");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("--Please  Wait--");
  lcd.setCursor(0, 1);

  lcd.print("-GSM Connecting-");

  //////////////////////// START GSM networks scanner/////////////////////////
  // scannerNetworks.begin();

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
    {
      notConnected = false;
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(" GSM  Connected");
      delay(5000);
      lcd.clear();
    }

    else
    {
      Serial.println("Not connected !");
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("NO GSM !");
      delay(1000);
    }
  }

  vcs.hangCall();

  Serial.println("Waiting for a call");

  ///////////////// SELECT SITE NAME //////////////////////
  while(select==0){
    // read the state of the pushbutton value:
    upbuttState = digitalRead(upbuttPin);
    downbuttState = digitalRead(downbuttPin);
    selectbuttState = digitalRead(selectPin);

    // if it is, the upbuttState is HIGH:
    if (upbuttState == HIGH) {     
      // increment name
      NameIndex = (NameIndex+1)%NAME_COUNT;
    } // Wrap around

    //if it is, the upbuttState is HIGH:
    if (downbuttState == HIGH) {     
      // increment name
      NameIndex = (NameIndex-1)%NAME_COUNT;
      if (NameIndex < 0) {
        NameIndex=NAME_COUNT-1;
      }
    } // Wrap around

    if (selectbuttState == HIGH){
      select=1;
    }
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("> ");
    lcd.setCursor(2,0);
    lcd.print (Names[NameIndex]);
    lcd.setCursor(0,1);
    lcd.print("Select Location ");

    delay(500);
    lcd.clear();
  }
}

void loop()
{
  {

    {

      unsigned char buf[5];
      int stereo;
      int signal_level;
      double current_freq;
      unsigned long current_millis = millis();

      for(int i=0; i<NUM_FREQS; i++) {
        channel=Freq[NameIndex][i];
        Radio.set_frequency(channel);
        lcd.setCursor(0, 0);
        smsmuteState = digitalRead(smsmutePin);
        lcd.setCursor(0, 1);
        lcd.print(Names[NameIndex]);
        delay(10000);



        if (Radio.read_status(buf) == 1) {
          current_freq =  floor (Radio.frequency_available (buf) / 100000 + .5) / 10;
          stereo = Radio.stereo(buf);
          signal_level = Radio.signal_level(buf);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(current_freq);
          lcd.setCursor(6,0);
          lcd.print("MHz");
          lcd.setCursor(13,0);
          if (stereo) lcd.print(" ST ");
          else lcd.print(" MO");
          lcd.setCursor(10,0);
          lcd.print(signal_level *  100 / 16);
          lcd.setCursor(12,0);
          lcd.print("%");

          //}

          delay(1000);
          if((stereo)&&(smsmuteState == HIGH))
          {
          }
          else
            lcd.clear();
          lcd.setCursor(0,1);
          lcd.print("");
          if (smsmuteState == LOW)
          {
            sms.beginSMS("phone number");
            lcd.clear();
            lcd.setCursor(0, 1);
            lcd.print("----- FAULT ------");
            delay(1000);
            lcd.clear();
            lcd.print("SMS SENDING");
            sms.print("\xFEgmail.com ");
            sms.print(Names[NameIndex]);
            sms.print("  ");
            sms.print(channel);
            sms.print(" SHUT DOWN");
            sms.endSMS(); 
            lcd.clear();
            lcd.setCursor(0, 1);
            lcd.print("SMS SENT OK");
            delay(5000);
            lcd.clear();
          }


          if (smsmuteState == HIGH)
            lcd.setCursor(14, 1);
          lcd.print("M!");
          delay(5000);
          lcd.clear();

        }

      }


    }
  }
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26218
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your problem may become clearer to you (and us) if you get rid of of all the useless braces, and apply the auto format tool.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Full Member
***
Karma: 0
Posts: 118
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hows this
Code:
// libraries
#include <GSM.h>
#include <LiquidCrystal.h>
// //#include <Si4703_Breakout.h>
#include <Wire.h>
#include <TEA5767.h>
// from https://github.com/andykarpov/TEA5767
#include <Button.h>
// from http://arduino-info.wikispaces.com/HAL-LibrariesUpdates

// PIN Number
#define PINNUMBER ""
///////////////////////////////  GSM  //////////////////////

// initialize the library instance
GSM gsmAccess;     // include a 'true' parameter to enable debugging
GSM_SMS sms;
GSMVoiceCall vcs;
// Array to hold the number for the incoming call
char numtel[20];


////////////////////////////// TEA5767 /////////////////////
TEA5767 Radio;
double old_frequency;
double frequency;
int search_mode = 0;
int search_direction;
unsigned long last_pressed;
///////////////////////////// LCD //////////////////////////
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 9, 8);

// This section descibes button connection.
const int buttonPin = A0;
const int upbuttPin = A2;
const int downbuttPin = A3;
const int selectPin =  A1;
const int smsmutePin = 6;

///////////freq map//////////////////////

float Freq[][5] ={
  {
    99.5, 89.9 , 91.4, 104.7, 93.6                          }
  ,//Aberdare
  {
    98.3 , 88.7, 90.9, 93.1, 103.5                          }

  ,//Abergavenny
  {
    99.5 , 89.9, 92.1, 94.3, 101.7                       }
  ,//Wenvoe
  {
    98.6 , 89.0, 91.2, 93.4, 104.3                       }
  ,//Abertillery
  {
    98.1 , 88.5, 90.7, 92.9, 104.0                       }
  ,//Blaenavon
  {
    98.5 , 88.9, 91.1, 104.7, 93.3                        }
  ,//Brecon
  {
    98.0 , 88.4, 90.6, 104.6, 92.8                        }
  ,//Carmel
  {
    89.5 , 91.7, 93.9, 96.4, 0                        }
  ,//kvh
  {
    89.5 , 91.7, 93.9, 96.4, 0                        }
  ,//kvh
  {
    89.5 , 91.7, 93.9, 96.4, 0                        }
  ,//kvh
  {
    89.5 , 91.7, 93.9, 96.4, 0                        }
  ,//kvh
  {
    89.5 , 91.7, 93.9, 96.4, 0                        }
  ,//kvh

};
const int NUM_FREQS = sizeof Freq[0]/sizeof Freq[0][0];


// variables will change:
int buttonState = 0;         
int upbuttState = 0;         
int downbuttState = 0;
int selectbuttState = 0;
int smsmuteState = 0;
int select = 0;
float channel;
// Save data variables
String IMEI = "";

// serial monitor result messages
String errortext = "ERROR";


///////////////////////// NAME INDEX ////////////////////////////////
char * Names[] = {
  "Aberdare  ", "Abergavenny  ", "Wenvoe", "Abertillery", "Blaenavon", "Brecon", "Carmel" };
const int NAME_COUNT = sizeof Names / sizeof Names[0];
int NameIndex = 0;

void setup()
{

  Wire.begin();
  Radio.init();
  //Radio.set_frequency(99.5);


  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   
  pinMode(upbuttPin, INPUT);
  pinMode(downbuttPin, INPUT);
  pinMode(selectPin, INPUT);
  pinMode(smsmutePin, INPUT);

  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  /////////////////////// LCD BOOT  turn on display? ////////////////////
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("FM Rover by DM");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("--Please  Wait--");
  lcd.setCursor(0, 1);

  lcd.print("-GSM Connecting-");

  //////////////////////// START GSM networks scanner/////////////////////////
  // scannerNetworks.begin();

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)

    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
    {
      notConnected = false;
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print(" GSM  Connected");
      delay(5000);
      lcd.clear();
    }

    else
    {
      Serial.println("Not connected !");
      lcd.setCursor(0, 1);
      lcd.clear();
      lcd.print("NO GSM !");
      delay(1000);
    }


  vcs.hangCall();

  Serial.println("Waiting for a call");

  ///////////////// SELECT SITE NAME //////////////////////
  while(select==0){
    // read the state of the pushbutton value:
    upbuttState = digitalRead(upbuttPin);
    downbuttState = digitalRead(downbuttPin);
    selectbuttState = digitalRead(selectPin);

    // if it is, the upbuttState is HIGH:
    if (upbuttState == HIGH) {     
      // increment name
      NameIndex = (NameIndex+1)%NAME_COUNT;
    } // Wrap around

    //if it is, the upbuttState is HIGH:
    if (downbuttState == HIGH) {     
      // increment name
      NameIndex = (NameIndex-1)%NAME_COUNT;
      if (NameIndex < 0) {
        NameIndex=NAME_COUNT-1;
      }
    } // Wrap around

    if (selectbuttState == HIGH){
      select=1;
    }
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("> ");
    lcd.setCursor(2,0);
    lcd.print (Names[NameIndex]);
    lcd.setCursor(0,1);
    lcd.print("Select Location ");

    delay(500);
    lcd.clear();
  }
}

void loop()

  //boolean stereo = true;
  unsigned char buf[5];
  int stereo;
  int signal_level;
  double current_freq;
  unsigned long current_millis = millis();

  for(int i=0; i<NUM_FREQS; i++) {
    channel=Freq[NameIndex][i];
    Radio.set_frequency(channel);
    delay(2000);// allow time to tune
    smsmuteState = digitalRead(smsmutePin);
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print(Names[NameIndex]);

    if (Radio.read_status(buf) == 1) {
      current_freq =  floor (Radio.frequency_available (buf) / 100000 + .5) / 10;
      stereo = Radio.stereo(buf);
      signal_level = Radio.signal_level(buf);
      delay(1000); // allow time for buffer ?
      lcd.setCursor(0,0);
      lcd.print(current_freq);
      lcd.setCursor(6,0);
      lcd.print("MHz");
      lcd.setCursor(13,0);
      // if (stereo)
      stereo = true;
      lcd.print(" ST ");
    }
    else
      lcd.print(" MO");
    lcd.setCursor(10,0);
    lcd.print(signal_level *  100 / 16);
    lcd.setCursor(12,0);
    lcd.print("%");
    delay(10000);

    delay(1000);
    if ((stereo)&&(smsmuteState == HIGH))
    {
    }
    else
      lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("");

    if(smsmuteState== LOW)
    {
      sms.beginSMS("cccccccccc42");
      lcd.clear();
      lcd.setCursor(0, 1);
      lcd.print("----- FAULT ------");
      delay(1000);
      lcd.clear();
      lcd.print("SMS SENDING");
      sms.print("cccccccc\xFEgmail.com ");
      sms.print(Names[NameIndex]);
      sms.print("  ");
      sms.print(channel);
      sms.print(" SHUT DOWN");
      sms.endSMS(); 
      lcd.clear();
      lcd.setCursor(0, 1);
      lcd.print("SMS SENT OK");
      delay(5000);
      lcd.clear();
    }


    if (smsmuteState == HIGH)
    {
      lcd.setCursor(14, 1);
      lcd.print("M!");
      delay(5000);
      lcd.clear();
    }
  }
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
  while(notConnected)
While statements should ALWAYS have curly braces, as should if and for statements.

You need to pick a style - the { goes on a new line (my preference) OR the { goes on the statement that introduces the block -  and CONSISTENTLY use that style. Do NOT use both styles in the same sketch.

Code:
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
    {
  while(select==0){
Makes for some difficult to follow code.

Use spaces between the ) and the { if you insist on putting the { on the statement line.

This is not a good idea:
Code:
    if ((stereo)&&(smsmuteState == HIGH))
    {
    }
    else
      lcd.clear();

This does the same thing, and is easier to understand.
Code:
      if(!stereo || smsmuteState == LOW
         lcd.clear();

Nothing here about stereo being true or false...
Code:
    if(smsmuteState== LOW)
    {
      sms.beginSMS("cccccccccc42");

With all that out of the way, you really need to learn about function. If you has a function to send an SMS, you could just call that, and then we could look at the implementation, and determine if that code looked right for unconditionally sending an SMS.

Then, we could look at the conditional call to the function, and see if that looked right. Much simpler to understand and debug code that way. Not to mention much cleaner looking and much simpler to write.
Logged

Idaho, US
Offline Offline
God Member
*****
Karma: 19
Posts: 868
Special User
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is not a good idea:

Code:
    if ((stereo)&&(smsmuteState == HIGH))
    {
    }
    else
      lcd.clear();
I'm with you there...

Quote
This does the same thing, and is easier to understand.

Code:
      if(!stereo || smsmuteState == LOW
         lcd.clear();
...and you lost me again. Shouldn't that be:

Code:
if(!stereo || smsmuteState == LOW)
  {
  lcd.clear();
  }
?

Quote
With all that out of the way, you really need to learn about function.
Agreed.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Shouldn't that be
If there is only one statement to execute, the curly braces are optional. Recommended, but not required.
Logged

Idaho, US
Offline Offline
God Member
*****
Karma: 19
Posts: 868
Special User
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Shouldn't that be
If there is only one statement to execute, the curly braces are optional. Recommended, but not required.
True. However I was thinking of the

Quote
BareMinimum:8: error: expected `)' before 'lcd'

message the compiler reports. smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However I was thinking of the
Picky, procreating picky.
Logged

Idaho, US
Offline Offline
God Member
*****
Karma: 19
Posts: 868
Special User
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However I was thinking of the
Picky, procreating picky.
Being a pedant is sometimes important.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However I was thinking of the
Picky, procreating picky.
Being a pedant is sometimes important.
That made me laugh.
Logged

Pages: [1]   Go Up
Jump to: