0

I am programming Arduino UNO for this functionality: with use of SD card reader module and SIM900 GSM/GPRS shield I am trying to: 1. Pick up incomming call, play message from SD file and after the message ends, hang up. 2. Call from Arduino to defined telephone number, after the call is picked up, play message and after the message ends, hang up. 3. In case of outcomming call (arduino calls to defined number) and its declined or not picked up, Arduino makes another try for a total of 3 tries. 4. I want to play the message in Czech language OR English message, based on pushed/unpushed button.

Its all working, but number 4. the button for language switch is not working. If I place in code another "digitalRead(pin)" Arduino does all the stuff but does not play the message - its silent on the other end. If I delete this line of code, it is working. So the functionality is good, but the language switch is not working. I have tried to switch it to Global/Local variables, tried to put it straight into the If statement. Everything is wrong.

Any ideas? Thank you.

Code:

#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <SD.h>
#include <TMRpcm.h>
#include "SPI.h"

#define SD_ChipSelectPin 10
#define PIN_TX    7
#define PIN_RX    8
#define BAUDRATE  9600
#define MESSAGE_LENGTH 20

GPRS gprs(PIN_TX, PIN_RX, BAUDRATE);
TMRpcm tmrpcm;

char telefon[] = "999999999";
//char *s = NULL;
char englishMessage[] = "Hlas6en.wav";
char czechMessage[] = "Hlas6cz.wav";//"Hlas6cz.wav";
char gprsBuffer[64];
//char in_number[16] = {0};

unsigned long englishMessageTime = 11000;
unsigned long czechMessageTime = 11000;

int callRetry = 2; //pocet pokusu opakovaneho telefonatu
//int i = 1;
//int inComing = 0;

bool callPrev = false;
bool callAct = false;
bool call = false;

uint8_t PIN_RST = 2;
int PIN_INPUT = 4;
//int LANGUAGE_INPUT = 6;
bool languageSwitch = HIGH;

void setup()
{
  pinMode(PIN_INPUT, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);

  Serial.begin(BAUDRATE);
  //delay(10000); //NECHAT!

  while (!gprs.init())
  {
    Serial.println("SIM 900 - INIT ERROR");
    gprs.powerReset(PIN_RST);
    delay(7000);
  }

  while (!SD.begin(SD_ChipSelectPin))//SD_ChipSelectPin
  {
    Serial.println("SD fail");
    delay(1000);
    //return;
  }
  Serial.println("Zapnuto.");
  tmrpcm.speakerPin = 9;
  tmrpcm.setVolume(5);
  //sim900_clean_buffer(gprsBuffer, 32);
  //gprs.callUp(telefon);
  //languageSwitch = digitalRead(3);
}

void loop() {
  if ((gprs.readable()) || call)
  {
    sim900_read_buffer(gprsBuffer, 32, DEFAULT_TIMEOUT);
    Serial.print(gprsBuffer);
    if (NULL != strstr(gprsBuffer, "OK"))
    {
      Serial.println("Hovor prijat.");
      playAudio();
      Serial.println("Zprava prehrana, pokladam.");
      gprs.hangup();
      callRetry = 2;
    }
    else if (NULL != strstr(gprsBuffer, "RING"))
    {
      Serial.println("Prijimam prichozi hovor.");
      gprs.answer(); //zvednuti telefonu v pripade prichoziho hovoru
      callRetry = 2;
    }

    else if ((NULL != strstr(gprsBuffer, "BUSY")) || call)
    {

      if (callRetry == 0)
      {
        callRetry = 2;
        Serial.println("Nedovolal jsem se.");
      }
      else if ((callRetry > 0) && (!call))
      {
        Serial.print("Zbyva pocet pokusu:");
        Serial.println(callRetry - 1);
        gprs.callUp(telefon); //Opakovane volani v pripade polozeni
        callRetry--;
      }
      else if ((callRetry == 2) && (call))
      {
        gprs.callUp(telefon);
        Serial.println("Volam");
      }
      call = false;
    }
    //smazani bufferu
    sim900_clean_buffer(gprsBuffer, 32);
  }
  callPrev = callAct;
  callAct = !digitalRead(PIN_INPUT);
  //languageSwitch = digitalRead(3);
  call = !callPrev && callAct;
  //languageSwitch=digitalRead(LANGUAGE_INPUT);
  delay(1000);
  Serial.println(call);
  //Serial.println(languageSwitch);
}

void playAudio()
{
  bool languageSwitch = digitalRead(3); //PROBLEM!!!
  tmrpcm.speakerPin = 9;
  if (!SD.begin(SD_ChipSelectPin))//SD_ChipSelectPin
  {
    Serial.println("SD fail");
    return;
  }
  Serial.println("Prehravani zpravy.");
  tmrpcm.setVolume(5);
  if (languageSwitch==HIGH)
  {
    Serial.println("Prehravam zpravu v cestine");
    tmrpcm.play(czechMessage);//czechMessage
    delay(czechMessageTime);
  }
  else
  {
    Serial.println("Prehravam zpravu v anglictine");
    tmrpcm.play(englishMessage);//englishMessage
    delay(englishMessageTime);
  }
  return;
}
  • How is the button connected to the Arduino? Do you have a pullup/down resistor, can you show a schematic? – Maximilian Gerhardt Aug 26 at 21:55
  • As you can see, the pin is initialized in pinmode input_pullup so if there is nothing connected it should be all time high. And it is. If I use println with the pin state it represents the correct state ,it just does not play the message from SD. – Jasmin Jatić Aug 27 at 7:45
  • But you said you execute the tmrpcm.play(czechMessage); yourself it does play the sound, so only inside playAudio() the digitalRead doesn't work? Is it stuck to always the same value or random? – Maximilian Gerhardt Aug 27 at 10:55
  • It doesn't matter where the digital read is. If it is present in the loop or inside the playAudio() function. If it is present anywhere the message - sound is not playing. If you delete the digitalRead sound is playing properly. – Jasmin Jatić Aug 27 at 14:01
  • Otherwise the digitalRead is working properly - high on unpressed button, low on pressed button. It just mess up the play of the audio message. – Jasmin Jatić Aug 27 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.