Pages: [1]   Go Down
Author Topic: [SOLVED]Siemens TC35 serial communication  (Read 1899 times)
0 Members and 1 Guest are viewing this topic.
Terni/Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Dedalo project member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello  smiley
I'm using a Siemens TC35 module to send SMS with Arduino. I wrote  a simple sketch and it works, i can send SMS with analog data from sensors.
Now i want to know when the modem registers on the network, so first of all i send the "AT+CREG=1" command but....how can i see the modem answer on serial monitor? I tried with the following sketch, but it doesn't work. I don't know how serial communication works...  smiley-roll-sweat

Code:
#include <NewSoftSerial.h>
NewSoftSerial cell(7,8);
char inchar;

void setup(){

  Serial.begin(9600);
  cell.begin(9600);
  delay(1000);
  
  }

void loop(){
  cell.print("AT+CREG=1\r\n");
  
  if(cell.available() >0){
     inchar = cell.read();
     Serial.print("Answer1: ");
     Serial.println(inchar);
      }
  delay(2000);

 }

The Answer1 should be "OK"...but i can't see neither "Answer1:" nor "OK".

Can you help me?
« Last Edit: August 09, 2012, 12:59:52 pm by zeroG » Logged

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

Code:
  cell.print("AT+CREG=1\r\n");
You want to send this over and over? If not, it belongs in setup().

Code:
  if(cell.available() >0){
Tests how many bytes of data there are to read.

Code:
     inchar = cell.read();
Reads ONE of them.

Quote
The Answer1 should be "OK"
No, it should be 'O' or 'K', assuming that the TC35 responded to the request. You'll have to look at the documentation, and confirm that +CREG=1 is a valid AT command, and that it causes the phone to generate a response.

Once you know whether the phone has registered, why would you want to send the same command again?
Logged

Terni/Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Dedalo project member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
i don't need to send the command every loop, i put it there to check if it works. After i'll need it to send SMS.
You said that i receive "O" and then "K"...what if i use a cycle to store all chars into an array?
Code:
      for(i=0;i<max;i++){
        inchar[i] = cell.read();
      }

The command AT+CREG=1 is correct, i used the same command list to send SMS, and it worked.
Thanks for your reply
Logged

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

Quote
what if i use a cycle to store all chars into an array?
If you are getting a response at all, that is a good idea. If not, then it won't help.

Don't try to read what hasn't arrived yet.
Logged

Terni/Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Dedalo project member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok i found a solution. The following code may seem stupid, but in this way i understood how serial communication works.

Code:
#include <NewSoftSerial.h>

NewSoftSerial cell(7, 8);
int i=0;

void setup()
{
  cell.begin(9600);
  Serial.begin(9600);
  Serial.println("Starting communications...");
  delay(5000);
}

void loop(){
 
  Serial.print("Loop: ");
  Serial.println(i);            //number of this loop
 
  cell.print("AT\r\n");      //put here the AT command followed by \r\n
     
      while(cell.available()>0){
        Serial.print((char)cell.read());   //reading GSM result
      }
     
  Serial.println("End loop.");
  i++;
  delay(3000);
}

There's a problem: during the first loop (loop 0) there's no results, i start receiving data from loop 1. I tried to put a delay(5000) in the setup, but it doesn't change:
(Serial monitor)

     Loop 0

     End loop

     Loop 1
     AT
     OK
     End loop
     ....

Logged

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

Quote
I tried to put a delay(5000) in the setup, but it doesn't change:
Why, if you want to wait for a reply from the AT command, would you put the delay() BEFORE sending the AT command?
Logged

Terni/Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Dedalo project member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Because maybe the modem needs time to start, i don't know. However, ignore that line...
I'm reading the manual, maybe i'll find something useful to solve this problem.
Logged

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

Well, the hint was there for you to add a delay() AFTER sending the AT command, before trying to read the response.
Logged

Terni/Roma
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
Dedalo project member
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I didn't use this method before because the problem appears only during the first loop.
I solved putting this line after the AT command (n is the loop number):

Code:
cell.print("AT\r\n");
if(n==0)(delay(3000));

Now it works!
Thanks for your help  smiley
« Last Edit: August 09, 2012, 01:43:34 pm by zeroG » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can you give me the part of code to read simply sms to a tc35 board witjh arduino uno ?
Logged

Pages: [1]   Go Up
Jump to: