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

2014-02-081.3万
AI 快速预览详细 收起
本文讨论了使用DFRobot的GPS/GSM/GPRS Shield V3.0模块时遇到的数据接收问题。用户发现Serial.available()值一直为0,无法接收数据。文章详细介绍了故障排查步骤,包括检查S1和S2开关的位置、移除UART选择跳线等。通过这些步骤,可以确保模块正确配置,从而解决数据接收问题。


参考 https://www.dfrobot.com.cn/commun ... d=631&highlight=gps 此贴后无果, 没办法 再发个帖子, 求解
代码参考
  1. // Product name: GPS/GPRS/GSM Module V3.0
  2. // # Product SKU : TEL0051
  3. // # Version     : 0.1
  4.   
  5. // # Description:
  6. // # The sketch for driving the gps mode via the Arduino board
  7.   
  8. // # Steps:
  9. // #        1. Turn the S1 switch to the Prog(right side)
  10. // #        2. Turn the S2 switch to the Arduino side(left side)
  11. // #        3. Take off the GSM/GPS jumper caps from the Uart select
  12. // #        4. Upload the sketch to the Arduino board
  13. // #        5. Turn the S1 switch to the comm(left side)
  14. // #        6. Remove the jumpers(old version) or set the UART select switch to middle.
  15. // #        7. RST the board
  16.   
  17. // #        If you get 'inf' values, go outdoors and wait until it is connected.
  18. // #        wiki link- http://www.dfrobot.com/wiki/index.php/GPS/GPRS/GSM_Module_V3.0_(SKU:TEL0051)
  19. double Datatransfer(char *data_buf,char num)//convert the data to the float type
  20. {                                           //*data_buf:the data array                                       
  21.   double temp=0.0;                           //the number of the right of a decimal point
  22.   unsigned char i,j;
  23.   if(data_buf[0]=='-')
  24.   {
  25.     i=1;
  26.     //process the data array
  27.     while(data_buf[i]!='.')
  28.       temp=temp*10+(data_buf[i++]-0x30);
  29.     for(j=0;j<num;j++)
  30.       temp=temp*10+(data_buf[++i]-0x30);
  31.     //convert the int type to the float type
  32.     for(j=0;j<num;j++)
  33.       temp=temp/10;
  34.     //convert to the negative numbe
  35.     temp=0-temp;
  36.   }
  37.   else//for the positive number
  38.   {
  39.     i=0;
  40.     while(data_buf[i]!='.')
  41.       temp=temp*10+(data_buf[i++]-0x30);
  42.     for(j=0;j<num;j++)
  43.       temp=temp*10+(data_buf[++i]-0x30);
  44.     for(j=0;j<num;j++)
  45.       temp=temp/10 ;
  46.   }
  47.   return temp;
  48. }
  49. char ID()//Match the ID commands
  50. {
  51.   char i=0;
  52.   char value[6]={
  53.     '
  54. 我在  ID() 函数中输出了 Serial.available(), 这个值一直为0, 这个值为0能说明什么?  
  55. ,'G','P','G','G','A'    };//match the gps protocol
  56.   char val[6]={
  57.     '0','0','0','0','0','0'    };
  58.   while(1)
  59.   {
  60.     if(Serial.available())
  61.     {
  62.       val[i] = Serial.read();//get the data from the serial interface
  63.       if(val[i]==value[i]) //Match the protocol
  64.       {   
  65.         i++;
  66.         if(i==6)
  67.         {
  68.           i=0;
  69.           return 1;//break out after get the command
  70.         }
  71.       }
  72.       else
  73.         i=0;
  74.     }
  75.   }
  76. }
  77. void comma(char num)//get ','
  78. {   
  79.   char val;
  80.   char count=0;//count the number of ','
  81.   while(1)
  82.   {
  83.     if(Serial.available())
  84.     {
  85.       val = Serial.read();
  86.       if(val==',')
  87.         count++;
  88.     }
  89.     if(count==num)//if the command is right, run return
  90.       return;
  91.   }
  92. }
  93. void UTC()//get the UTC data -- the time
  94. {
  95.   char i;
  96.   char time[9]={
  97.     '0','0','0','0','0','0','0','0','0'
  98.   };
  99.   double t=0.0;
  100.   if( ID())//check ID
  101.   {
  102.     comma(1);//remove 1 ','
  103.     //get the datas after headers
  104.     while(1)
  105.     {
  106.       if(Serial.available())
  107.       {
  108.         time[i] = Serial.read();
  109.         i++;
  110.       }
  111.       if(i==9)
  112.       {
  113.         i=0;
  114.         t=Datatransfer(time,2);//convert data
  115.         t=t+80000.00;//convert to the chinese time GMT+8 Time zone
  116.         Serial.println(t);//Print data
  117.         return;
  118.       }  
  119.     }
  120.   }
  121. }
  122. void latitude()//get latitude
  123. {
  124.   char i;
  125.   char lat[10]={
  126.     '0','0','0','0','0','0','0','0','0','0'
  127.   };
  128.   if( ID())
  129.   {
  130.     comma(2);
  131.     while(1)
  132.     {
  133.       if(Serial.available())
  134.       {
  135.         lat[i] = Serial.read();
  136.         i++;
  137.       }
  138.       if(i==10)
  139.       {
  140.         i=0;
  141.         Serial.println(Datatransfer(lat,5),5);//print latitude
  142.         return;
  143.       }  
  144.     }
  145.   }
  146. }
  147. void lat_dir()//get dimensions
  148. {
  149.   char i=0,val;
  150.   if( ID())
  151.   {
  152.     comma(3);
  153.     while(1)
  154.     {
  155.       if(Serial.available())
  156.       {
  157.         val = Serial.read();
  158.         Serial.write(val);
  159.         Serial.println();
  160.         i++;
  161.       }
  162.       if(i==1)
  163.       {
  164.         i=0;
  165.         return;
  166.       }  
  167.     }
  168.   }
  169. }
  170. void longitude()//get longitude
  171. {
  172.   char i;
  173.   char lon[11]={
  174.     '0','0','0','0','0','0','0','0','0','0','0'
  175.   };
  176.   if( ID())
  177.   {
  178.     comma(4);
  179.     while(1)
  180.     {
  181.       if(Serial.available())
  182.       {
  183.         lon[i] = Serial.read();
  184.         i++;
  185.       }
  186.       if(i==11)
  187.       {
  188.         i=0;
  189.         Serial.println(Datatransfer(lon,5),5);
  190.         return;
  191.       }  
  192.     }
  193.   }
  194. }
  195. void lon_dir()//get direction data
  196. {
  197.   char i=0,val;
  198.   if( ID())
  199.   {
  200.     comma(5);
  201.     while(1)
  202.     {
  203.       if(Serial.available())
  204.       {
  205.         val = Serial.read();
  206.         Serial.write(val); //Serial.println(val,BYTE);
  207.         Serial.println();
  208.         i++;
  209.       }
  210.       if(i==1)
  211.       {
  212.         i=0;
  213.         return;
  214.       }  
  215.     }
  216.   }
  217. }
  218. void altitude()//get altitude data
  219. {
  220.   char i,flag=0;
  221.   char alt[8]={
  222.     '0','0','0','0','0','0','0','0'
  223.   };
  224.   if( ID())
  225.   {
  226.     comma(9);
  227.     while(1)
  228.     {
  229.       if(Serial.available())
  230.       {
  231.         alt[i] = Serial.read();
  232.         if(alt[i]==',')
  233.           flag=1;
  234.         else
  235.           i++;
  236.       }
  237.       if(flag)
  238.       {
  239.         i=0;
  240.         Serial.println(Datatransfer(alt,1),1);//print altitude data
  241.         return;
  242.       }  
  243.     }
  244.   }
  245. }
  246. void setup()
  247. {
  248.   pinMode(3,OUTPUT);//The default digital driver pins for the GSM and GPS mode
  249.   pinMode(4,OUTPUT);
  250.   pinMode(5,OUTPUT);
  251.   digitalWrite(5,HIGH);
  252.   delay(1500);
  253.   digitalWrite(5,LOW);
  254.   digitalWrite(3,LOW);//Enable GSM mode
  255.   digitalWrite(4,HIGH);//Disable GPS mode
  256.   delay(2000);
  257.   Serial.begin(9600);
  258.   delay(5000);//GPS ready
  259.   Serial.println("AT");   
  260.   delay(2000);
  261.   //turn on GPS power supply
  262.   Serial.println("AT+CGPSPWR=1");
  263.   delay(1000);
  264.   //reset GPS in autonomy mode
  265.   Serial.println("AT+CGPSRST=1");
  266.   delay(1000);
  267.   digitalWrite(4,LOW);//Enable GPS mode
  268.   digitalWrite(3,HIGH);//Disable GSM mode
  269.   delay(2000);
  270.   Serial.println("$GPGGA statement information: ");
  271. }
  272. void loop()
  273. {
  274.   while(1)
  275.   {
  276.     Serial.print("UTC:");
  277.     UTC();
  278.     Serial.print("Lat:");
  279.     latitude();
  280.     Serial.print("Dir:");
  281.     lat_dir();
  282.     Serial.print("Lon:");
  283.     longitude();
  284.     Serial.print("Dir:");
  285.     lon_dir();
  286.     Serial.print("Alt:");
  287.     altitude();
  288.     Serial.println(' ');
  289.     Serial.println(' ');
  290.   }
  291. }
