我是靠谱客的博主 冷傲鱼,最近开发中收集的这篇文章主要介绍Arduino读取JY901+GPS/北斗双模定位模块信息(提高定位精度)串口和I2C通信Arduino读取JY901+GPS/北斗双模定位模块信息,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Arduino读取JY901+GPS/北斗双模定位模块信息

上一篇JY901模块连接ATK-1218-BD,GPS/北斗通过JY901上位机显示数据
采用JY901的上位机查看信息后,确定JY901,GPS模块连接没问题,下面通过arduino读取串口数据,便于进行接下来的应用开发。

本篇主要是串口通信和I2C的源码。
先安装库文件:
JY901的Arduio库文件:
JY901的Arduio库文件下载(免费、免积分)
内涵arduino的JY901库文件,包括串口通信和I2C通信源码例子。

  1. 将 JY901.zip 文件解压然后将解压出来的文件夹 JY901 拷贝到 Arduino 库安装目录下:
    C:Program Files (x86)Arduinolibraries.

  2. 打开 ArduinoIDE,点击 File->Examples->JY901,然后选择对应的实例程序。
    安装库文件

  3. 可以使用的函数可以再 JY901.h 文件中看到。

串口通信:

接线:

/*
Test on Uno R3.
JY901
UnoR3
TX <---> 0(Rx)
VCC<--->VCC
GND<---> GND
*/

源码:
注意,如果使用例子,修改波特率为9600

