zs1621 发表于 2014-2-8 15:30:51

用GPS/GSM/GPRS shield V3.0 三合一模块接收数据的问题

本帖最后由 zs1621 于 2014-2-8 15:34 编辑

参考 https://www.dfrobot.com.cn/commun ... d=631&highlight=gps 此贴后无果, 没办法 再发个帖子, 求解
代码参考// Product name: GPS/GPRS/GSM Module V3.0
// # Product SKU : TEL0051
// # Version   : 0.1

// # Description:
// # The sketch for driving the gps mode via the Arduino board

// # Steps:
// #      1. Turn the S1 switch to the Prog(right side)
// #      2. Turn the S2 switch to the Arduino side(left side)
// #      3. Take off the GSM/GPS jumper caps from the Uart select
// #      4. Upload the sketch to the Arduino board
// #      5. Turn the S1 switch to the comm(left side)
// #      6. Remove the jumpers(old version) or set the UART select switch to middle.
// #      7. RST the board

// #      If you get 'inf' values, go outdoors and wait until it is connected.
// #      wiki link- http://www.dfrobot.com/wiki/index.php/GPS/GPRS/GSM_Module_V3.0_(SKU:TEL0051)

double Datatransfer(char *data_buf,char num)//convert the data to the float type
{                                           //*data_buf:the data array                                       
double temp=0.0;                           //the number of the right of a decimal point
unsigned char i,j;

if(data_buf=='-')
{
    i=1;
    //process the data array
    while(data_buf!='.')
      temp=temp*10+(data_buf-0x30);
    for(j=0;j<num;j++)
      temp=temp*10+(data_buf[++i]-0x30);
    //convert the int type to the float type
    for(j=0;j<num;j++)
      temp=temp/10;
    //convert to the negative numbe
    temp=0-temp;
}
else//for the positive number
{
    i=0;
    while(data_buf!='.')
      temp=temp*10+(data_buf-0x30);
    for(j=0;j<num;j++)
      temp=temp*10+(data_buf[++i]-0x30);
    for(j=0;j<num;j++)
      temp=temp/10 ;
}
return temp;
}

char ID()//Match the ID commands
{
char i=0;
char value={
    '

我在ID() 函数中输出了 Serial.available(), 这个值一直为0, 这个值为0能说明什么?




,'G','P','G','G','A'    };//match the gps protocol
char val={
    '0','0','0','0','0','0'    };

while(1)
{
    if(Serial.available())
    {
      val = Serial.read();//get the data from the serial interface
      if(val==value) //Match the protocol
      {   
      i++;
      if(i==6)
      {
          i=0;
          return 1;//break out after get the command
      }
      }
      else
      i=0;
    }
}
}