复制代码


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





创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(2)
Mickey
Mickey
我们已经使用GSM三合一模块和bluno做了测试,没有任何问题,同时也将测试程序发给楼主不知道问题解决没有?测试程序代码如下,程序下载成功后,步骤:
1)把S1开关拨到com一端
2)把S2开关拨到Arduino一端
3)GSM/GPS选择开关居中
4)打开串口助手软件
5)复位Arduino直到STAT灯常亮,NET灯闪烁为止
[code]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);
}
}
[/code]
Mickey
Mickey回复zs1621
解决就好。
zs1621
zs1621
作者
回复Mickey
mickey 最后去dfrobot那里找 lisper测试了下(结果还是得不到数据),换了块GPS/GSM/GPRS 板子(用你给我发的代码测试可以的) - 解决了! 具体问题应该就是你说的连接问题, 最终还是解决了, 谢谢~
phoebe.wang40
phoebe.wang40
把天线放到室外了吗?要等上一段时间。现在串口输出的数据是什么?
zs1621
zs1621
作者
回复phoebe.wang40
[code]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");
}
}[/code]
我用这个代码测试了一遍 只能得到"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。 还没试。
phoebe.wang40
phoebe.wang40回复zs1621
你按照下面的步骤试一下:
1)把S1开关拨到Prog一端
2)把S2开关拨到Arduino一端
3)把下面的三档开关拨到中间
4)下载代码到Arduino板
5)把S1拨到com端
6)重启板子(按RST键)多按几下
共4条回复,已加载2条,点击查看更多共4条回复,已加载全部
- 没有更多了 -