• Welcome to LusoRobótica - Robótica em Português.
 

Ajuda Siemens C35i, como o ligar ao arduino, comandos AT.

Started by r16, 11 de August de 2012, 13:12

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

r16


VIDEO DO PROJECTO CONCLUIDO





Viva comprei um C35I, para ligar ao arduino para que este reconheca os comados AT.
Certo porem tou com algumas dificuldades em saber como polo a funcionar , e tambem nas ligacoes que tenho que fazer.

Ora bem eu tenho a minha disposicao resistencias de:

3.3k
2.7k
12k
15k
18k

Eu estive a ver em varios sites como se fazia as ligacoes a ele.

Eu ja descobri o pinout do telemovel e tenho cabo de dados:
1   GND   -   Ground
2   SELF-SERVICE   in/out   Recognition/control battery charger
3   LOAD   in   Charging voltage
4   BATTERY   out   Battery (S25 only)
5   DATA OUT (TX)   out   Data sent
6   DATA IN (RX)   in   Data received
7   Z_CLK   -   Clock line for accessory bus. Use as DCD In data operation
8   Z_DATA   -   Data line for accessory bus. Use as CTS in data operation
9   MICG   -   Ground for microphone
10   MIC   in   Microphone input
11   AUD   out   Loudspeaker
12   AUDG   -   Ground for external speaker

A minha duvida é como montar o esquema na breadboard com as resistencias alguem me pode ajudar?


Encontrei este site mas ele funciona com um siemens c75 logo as ligacoes nao sao iguais nem o pinout:

https://sites.google.com/site/carlosoliveiraprojects/home/arduino/gsm-and-arduino

No entanto tambem descobri este site:
http://www.embeddedrelated.com/groups/basicx/show/22276.php

onde aqui fala de ligar uma resistencia de 12k ao tx e 18k ao rx e ao gnd..se nao efectuar estas ligacoes ja verifiquei que o tlm fica sem apanhar rede pois ele trabalho abaixo dos 5v.

Tou muito confuso se algume me poder ajudar agradecia.

Pedrock

Tens que fazer divisões de voltagem com as resistências.

r16

Como sei como fazer isso? Podes ser mais explicito sff.

Posso te dar mais dados, precisas dos dados da bateria do telemovel? do carregador?

pmj_pedro

Quote from: r16 on 11 de August de 2012, 15:20
Como sei como fazer isso? Podes ser mais explicito sff.

Posso te dar mais dados, precisas dos dados da bateria do telemovel? do carregador?

http://en.wikipedia.org/wiki/Voltage_divider#Resistive_divider

r16

Agradeço as respostas mas as tuas mantem-se, pois não sei como calcular esse valor resistivo,, que dados uso?

Pedrock

Vê a página que o pmj_pedro postou.

Vout = R2 / (R1+R2) * Vin
Substituindo:
3 = 18000 / (12000 + 18000) * 5
3 = 3

Usei os valores daquele site que encontraste, mas podiam ser calculados.
Agora é só montares o esquema que está na página da wikipédia e usas R1 de 12k ohm e R2 de 18k ohm.

r16

ok segundo aqui o rapaz que usa tambem um c35:

ele diz:
"I figured it out, solved the problem doing a voltage divider with a 12K
resistor between basic TX and cellphone RX and another 18K resistor between
cellphone RX and GND."

Segundo o desenho indicado por vós



R1 = 12k
R2 = 18k

TX pino 3 do Arduino
RX pino 2 do Arduino

Fio azul que vem do telemovel TX
Fio Amarelo que vem do telemovel RX

Portanto ai nesse esquema onde diz Vin e Vout onde ligo o fio azul e amarelo que vem do telemovel????

e depois onde ligo os fios do tx e rx que vão para o arduino????

Pedrock

TX significa transmição e RX recepção.

O pino 0 do arduino é o RX e o 1 é o TX.

Tens de ligar TX com RX e RX com TX.

Como o arduino fornece 5v e o telemóvel recebe 3v, usas o divisor de tensão para passar os 5v do TX do arduino para 3v no RX do telemóvel. O TX do telemóvel acho que ligas diretamente ao RX do arduino.

E parece que esse que usou o C35 tem um site com alguma informação:
http://alumni.ipt.pt/~pmad/gsm_alarm.php