void comma(char num)//get ','
{   
char val;
char count=0;//count the number of ','

while(1)
{
    if(Serial.available())
    {
      val = Serial.read();
      if(val==',')
      count++;
    }
    if(count==num)//if the command is right, run return
      return;
}

}
void UTC()//get the UTC data -- the time
{
char i;
char time={
    '0','0','0','0','0','0','0','0','0'
};
double t=0.0;

if( ID())//check ID
{
    comma(1);//remove 1 ','
    //get the datas after headers
    while(1)
    {
      if(Serial.available())
      {
      time = Serial.read();
      i++;
      }
      if(i==9)
      {
      i=0;
      t=Datatransfer(time,2);//convert data
      t=t+80000.00;//convert to the chinese time GMT+8 Time zone
      Serial.println(t);//Print data
      return;
      }
    }
}
}
void latitude()//get latitude
{
char i;
char lat={
    '0','0','0','0','0','0','0','0','0','0'
};


if( ID())
{
    comma(2);
    while(1)
    {
      if(Serial.available())
      {
      lat = Serial.read();
      i++;
      }
      if(i==10)
      {
      i=0;
      Serial.println(Datatransfer(lat,5),5);//print latitude
      return;
      }
    }
}
}
void lat_dir()//get dimensions
{
char i=0,val;

if( ID())
{
    comma(3);
    while(1)
    {
      if(Serial.available())
      {
      val = Serial.read();
      Serial.write(val);
      Serial.println();
      i++;
      }
      if(i==1)
      {
      i=0;
      return;
      }
    }
}
}
void longitude()//get longitude
{
char i;
char lon={
    '0','0','0','0','0','0','0','0','0','0','0'
};

if( ID())
{
    comma(4);
    while(1)
    {
      if(Serial.available())
      {
      lon = Serial.read();
      i++;
      }
      if(i==11)
      {
      i=0;
      Serial.println(Datatransfer(lon,5),5);
      return;
      }
    }
}
}
void lon_dir()//get direction data
{
char i=0,val;

if( ID())
{
    comma(5);
    while(1)
    {
      if(Serial.available())
      {
      val = Serial.read();
      Serial.write(val); //Serial.println(val,BYTE);
      Serial.println();
      i++;
      }
      if(i==1)
      {
      i=0;
      return;
      }
    }
}
}
void altitude()//get altitude data
{
char i,flag=0;
char alt={
    '0','0','0','0','0','0','0','0'
};

if( ID())
{
    comma(9);
    while(1)
    {
      if(Serial.available())
      {
      alt = Serial.read();
      if(alt==',')
          flag=1;
      else
          i++;
      }
      if(flag)
      {
      i=0;
      Serial.println(Datatransfer(alt,1),1);//print altitude data
      return;
      }
    }
}
}
void setup()
{
pinMode(3,OUTPUT);//The default digital driver pins for the GSM and GPS mode
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
digitalWrite(5,HIGH);
delay(1500);
digitalWrite(5,LOW);

digitalWrite(3,LOW);//Enable GSM mode
digitalWrite(4,HIGH);//Disable GPS mode
delay(2000);
Serial.begin(9600);
delay(5000);//GPS ready

Serial.println("AT");   
delay(2000);
//turn on GPS power supply
Serial.println("AT+CGPSPWR=1");
delay(1000);
//reset GPS in autonomy mode
Serial.println("AT+CGPSRST=1");
delay(1000);

digitalWrite(4,LOW);//Enable GPS mode
digitalWrite(3,HIGH);//Disable GSM mode
delay(2000);

Serial.println("$GPGGA statement information: ");
}
void loop()
{
while(1)
{
    Serial.print("UTC:");
    UTC();
    Serial.print("Lat:");
    latitude();
    Serial.print("Dir:");
    lat_dir();
    Serial.print("Lon:");
    longitude();
    Serial.print("Dir:");
    lon_dir();
    Serial.print("Alt:");
    altitude();
    Serial.println(' ');
    Serial.println(' ');
}
}

我在ID() 函数中输出了 Serial.available(), 这个值一直为0, 这个值为0能说明什么?




Phoebe 发表于 2014-2-9 22:16:21

把天线放到室外了吗?要等上一段时间。现在串口输出的数据是什么?

zs1621 发表于 2014-2-10 15:01:31

Phoebe 发表于 2014-2-9 22:16
把天线放到室外了吗?要等上一段时间。现在串口输出的数据是什么?

通过usb连接模块可以读到数据的(drive gps via usb port), 但是把程序烧进arduino(drive gps via arduino),通过coolterm读到   串口(Serial.read()) 的数据是-1

zs1621 发表于 2014-2-10 15:02:27

Phoebe 发表于 2014-2-9 22:16
把天线放到室外了吗?要等上一段时间。现在串口输出的数据是什么?

板子是放在室外试验的

Phoebe 发表于 2014-2-13 10:23:42

zs1621 发表于 2014-2-10 15:01
通过usb连接模块可以读到数据的(drive gps via usb port), 但是把程序烧进arduino(drive gps via ardui ...

你按照下面的步骤试一下:
1)把S1开关拨到Prog一端
2)把S2开关拨到Arduino一端
3)把下面的三档开关拨到中间
4)下载代码到Arduino板
5)把S1拨到com端
6)重启板子(按RST键)多按几下

zs1621 发表于 2014-2-13 11:19:55

Phoebe 发表于 2014-2-13 10:23
你按照下面的步骤试一下:
1)把S1开关拨到Prog一端
2)把S2开关拨到Arduino一端


