Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 8434|回復: 8
打印 上一主題 下一主題

Arduino GPS的問題

[複製鏈接]
跳轉到指定樓層
1#
發表於 2012-11-28 17:28:16 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
拜託各位大大有誰能幫我解決GPS,
書上寫要加BYTE可是我打出來的都是黑字別人跟其他論壇打的都是綠字,是我少了哪些東西呢?
加上書上的範例程式他缺少了副程式根本沒有頭緒,我快抓狂了@@
還有我的GPS型號是
                                        EM-406A 衛星接收模組然後程式我一整個就是寫不出來,有誰可以幫幫我很急拜託
2#
發表於 2012-11-29 10:37:30 | 只看該作者
回復 1# q82839338

照這網頁做:inside have code
http://bildr.org/2011/06/em406a-gps-arduino/
3#
 樓主| 發表於 2012-11-29 17:20:12 | 只看該作者
我試了我連副程式都放了但是

while(uart_gps.available()){

他跟我這一段說錯誤 @@拜託告訴我這一怎麼一回是阿 ㄚㄚㄚㄚ
4#
發表於 2012-11-29 22:04:01 | 只看該作者
回復 3# q82839338

試試
    #include <NewSoftSerial.h>
自己去下載NewSoftSerial.h
參考成功範例
http://forum.processing.org/topic/arduino-gps-serial-data-to-processing-problem
5#
 樓主| 發表於 2012-11-30 12:24:41 | 只看該作者




我試了很多種頻率了
以上是他出現的訊號
我用的 版子是
arduino 的  MEGA 2560
這張版子
所以我把他的TX  RX  改成 1,0
本來大家都設定是在2.3腳位
不知道會不會有問題?
程式的部分我該抓的 副程式該用的都用了真的 不知道哪邊出問題能幫幫我麼?
6#
發表於 2012-11-30 12:57:00 | 只看該作者
回復 5# q82839338


    你的圖片顯示使用
#include <SoftwareSerial.h>
我是說
試試
    #include <NewSoftSerial.h>
一個有 new的.h, for arduino 1.0
7#
 樓主| 發表於 2012-11-30 13:02:38 | 只看該作者
但是當我使用後他出現了


In file included from _3212313.cpp:1:
P:\arduino-1.0.1\libraries\NewSoftSerial/NewSoftSerial.h:71: error: conflicting return type specified for 'virtual void NewSoftSerial::write(uint8_t)'
P:\arduino-1.0.1\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'
結果是直接出錯
所以這樣是我的副程式部分出現問題麼?
8#
發表於 2012-11-30 20:50:23 | 只看該作者
回復 7# q82839338

NewSoftSerial.h是不需要的

你改成
Serial.begin(4800);

另外要接 3.3V Logic Level Converter
https://www.sparkfun.com/products/8745?

以下的程式
#define RXPIN 19
#define TXPIN 18

我可以compiling成功

#include <TinyGPS.h>
#include <SoftwareSerial.h>
// Define which pins you will use on the Arduino to communicate with your
// GPS. In this case, the GPS module's TX pin will connect to the
// Arduino's RXPIN which is pin 3.
#define RXPIN 19
#define TXPIN 18
//Set this value equal to the baud rate of your GPS
#define GPSBAUD 4800
// Create an instance of the TinyGPS object
TinyGPS gps;
// Initialize the NewSoftSerial library to the pins you defined above
SoftwareSerial uart_gps(RXPIN, TXPIN);
// This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
void getgps(TinyGPS &gps);
// In the setup function, you need to initialize two serial ports; the
// standard hardware serial port (Serial()) to communicate with your
// terminal program an another serial port (NewSoftSerial()) for your
// GPS.
void setup()
{
// This is the serial rate for your terminal program. It must be this
// fast because we need to print everything before a new sentence
// comes in. If you slow it down, the messages might not be valid and
// you will likely get checksum errors.
Serial.begin(4800);
//Sets baud rate of your GPS
uart_gps.begin(GPSBAUD);
Serial.println("");
Serial.println("GPS Shield QuickStart Example Sketch v12");
Serial.println(" ...waiting for lock... ");
Serial.println("");
}
// This is the main loop of the code. All it does is check for data on
// the RX pin of the ardiuno, makes sure the data is valid NMEA sentences,
// then jumps to the getgps() function.
void loop()
{
while(uart_gps.available()) // While there is data on the RX pin...
{
int c = uart_gps.read(); // load the data into a variable...
if(gps.encode(c)) // if there is a new valid sentence...
{
getgps(gps); // then grab the data.
}
}
}
// The getgps function will get and print the values we want.
void getgps(TinyGPS &gps)
{
// To get all of the data into varialbes that you can use in your code,
// all you need to do is define variables and query the object for the
// data. To see the complete list of functions see keywords.txt file in
// the TinyGPS and NewSoftSerial libs.
// Define the variables that will be used
float latitude, longitude;
// Then call this function
gps.f_get_position(&latitude, &longitude);
// You can now print variables latitude and longitude
Serial.print("Lat/Long: ");
Serial.print(latitude,5);
Serial.print(", ");
Serial.println(longitude,5);
// Same goes for date and time
int year;
byte month, day, hour, minute, second, hundredths;
gps.crack_datetime(&year,&month,&day,&hour,&minute,&second,&hundredths);
// Print data and time
Serial.print("Date: "); Serial.print(month, DEC); Serial.print("/");
Serial.print(day, DEC); Serial.print("/"); Serial.print(year);
Serial.print(" Time: "); Serial.print(hour, DEC); Serial.print(":");
Serial.print(minute, DEC); Serial.print(":"); Serial.print(second, DEC);
Serial.print("."); Serial.println(hundredths, DEC);
//Since month, day, hour, minute, second, and hundr
// Here you can print the altitude and course values directly since
// there is only one value for the function
Serial.print("Altitude (meters): "); Serial.println(gps.f_altitude());
// Same goes for course
Serial.print("Course (degrees): "); Serial.println(gps.f_course());
// And same goes for speed
Serial.print("Speed(kmph): "); Serial.println(gps.f_speed_kmph());
Serial.println();
// Here you can print statistics on the sentences.
unsigned long chars;
unsigned short sentences, failed_checksum;
gps.stats(&chars, &sentences, &failed_checksum);
//Serial.print("Failed Checksums: ");Serial.print(failed_checksum);
//Serial.println(); Serial.println();
}
9#
發表於 2012-11-30 20:54:45 | 只看該作者
回復 7# q82839338


    另外一個的程式
我也可以compiling成功
你試看看
RXPIN 是19
#include "TinyGPS.h"
TinyGPS gps;
unsigned long fix_age, time, date, speed;
void getgps(TinyGPS &gps);
void setup() {
  Serial.begin(4800);
  Serial1.begin(4800);
}
void loop(){
  byte month, day, hour, minute, second, decsec;
  int year;
{
  if (Serial1.available() > 0){  
    char c = Serial1.read();
     if (gps.encode(c))
    {
   gps.get_datetime(&date, &time);
        gps.crack_datetime(&year, &month, &day, &hour, &minute, &second);
  Serial.print("Date: "); Serial.print(static_cast<int>(month));
  Serial.print("/"); Serial.print(static_cast<int>(day));
  Serial.print("/"); Serial.print(year); Serial.print("  Time: ");
  Serial.print(static_cast<int>(hour)); Serial.print(":");
  Serial.print(static_cast<int>(minute)); Serial.print(":");
  Serial.print(static_cast<int>(second));
  float falt = gps.f_altitude(); // +/- altitude in meters
        float velocidade = gps.f_speed_kmph();
   Serial.print("  Altitude: ");
   Serial.println(falt);
        Serial.print("Velocidade: ");
   Serial.println(velocidade);
        
delay(1000);
    }}}}
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-9-29 06:56 , Processed in 0.139861 second(s), 11 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表