|
本帖最后由 wasdylb 于 2013-12-26 19:54 编辑
Microduino出GPS模块了,测试了其基本功能。包括:时间(年月日,时钟)、经纬度、速度、卫星个数、海拔高度,信号强度。
模块使用详见:http://wiki.microduino.net/index.php?title=Microduino-NEO-6M
整体:
PPS指示灯:
注意:必须匹配好串口,在空旷地方调试。Microduino NEO-6M模块默认与Core的串口通讯引脚是RX0、TX1,因此不可直接与Microduino FT232R叠加。为了方便调试改动模块背面的跳线:切断两组的焊盘中间与RX0/TX1的连线,将焊盘中间与D2、D3焊上。
程序:
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
Adafruit_GPS GPS(&Serial1);
//oled=======================================
#include <U8glib.h>
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // HW SPI Com: CS = 10, A0 = 9 (Hardware Pins are SCK = 13 and MOSI = 11)
//-------字体设置,大、中、小
#define setFont_L u8g.setFont(u8g_font_courB14)
#define setFont_M u8g.setFont(u8g_font_fixed_v0r)
#define setFont_S u8g.setFont(u8g_font_chikitar)
/*
font:
u8g.setFont(u8g_font_7x13)
u8g.setFont(u8g_font_fixed_v0r);
u8g.setFont(u8g_font_chikitar);
u8g.setFont(u8g_font_osb21);
*/
#define u8g_logo_width 128
#define u8g_logo_height 18
const unsigned char u8g_logo_bits[] U8G_PROGMEM =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0xE0,
0x03, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0xF0, 0x01, 0x00, 0x00, 0x00,
0x00, 0xFE, 0xF9, 0xF7, 0x07, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0xF8,
0x03, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xF9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0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
#define GPSECHO false
//==========================
boolean STA; //GPS状态
float f_latitude,f_longitude; //经纬度
char c_lat,c_lon; //经纬极向
int itime[3]; //时间
int idate[3]; //日期
float f_Speed; //速度
int i_Speed[2]; //速度格式化
float f_Height; //海拔
int i_satellites; //卫星数
float f_fixquality; //信号质量
#define init_updata 1000 //gps数据刷新时间
#define init_oled 500 //OLED刷新时间
unsigned long time_oled = millis();
unsigned long timer = millis();
void setup()
{
Serial.begin(115200);
GPS.begin(38400);
delay(1000);
// Ask for firmware version
// u8g.setRot180();
volcdlogo(0, 10);
delay(2000);
}
void volcdlogo(unsigned int x, unsigned int y)
{
u8g.firstPage();
do
{
u8g.drawXBMP( x, y, u8g_logo_width, u8g_logo_height, u8g_logo_bits);
}
while( u8g.nextPage() );
}
void vogps_dataread()
{
char c = GPS.read();
// if you want to debug, this is a good time to do it!
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
// a tricky thing here is if we print the NMEA sentence, or data
// we end up not listening and catching other sentences!
// so be very wary if using OUTPUT_ALLDATA and trytng to print out data
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
if (timer > millis())
timer = millis();
if (millis() - timer > init_updata)
{
timer = millis(); // reset the timer
if(GPS.hour>=0&&GPS.hour<=16)
itime[0]=GPS.hour+8;
else
itime[0]=GPS.hour;
itime[1]=GPS.minute;
itime[2]=GPS.seconds;
idate[0]=GPS.year;
idate[1]=GPS.month;
idate[2]=GPS.day;
f_fixquality=GPS.fixquality; //信号质量
STA=GPS.fix; //GPS定位状态
if (STA) //当GPS定位上
{
f_latitude=GPS.latitude;
f_longitude=GPS.longitude;
c_lat=GPS.lat;
c_lon=GPS.lon;
lat_lon_transform(); //经纬度转化
f_Speed=1.852*GPS.speed; //速度转化
i_Speed[0]=int(f_Speed*10)%10; //速度格式化
i_Speed[1]=int(f_Speed); //速度格式化
f_Height=GPS.altitude; //海拔
i_satellites=GPS.satellites; //卫星数
}
vooled();//OLED显示
}
}
//lat_lon_transform================================
void lat_lon_transform()
{
f_latitude=(int(f_latitude)/100)+((int(f_latitude)%100)/60.0)+((f_latitude-int(f_latitude))/60.0);
if(c_lat=='S') //南纬
f_latitude=-f_latitude;
//---------------------------------
f_longitude=(int(f_longitude)/100)+((int(f_longitude)%100)/60.0)+((f_longitude-int(f_longitude))/60.0);
if(c_lon=='W') //西经
f_longitude=-f_longitude;
}
void draw(void)
{
for(int a=0;a<3;a++)
{
u8g.drawFrame(106+(6*a), 4-(a*2), 5, 4+(a*2));
}
for(int a=0;a<f_fixquality+1;a++)
{
u8g.drawBox(106+(6*a), 4-(a*2), 5, 4+(a*2));
}
u8g.setPrintPos(0, 8);
u8g.print("Sat:");
u8g.print(i_satellites);
u8g.setPrintPos(36, 8);
u8g.print("ELE:");
u8g.print(f_Height);
u8g.print("m");
u8g.drawLine(0,11 , 128, 11);
setFont_L;
u8g.setPrintPos(2, 27);
u8g.print("Speed:");
if(STA)
{
u8g.print(i_Speed[1]);
setFont_M;
u8g.print(".");
u8g.print(i_Speed[0]);
}
else
{
u8g.print("N/A");
setFont_M;
}
u8g.drawLine(0,29 , 128, 29);
u8g.setPrintPos(2, 41);
u8g.print("Lat.: ");
u8g.print( f_latitude,4);
u8g.print(" ");
u8g.print( c_lat);
u8g.setPrintPos(2, 50);
u8g.print("Lon.: ");
u8g.print(f_longitude,4);
u8g.print(" ");
u8g.print( c_lon);
u8g.drawLine(0, 53, 128, 53);
u8g.setPrintPos(2, 64);
u8g.print("20");
u8g.print(idate[0]);
u8g.print("-");
u8g.print(idate[1]);
u8g.print("-");
u8g.print(idate[2]);
u8g.print(" ");
u8g.print(itime[0]);
u8g.print(":");
u8g.print(itime[1]);
u8g.print(":");
u8g.print(itime[2]);
}
//OLED===================================================
void vooled()
{
if (time_oled > millis())
time_oled = millis();
if(millis()-time_oled>init_oled)
{
u8g.firstPage();
do
{
draw();
}
while( u8g.nextPage() );
}
}
void loop()
{
vogps_dataread();
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|