void setup()
{
        pinInit();
        Serial.begin(9600);
        delay(5000);
}

void pinInit()
{
        pinMode(3, OUTPUT);
        pinMode(4, OUTPUT);
        pinMode(5, OUTPUT);
        delay(2000);
        //Serial.print("start");
        digitalWrite(5, HIGH);
        delay(1500);
        digitalWrite(5, LOW);
        //Serial.print("start2");
        digitalWrite(3,LOW);//Enable GSM mode
        digitalWrite(4,HIGH);//Disable GPS mode

      Serial.println("AT");
        delay(2000);
        Serial.println("AT+CGPSIPR=9600");
        delay(2000);
        Serial.println("AT+CGPSPWR=1");
        delay(2000);
        Serial.println("AT+CGPSRST=1");
        delay(2000);
        digitalWrite(4, LOW);
        digitalWrite(3, HIGH);
        delay(2000);
        Serial.println("$GPGGA statement information: ");
}

void loop()
{
if (Serial.available() > 0)
{
    Serial.println(Serial.read());
}
else
{
    Serial.println("not ok");
}       
}

我用这个代码测试了一遍只能得到"not ok";

你看下是不是我的线路连接有问题, 看下面的链接
http://yun.baidu.com/share/link?shareid=949590621&uk=1426543175

ps: 我在http://www.dfrobot.com/forum/index.php?topic=14931.0 也提问了, 得到的回复是Serial port 被bluno 占用了, 推荐我试下dtmf. 我目前没有DTMF shield。 还没试。

mickey 发表于 2014-2-18 14:08:45

我们已经使用GSM三合一模块和bluno做了测试,没有任何问题,同时也将测试程序发给楼主不知道问题解决没有?测试程序代码如下,程序下载成功后,步骤:
1)把S1开关拨到com一端
2)把S2开关拨到Arduino一端
3)GSM/GPS选择开关居中
4)打开串口助手软件
5)复位Arduino直到STAT灯常亮,NET灯闪烁为止
void setup()
{
   Serial.begin(9600);
   pinInit();
   //delay(5000);
}

void pinInit()
{
   pinMode(3, OUTPUT);
   pinMode(4, OUTPUT);
   pinMode(5, OUTPUT);
   delay(1000);
   //Serial.print("start");
   digitalWrite(5, HIGH);
   delay(1500);
   digitalWrite(5, LOW);
   //Serial.print("start2");
   digitalWrite(3,LOW);//Enable GSM mode
   digitalWrite(4,HIGH);//Disable GPS mode

   Serial.println("AT");
   delay(2000);
   Serial.println("AT");
   delay(2000);
   Serial.println("AT+CGPSIPR=9600");
   delay(2000);
   Serial.println("AT+CGPSPWR=1");
   delay(2000);
   Serial.println("AT+CGPSRST=1");
   delay(2000);
   digitalWrite(3,HIGH);//Disable GSM mode
   digitalWrite(4,LOW);//Enable GPS mode
}

void loop()
{
if (Serial.available()){
          while(Serial.available()>0){
          char c = Serial.read();
          Serial.write(c);
          delay(50);
          }   
      Serial.println();
}
else
{
    Serial.println("not ok");
    delay(500);
}   
}

zs1621 发表于 2014-2-19 15:58:13

mickey 发表于 2014-2-18 14:08
我们已经使用GSM三合一模块和bluno做了测试,没有任何问题,同时也将测试程序发给楼主不知道问题解决没有? ...

mickey 最后去dfrobot那里找 lisper测试了下(结果还是得不到数据),换了块GPS/GSM/GPRS 板子(用你给我发的代码测试可以的) - 解决了! 具体问题应该就是你说的连接问题, 最终还是解决了, 谢谢~

mickey 发表于 2014-2-19 17:41:46

zs1621 发表于 2014-2-19 15:58
mickey 最后去dfrobot那里找 lisper测试了下(结果还是得不到数据),换了块GPS/GSM/GPRS 板子(用你给我发 ...

解决就好。
页: [1]
查看完整版本: 用GPS/GSM/GPRS shield V3.0 三合一模块接收数据的问题