r16

Este codigo aqui da para eu testar se os comandos ATestao a funcionar bem?

Acho que é preciso colocar esse INT
em estado=3

e depois basta escrever no serial monitor AT??

/***********************************************************
*                  SMS Alarm 
    This Software uses Arduino connected to a mobile phone(SIEMENS C75)
    and it sends a SMS when a certain amount of light is off (LDR) and it sends
    another (SMS) after light values are restored.
   
    Copyright (C) 2012  Carlos Oliveira

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
***********************************************************/
/*
HARDWARE SETUP

13 -Led pin Debug 13 (used for status)
A2 -Analog input A2 (Light Sensor LDR)
2 -RX (phone) 2
3 -TX (phone) 3

*/
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3


/***********************************************************
*                  PDU encoder setup       
*  Copyright (C) 2010  Daniel Richman
***********************************************************/
/* From hexdump.h ALIEN Project Daniel Richman */
#define num_to_char(number)   ((number) < 10 ?                           \
                                               ('0' + (number)) :        \
                                               (('A' - 10) + (number)) )
/* To select the 4 bits we do this */
#define first_four(byte)       (0x0F & (byte))

/* Last four: Shift left to get to a number < 16 */
#define  last_four(byte)      ((0xF0 & (byte)) >> 4)

/* The MSB goes first. */
#define hexdump_a(byte)  num_to_char( last_four(byte))
#define hexdump_b(byte)  num_to_char(first_four(byte))
/*
*/
//**********************************************************
// End of PDU encoder setup

//init
SoftwareSerial phone=SoftwareSerial(rxPin, txPin);
int ledPin = 13; //Used for DEBUG
int sensorPin = A2; 
int sensorValue = 0;
int estado=0;
//estado=3 for testing serial communication with mobile
boolean flagLUZoff=false;
boolean flagSMS=false;

/***********************************************************
*                  Setup                                   *
***********************************************************/
void setup() 
{
  pinMode(ledPin,OUTPUT); // LED DEBUG
  //Serial -------------------------------------------------
  // Open serial communications and wait for port to open:
  Serial.begin(9600);  // DEBUG
  while (!Serial) {;
  // wait for serial port toconnect.Needed for Leonardo only
  }

  //C75 init ----------------------------------------------
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  phone.begin(9600);

}


/***********************************************************
*                  LOOP                                    *
***********************************************************/
void loop() // run over and over
{
  automatoMain();
}

/***********************************************************
*                  Automato                                *
***********************************************************/

void automatoMain() {

  switch(estado) {
  case 0://check light value
    digitalWrite(ledPin, HIGH); 
    delay(1000);   
    sensorValue = analogRead(sensorPin);
    digitalWrite(ledPin, LOW);
    delay(1000);
    if (sensorValue < 900){
      flagLUZoff=true;
      estado=1;
    }
    else{
      flagLUZoff=false;
      estado=2;
    }

    break;

  case 1:// SMS send Light OFF
    delay(1000);
    if(flagLUZoff && !flagSMS){
    Serial.println("Sending SMS light is OFF"); // DEBUG
    send_sms("351969999999","Light is OFF!");
    flagSMS=true;
    }
    delay(1000);
    estado=0;
    break;

  case 2:// SMS send Light ON
    if(!flagLUZoff && flagSMS){
    Serial.println("Sending SMS light is ON"); // DEBUG
    send_sms("351969999999","Light is ON!");
    flagSMS=false;
    }   
    delay(1000);
    estado=0;
    break;

  case 3://Phone communication tests (via Serial COM)
    if (phone.available())
      Serial.write(phone.read());
    if (Serial.available())
      phone.write(Serial.read());

    break;

  default:
    break;
  }
}

/***********************************************************
*                  SMS PDU encript 

    This part of the code is not written by me, nevertheless I had to
    change some parts (documented) in order to work correctly under
    Arduino V1.0. And also I added a converter function for the phone
    number, but only works for phone number with 12 digits.
   
    code was taken from Tim Zaman site:
    ([url=http://www.timzaman.nl/?p=47&lang=en]http://www.timzaman.nl/?p=47&lang=en[/url])
   
    **********************************************************
   
    Copyright (C) 2010  Daniel Richman (/Timbobel) (/Oliveira)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    For a full copy of the GNU General Public License,
    see . <http://www.gnu.org/licenses/>.
*
***********************************************************/
void hexdump_byte(unsigned char byte)
{
  phone.write(hexdump_a(byte));
  phone.write(hexdump_b(byte));
}

