Hola, tengo un proyecto de discriminador de llamadas telefónicas usando un Arduino Uno R3, un modem, un modulo serie y una tarjeta SD. El sistema lee los números que llaman, los compara con los almacenados en un fichero de la tarjeta SD y si coinciden, bloquea la llamada. El sistema funciona perfectamente. Pero le he intentado añadir una funcionalidad mas, grabar los números de llamadas recibidas, leerlos y grabarlos en el fichero de números bloqueados. Para ello estoy usando un keypad shied que lleva un LCD 16x02 por el que puedo ver los números llamantes, elegirlos y bloquearlos. El problema está en que cada vez que intento activar el Void que lanza el sistema de botonadura buttonselect(), el sistema deja de ejecutar el código que lee los números bloqueados, no importa que lo coloque tras un if condicional que impida que se ejecute hasta que todos los números del fichero hayan sido leídos, lo sigue haciendo. He comprobado colocando puntos de impresion de sucesos en el LCD que el bucle de lectura se ejecuta perfectamente, pero parece que el sistema " if(strcmp(charBuf, charBuf2)" no se ejecuta en presencia de buttonselect(). Os dejo el codigo (en dos post ya que no cabe en uno solo):
/* Proyecto de discriminador de llamadas telefonicas no deseadas, tras la llamada se identifica el
numero llamante y se compara con los que están anotados en un fichero almacenado en una tarjeta SD.
El hardware necesario es un Arduino Uno, un modem con CallerID (en mi caso US Robotics 56k), un modulo
SD YL-30, una tarjeta SD, un modulo Serie RS232 y un cable serie modem nulo.
El cable serie modem nulo permite obviar el comportamiento del modem en respuesta a la lineas RTS-CTS,
DTR-DSR, las cuales se unen en los extremos de cada conector, cruzándose las lineas TX-RX y
uniendo las GND entre si.
*/
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include <SD.h> //CS en pin 4
SoftwareSerial mySerial(8, 9); // RX, TX
// select the pins used on the LCD panel
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// Guardamos en que entrada de arduino esta conectado el pin CS del modulo.
const int chipSelect = 10;
char nmbrstring[ ] = "NMBR";
char numerodete[20];
char numerotst[20];
char numllam[20];
char charBuf[50];
char charBuf2[50];
int numblock = 50;//cantidad de lineas de numeros del fichero
File myFile2; //fichero llamadas recibidas
int llamadas = 0;
File myFile3; //grabacion fichero llamadas recibidas
int i2 = 0;
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
// For V1.1 us this threshold
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 250) return btnUP;
if (adc_key_in < 450) return btnDOWN;
if (adc_key_in < 650) return btnLEFT;
if (adc_key_in < 850) return btnSELECT;
// For V1.0 comment the other threshold and use the one below:
/*
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
*/
return btnNONE; // when all others fail, return this...
}
// FIN READ BUTTONS
//Sistema de lectura del puerto serie
int readline(int readch, char *buffer, int len)
{
static int pos = 0;
int rpos;
if (readch > 0) {
switch (readch) {
case '\n': // Ignore new-lines
break;
case '\r': // Return on CR
rpos = pos;
pos = 0; // Reset position index ready for next time
return rpos;
default:
if (pos < len-1) {
buffer[pos++] = readch;
buffer[pos] = 0;
}
}
}
// No end of line has been found, so return -1.
return -1;
}
// fin programa lectura puerto serie
void setup()
{
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
lcd.print("LCD Activado"); // print a simple messag
delay (2000);
// Configuramos el puerto serie para informar de fallos a traves de el.
Serial.begin(9600);
// Configuramos el puerto serie virtual para comunicarnos con el modem.
mySerial.begin(9600);
//Serial.println("Setup is Ready\n");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Setup is Ready");
lcd.setCursor(0,1);
lcd.print("Starting....");
// Iniciamos los comandos Hayes para configurar el modem
mySerial.write("ATZ\r\n");
delay(4000);
//mySerial.write("AT+VCID=1\r\n");//Conceptronics CID ON
mySerial.write("AT#CID=1\r\n");//USR Robotics CID ON
delay(2000);
mySerial.write("ATS7=5\r\n");//USR Robotics Answer Wait 7 seg
delay(2000);
mySerial.write("ATS0=0\r\n");//USR Robotics Auto Answer OFF
delay(2000);
//Iniciamos la SD
//Serial.print("Iniciando SD...");
//Serial.print("\n");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Iniciando SD...");
// El pin CS por defecto de la placa arduino debe ser configurado como salida
// aunque no se use (10 en la mayoria de las placas, 53 en Arduino Mega).
pinMode(10, OUTPUT);
// Si ha habido error al leer la tarjeta informamos por el puerto serie.
if (!SD.begin(chipSelect)) {
//Serial.println("Error inicializar SD!");
lcd.setCursor(0,1);
lcd.print("Error ini.SD!");
return;
}
//Serial.print("SD inicializada...OK");
//Serial.print("\n");
lcd.setCursor(0,1);
lcd.print("SD ini...OK");
delay(2000);
if (SD.exists("RECIB.TXT")){
lcd.setCursor(0,1);
lcd.print("RECIB.TXT exists");
SD.open("RECIB.TXT", FILE_WRITE).close();
}
//else {File Archivo1;
//Archivo1 = SD.open("RECIB.TXT", FILE_WRITE);
//SD.open("RECIB.TXT", FILE_WRITE).close();}
delay(2000);
if (SD.exists("test.txt")){
lcd.setCursor(0,1);
lcd.print("test.txt exists");
SD.open("test.txt", FILE_WRITE).close();
}
// else {File Archivo1;
// Archivo1 = SD.open("test.txt", FILE_WRITE);
//SD.open("test.txt", FILE_WRITE).close();}
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Waiting call...");
}