#include <Wire.h>
#include <JY901.h>
/*
Test on Uno R3.
JY901
UnoR3
TX <---> 0(Rx)
*/
int aax=0, aay=0,aaz=0, agx=0, agy=0, agz=0;
//角度变量
int magx=0, magy=0,magz=0, mag=0;
//
void setup()
{
Serial.begin(9600);
}
void loop()
{
//print received data. Data was received in serialEvent;
Serial.print("Time:20");Serial.print(JY901.stcTime.ucYear);Serial.print("-");Serial.print(JY901.stcTime.ucMonth);Serial.print("-");Serial.print(JY901.stcTime.ucDay);
Serial.print(" ");Serial.print(JY901.stcTime.ucHour);Serial.print(":");Serial.print(JY901.stcTime.ucMinute);Serial.print(":");Serial.println((float)JY901.stcTime.ucSecond+(float)JY901.stcTime.usMiliSecond/1000);
Serial.print("Acc:");Serial.print((float)JY901.stcAcc.a[0]/32768*16);Serial.print(" ");Serial.print((float)JY901.stcAcc.a[1]/32768*16);Serial.print(" ");Serial.println((float)JY901.stcAcc.a[2]/32768*16);
Serial.print("Gyro:");Serial.print((float)JY901.stcGyro.w[0]/32768*2000);Serial.print(" ");Serial.print((float)JY901.stcGyro.w[1]/32768*2000);Serial.print(" ");Serial.println((float)JY901.stcGyro.w[2]/32768*2000);
//读取角度
Serial.print("Angle:");aax = (float)JY901.stcAngle.Angle[0]/32768*180;
aay = (float)JY901.stcAngle.Angle[1]/32768*180;
aaz = (float)JY901.stcAngle.Angle[2]/32768*180;
Serial.print("Angle:");Serial.print("aax:");Serial.print(aax);Serial.print(" ");
Serial.print("aay:");Serial.print(aay);Serial.print(" ");
Serial.print("aaz:");Serial.println(aaz);
Serial.print("Mag:");
magx=JY901.stcMag.h[0];
magy=JY901.stcMag.h[1];
magz=JY901.stcMag.h[2];
Serial.print(magx);Serial.print("magx ");
Serial.print(magy);Serial.print("magy ");
Serial.print(magz);Serial.print("magz ");
mag = sqrt(magx*magx+magy*magy+magz*magz);
Serial.println(mag);Serial.print("mag ");
Serial.print("Pressure:");Serial.print(JY901.stcPress.lPressure);Serial.print(" ");Serial.println((float)JY901.stcPress.lAltitude/100);
Serial.print("DStatus:");Serial.print(JY901.stcDStatus.sDStatus[0]);Serial.print(" ");Serial.print(JY901.stcDStatus.sDStatus[1]);Serial.print(" ");Serial.print(JY901.stcDStatus.sDStatus[2]);Serial.print(" ");Serial.println(JY901.stcDStatus.sDStatus[3]);
Serial.print("Longitude:");Serial.print(JY901.stcLonLat.lLon/10000000);Serial.print("Deg");Serial.print((double)(JY901.stcLonLat.lLon % 10000000)/1e5);Serial.print("m Lattitude:");
Serial.print(JY901.stcLonLat.lLat/10000000);Serial.print("Deg");Serial.print((double)(JY901.stcLonLat.lLat % 10000000)/1e5);Serial.println("m");
Serial.print("GPSHeight:");Serial.print((float)JY901.stcGPSV.sGPSHeight/10);Serial.print("m GPSYaw:");Serial.print((float)JY901.stcGPSV.sGPSYaw/10);Serial.print("Deg GPSV:");Serial.print((float)JY901.stcGPSV.lGPSVelocity/1000);Serial.println("km/h");
Serial.println("");
delay(1000);
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX.
This routine is run between each
time loop() runs, so using delay inside loop can delay
response.
Multiple bytes of data may be available.
*/
void serialEvent()
{
while (Serial.available())
{
JY901.CopeSerialData(Serial.read()); //Call JY901 data cope function
}
}

串口显示内容:
串口监视器内容

I2C通信:

Arduino在使用I2C通信时都会用到SDA和SCL引脚,但各型号Arduino板的SDA和SCL引脚位置不同。
参考资料见Arduino官网:http://www.arduino.cc/en/Reference/Wire
各型号Arduino的I2C引脚:

Arduino Uno/nanoA4 (SDA) ,A5 (SCL)
Arduino Mega256020 (SDA), 21 (SCL)

另外,Arduino UNO / LEONARDO / YUN板都单独留有SCL、SDA引脚如下图

arduino i2c 引脚

接线:

/*
Test on Uno R3.
JY901
UnoR3
SDA <---> SDA
A4
SCL <---> SCL
A5
*/

源码:

#include <Wire.h>
#include <JY901.h>
/*
Test on Uno R3.
JY901
UnoR3
SDA <---> SDA
A4
SCL <---> SCL
A5
*/
int aax = 0, aay = 0, aaz = 0, agx = 0, agy = 0, agz = 0; //角度变量
void setup()
{
Serial.begin(9600);
JY901.StartIIC();
}
void loop()
{
//print received data. Data was received in serialEvent;
JY901.GetTime();
Serial.print("Time:20"); Serial.print(JY901.stcTime.ucYear); Serial.print("-"); Serial.print(JY901.stcTime.ucMonth); Serial.print("-"); Serial.print(JY901.stcTime.ucDay);
Serial.print(" "); Serial.print(JY901.stcTime.ucHour); Serial.print(":"); Serial.print(JY901.stcTime.ucMinute); Serial.print(":"); Serial.println((float)JY901.stcTime.ucSecond + (float)JY901.stcTime.usMiliSecond / 1000);
JY901.GetAcc();
Serial.print("Acc:"); Serial.print((float)JY901.stcAcc.a[0] / 32768 * 16); Serial.print(" "); Serial.print((float)JY901.stcAcc.a[1] / 32768 * 16); Serial.print(" "); Serial.println((float)JY901.stcAcc.a[2] / 32768 * 16);
JY901.GetGyro();
Serial.print("Gyro:"); Serial.print((float)JY901.stcGyro.w[0] / 32768 * 2000); Serial.print(" "); Serial.print((float)JY901.stcGyro.w[1] / 32768 * 2000); Serial.print(" "); Serial.println((float)JY901.stcGyro.w[2] / 32768 * 2000);
//读取角度
JY901.GetAngle();
aax = (float)JY901.stcAngle.Angle[0] / 32768 * 180;
aay = (float)JY901.stcAngle.Angle[1] / 32768 * 180;
aaz = (float)JY901.stcAngle.Angle[2] / 32768 * 180;
Serial.print("Angle:"); Serial.print("aax:"); Serial.print(aax); Serial.print(" ");
Serial.print("aay:"); Serial.print(aay); Serial.print(" ");
Serial.print("aaz:"); Serial.println(aaz);
JY901.GetMag();
Serial.print("Mag:"); Serial.print(JY901.stcMag.h[0]); Serial.print(" "); Serial.print(JY901.stcMag.h[1]); Serial.print(" "); Serial.println(JY901.stcMag.h[2]);
JY901.GetPress();
Serial.print("Pressure:"); Serial.print(JY901.stcPress.lPressure); Serial.print(" "); Serial.println((float)JY901.stcPress.lAltitude / 100);
JY901.GetDStatus();
Serial.print("DStatus:"); Serial.print(JY901.stcDStatus.sDStatus[0]); Serial.print(" "); Serial.print(JY901.stcDStatus.sDStatus[1]); Serial.print(" "); Serial.print(JY901.stcDStatus.sDStatus[2]); Serial.print(" "); Serial.println(JY901.stcDStatus.sDStatus[3]);
JY901.GetLonLat();
Serial.print("Longitude:"); Serial.print(JY901.stcLonLat.lLon / 10000000); Serial.print("Deg"); Serial.print((double)(JY901.stcLonLat.lLon % 10000000) / 1e5); Serial.print("m Lattitude:");
Serial.print(JY901.stcLonLat.lLat / 10000000); Serial.print("Deg"); Serial.print((double)(JY901.stcLonLat.lLat % 10000000) / 1e5); Serial.println("m");
JY901.GetGPSV();
Serial.print("GPSHeight:"); Serial.print((float)JY901.stcGPSV.sGPSHeight / 10); Serial.print("m GPSYaw:"); Serial.print((float)JY901.stcGPSV.sGPSYaw / 10); Serial.print("Deg GPSV:"); Serial.print((float)JY901.stcGPSV.lGPSVelocity / 1000); Serial.println("km/h");
Serial.println("");
delay(1000);
}

串口监视器显示内容:
串口监视器显示内容
JY901模块和GPS/北斗其他相关资料,请看我的分享:

JY901模块上位机程序下载(免费)

【正点原子】北斗GPS模块ATK-1218-BD相关资料下载(免费、免积分)

JY901官方使用说明文档

最后

以上就是冷傲鱼为你收集整理的Arduino读取JY901+GPS/北斗双模定位模块信息(提高定位精度)串口和I2C通信Arduino读取JY901+GPS/北斗双模定位模块信息的全部内容,希望文章能够帮你解决Arduino读取JY901+GPS/北斗双模定位模块信息(提高定位精度)串口和I2C通信Arduino读取JY901+GPS/北斗双模定位模块信息所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部