/***********************************************************
*                  convert Phone   (C.Oliveira)                        *
*this only works if your phone number has 12 digits, if not*
*use the old conversion method                             *
***********************************************************/
void convertPhone(char *pho){
  size_t data_length,y;
  data_length = strlen(pho);
  for (y = 0; y < data_length; y=y+2)
    {
      phone.write(pho[y+1]);
      phone.write(pho[y]);
    }
}
//********************************************************** 

void send_sms(char *recPhone, char *data)
{
  size_t data_length, x;
  char l;
  long i;
  long n;

  data_length = strlen(data);
  i = data_length * 7;

  /* Round i up to a multiple of 8 */
  if (i & 0x07) i = (i & ~0x07) + 0x08;

  /* Calculate the number of message octets */
  i = i / 8;

  phone.println("AT+CMGF=0");
  delay(1500);
  phone.print("AT+CMGS="); // Send SMS Comand
  //phone.print("AT+CMGW=");  //Send SMS to mobile draft folder (DEBUG)
  delay(1500);
  phone.println(i + 14); //change it if necessary (see example below) Fixed number for 12 digits phone.
  delay(1500);
 
/* Phone number is hardcoded if digits diferent from 12
   [url=http://twit88.com/home/utility/sms-pdu-encode-decode]http://twit88.com/home/utility/sms-pdu-encode-decode[/url]
  use the utility to convert into pdu format, just fullfil
  the receiver number and press convert button.
  Hexadecimal PDU Message
  below the example for: 351987654321
  output:
  AT+CMGW=14  <--- size of, use above
  0011000C915391785634120000AA
  */
  // phone.print("0011000C915391785634120000AA"); // mobile: 351987654321 OLD METHOD for phones with digits !=12
 
  phone.print("0011000C91"); // using the convertPhone function , for phones # with digits =12       
  convertPhone(recPhone);
  phone.print("0000AA");

  hexdump_byte(data_length & 0xFF);

  l = 0;
  n = 0;

  for (x = 0; x < data_length; x++)
  {
    if (data[x] == '$')  data[x] = 0x02;

    n |= (data[x] & 0x7F) << l;
    l += 7;

    if (l >= 8)
    {
      hexdump_byte(n & 0xFF);
      l -= 8;
      n >>= 8;
    }
  }

  if (l != 0)
  {
    hexdump_byte(n & 0xFF);
  }
  // Code changed for Arduino v1.0
  phone.write(0x1A); // Ctrl+Z
  phone.write(0x0D); // CR
  phone.write(0x0A); // LF
  delay(5000);
 
}


https://sites.google.com/site/carlosoliveiraprojects/home/arduino/gsm-and-arduino

Pedrock

Com esse código, se tirares o comentário ("//") do estado =3, o código fica à espera que envies algo pelo serial para o arduino, que depois é enviado para o telemóvel.
E liga os pinos desta forma:
2 do arduino ao TX do telemóvel
3 do arduino ao RX do telemóvel

EDIT:
Não te esqueças do divisor de voltagem entre o pino 3 e o RX e é preciso colocar uma resistência para limitar a currente entre o pino 2 e o TX.

r16

Bom liguei tudo como esta aqui excepto as resistencias que tao ai na linha roxa onde pus as minhas de 12k e 18k, de resto ta igualzinho.

Mudei aquilo para o estado 3.

E quando envio do serial monitor o comando AT, tal como explica aqui:

1- Send:  AT , received OK , it works!
2- Check the SMS format  (page 27 from AT reference pdf)  , only show a 0, it means that only supports PDU.
3- Just to be sure tried to force Text , but ERROR was received.

AT
OK

AT+CMGF?
+CMGF: 0
OK

AT+CMGF=1
ERROR




Simplesmente nao aparece nada no serial monitor

  :( :( :( :( :( :( :(


PS: nesse site onde tirei esse codigo o rapaz usa um siemens c75 e usou um outro fio que é o:
CTS

Siemens C75 used pinout:
> Vbatt - Power Charging (used for charging).
> Gnd - GND  (main ground).
> Tx   connected to arduino RX (using a resistor to limit current ).
> Rx  connected to arduino TX (using a voltage devider from 5v to ~2,75v).
> CTS  need to be connected to ground in order to work

eu tambem liguei o meu pinout

7   Z_CLK   -   Clock line for accessory bus. Use as DCD In data operation
8   Z_DATA   -   Data line for accessory bus. Use as CTS in data operation

8 mesmo a massa mas mesmo assim nao da.

dropes

Desculpa a intromissão, para inserir código é no sinal # das mensagens e evitam-se listagens grandes assim como símbolos mal interpretados tipo " if (l >= 8)"

Pedrock


r16

Aqui esta ele se houver um outro mais facil..era melhor, mas nao encontrei.
Como podes ver o estado ta em 3


/***********************************************************
*                  SMS Alarm 
    This Software uses Arduino connected to a mobile phone(SIEMENS C75)
    and it sends a SMS when a certain amount of light is off (LDR) and it sends
    another (SMS) after light values are restored.
   
    Copyright (C) 2012  Carlos Oliveira

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
***********************************************************/
/*
HARDWARE SETUP

13 -Led pin Debug 13 (used for status)
A2 -Analog input A2 (Light Sensor LDR)
2 -RX (phone) 2
3 -TX (phone) 3

*/
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3


/***********************************************************
*                  PDU encoder setup       
*  Copyright (C) 2010  Daniel Richman (more in the function)
***********************************************************/
/* From hexdump.h ALIEN Project Daniel Richman */
#define num_to_char(number)   ((number) < 10 ?                           \
                                               ('0' + (number)) :        \
                                               (('A' - 10) + (number)) )
/* To select the 4 bits we do this */
#define first_four(byte)       (0x0F & (byte))

/* Last four: Shift left to get to a number < 16 */
#define  last_four(byte)      ((0xF0 & (byte)) >> 4)

/* The MSB goes first. */
#define hexdump_a(byte)  num_to_char( last_four(byte))
#define hexdump_b(byte)  num_to_char(first_four(byte))
/*
*/
//**********************************************************
// End of PDU encoder setup

//init
SoftwareSerial phone=SoftwareSerial(rxPin, txPin);
int ledPin = 13; //Used for DEBUG
int sensorPin = A2; 
int sensorValue = 0;
int estado=3;
//estado=3 for testing serial communication with mobile;
boolean flagLUZoff=false;
boolean flagSMS=false;

/***********************************************************
*                  Setup                                   *
***********************************************************/
void setup() 
{
  pinMode(ledPin,OUTPUT); // LED DEBUG
  //Serial -------------------------------------------------
  // Open serial communications and wait for port to open:
  Serial.begin(9600);  // DEBUG
  while (!Serial) {;
  // wait for serial port toconnect.Needed for Leonardo only
  }

  //C75 init ----------------------------------------------
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  phone.begin(9600);

}


/***********************************************************
*                  LOOP                                    *
***********************************************************/
void loop() // run over and over
{
  automatoMain();
}

/***********************************************************
*                  Automato                                *
***********************************************************/

void automatoMain() {

  switch(estado) {
  case 0://check light value
    digitalWrite(ledPin, HIGH); 
    delay(1000);   
    sensorValue = analogRead(sensorPin);
    digitalWrite(ledPin, LOW);
    delay(1000);
    if (sensorValue < 900){
      flagLUZoff=true;
      estado=1;
    }
    else{
      flagLUZoff=false;
      estado=2;
    }

    break;

  case 1:// SMS send Light OFF
    delay(1000);
    if(flagLUZoff && !flagSMS){
    Serial.println("Sending SMS light is OFF"); // DEBUG
    send_sms("351964002176","Light is OFF!");
    flagSMS=true;
    }
    delay(1000);
    estado=0;
    break;

  case 2:// SMS send Light ON
    if(!flagLUZoff && flagSMS){
    Serial.println("Sending SMS light is ON"); // DEBUG
    send_sms("351969999999","Light is ON!");
    flagSMS=false;
    }   
    delay(1000);
    estado=0;
    break;

  case 3://Phone communication tests (via Serial COM)
    if (phone.available())
      Serial.write(phone.read());
    if (Serial.available())
      phone.write(Serial.read());

    break;

  default:
    break;
  }
}

/***********************************************************
*                  SMS PDU encript 

    This part of the code is not written by me, nevertheless I had to
    change some parts (documented) in order to work correctly under
    Arduino V1.0. And also I added a converter function for the phone
    number, but only works for phone number with 12 digits.
   
    code was taken from Tim Zaman site:
    (http://www.timzaman.nl/?p=47&lang=en)
   
    **********************************************************
   
    Copyright (C) 2010  Daniel Richman (/Timbobel) (/Oliveira)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    For a full copy of the GNU General Public License,
    see . <http://www.gnu.org/licenses/>.
*
***********************************************************/
void hexdump_byte(unsigned char byte)
{
  phone.write(hexdump_a(byte));
  phone.write(hexdump_b(byte));
}

/***********************************************************
*                  convert Phone   (C.Oliveira)                        *
*this only works if your phone number has 12 digits, if not*
*use the old conversion method                             *
***********************************************************/
void convertPhone(char *pho){
  size_t data_length,y;
  data_length = strlen(pho);
  for (y = 0; y < data_length; y=y+2)
    {
      phone.write(pho[y+1]);
      phone.write(pho[y]);
    }
}
//********************************************************** 

void send_sms(char *recPhone, char *data)
{
  size_t data_length, x;
  char l;
  long i;
  long n;

  data_length = strlen(data);
  i = data_length * 7;

  /* Round i up to a multiple of 8 */
  if (i & 0x07) i = (i & ~0x07) + 0x08;

  /* Calculate the number of message octets */
  i = i / 8;

  phone.println("AT+CMGF=0");
  delay(1500);
  phone.print("AT+CMGS="); // Send SMS Comand
  //phone.print("AT+CMGW=");  //Send SMS to mobile draft folder (DEBUG)
  delay(1500);
  phone.println(i + 14); //change it if necessary (see example below) Fixed number for 12 digits phone.
  delay(1500);
 
/* Phone number is hardcoded if digits diferent from 12
   http://twit88.com/home/utility/sms-pdu-encode-decode
  use the utility to convert into pdu format, just fullfil
  the receiver number and press convert button.
  Hexadecimal PDU Message
  below the example for: 351987654321
  output:
  AT+CMGW=14  <--- size of, use above
  0011000C915391785634120000AA
  */
  // phone.print("0011000C915391785634120000AA"); // mobile: 351987654321 OLD METHOD for phones with digits !=12
 
  phone.print("0011000C91"); // using the convertPhone function , for phones # with digits =12, like all numbers in Portugal.
  convertPhone(recPhone);
  phone.print("0000AA");

  hexdump_byte(data_length & 0xFF);

  l = 0;
  n = 0;

  for (x = 0; x < data_length; x++)
  {
    if (data[x] == '$')  data[x] = 0x02;

    n |= (data[x] & 0x7F) << l;
    l += 7;

    if (l >= 8)
    {
      hexdump_byte(n & 0xFF);
      l -= 8;
      n >>= 8;
    }
  }

  if (l != 0)
  {
    hexdump_byte(n & 0xFF);
  }
  // Code changed for Arduino v1.0
  phone.write(0x1A); // Ctrl+Z
  phone.write(0x0D); // CR
  phone.write(0x0A); // LF
  delay(5000);
 
}

Pedrock

Para fazer esses testes basta este código:
/*
HARDWARE SETUP
13 -Led pin Debug 13 (used for status)
2 -RX (phone) 2
3 -TX (phone) 3
*/

#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3

#define ledPin 13 //Used for DEBUG

SoftwareSerial phone = SoftwareSerial(rxPin, txPin);

void setup() 
{
  pinMode(ledPin,OUTPUT); // LED DEBUG
  //Serial -------------------------------------------------
  // Open serial communications and wait for port to open:
  Serial.begin(9600);  // DEBUG
  while (!Serial) {;
  // wait for serial port to connect.Needed for Leonardo only
  }
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);
  phone.begin(9600);
}

void loop() // run over and over
{
  if (phone.available()) Serial.write(phone.read());
  if (Serial.available()) phone.write(Serial.read());
}


Mas não vai fazer diferença. Acho que o problema não está no código e sim no hardware.