Jelajahi Sumber

修改arduino代码能正常工作

adam_zhuo 3 tahun lalu
induk
melakukan
f3b8982734

+ 0 - 52
Arduino UNOR3/JY901/examples/JY901IIC/JY901IIC.ino

@@ -1,52 +0,0 @@
-#include <Wire.h>
-#include <JY901.h>
-/*
-Test on Uno R3.
-JY901    UnoR3
-SDA <---> SDA
-SCL <---> SCL
-*/
-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();
-  Serial.print("Angle:");Serial.print((float)JY901.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)JY901.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)JY901.stcAngle.Angle[2]/32768*180);
-  
-  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(500);
-}
-
-
-

+ 0 - 54
Arduino UNOR3/JY901/examples/JY901Serial/JY901Serial.ino

@@ -1,54 +0,0 @@
-#include <Wire.h>
-#include <JY901.h>
-/*
-Test on Uno R3.
-JY901   UnoR3
-TX <---> 0(Rx)
-*/
-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:");Serial.print((float)JY901.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)JY901.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)JY901.stcAngle.Angle[2]/32768*180);
-  
-  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]);
-  
-  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(500);
-}
-
-/*
-  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
-  }
-}
-
-

+ 0 - 124
Arduino UNOR3/JY901/keywords.txt

@@ -1,124 +0,0 @@
-JY901	KEYWORD1
-CopeSerialData	KEYWORD2
-StartIIC	KEYWORD2
-CopeSerialData	KEYWORD2
-ReadWord	KEYWORD2
-WriteWord	KEYWORD2
-ReadData	KEYWORD2
-GetTime		KEYWORD2
-GetAcc		KEYWORD2
-GetGyro		KEYWORD2
-GetAngle	KEYWORD2
-GetMag		KEYWORD2
-GetPress	KEYWORD2
-GetDStatus	KEYWORD2
-GetLonLat	KEYWORD2
-GetGPSV		KEYWORD2
-stcTime	LITERAL1
-ucYear	LITERAL1
-ucMonth	LITERAL1
-ucDay	LITERAL1
-ucHour	LITERAL1
-ucMinute	LITERAL1
-ucSecond	LITERAL1
-usMiliSecond	LITERAL1
-
-stcAcc	LITERAL1
-a	LITERAL1
-T	LITERAL1
-
-stcGyro	LITERAL1
-w	LITERAL1
-
-stcAngle	LITERAL1
-Angle	LITERAL1
-
-stcMag	LITERAL1
-h	LITERAL1
-
-stcDStatus	LITERAL1
-sDStatus	LITERAL1
-
-stcPress	LITERAL1
-lPressure	LITERAL1
-lAltitude	LITERAL1
-
-stcLonLat	LITERAL1
-lLon	LITERAL1
-lLat	LITERAL1
-
-stcGPSV	LITERAL1
-sGPSHeight	LITERAL1
-sGPSYaw	LITERAL1
-lGPSVelocity	LITERAL1
-
-SAVE	LITERAL1
-CALSW	LITERAL1
-RSW	LITERAL1
-RRATE	LITERAL1
-BAUD	LITERAL1
-AXOFFSET	LITERAL1
-AYOFFSET	LITERAL1
-AZOFFSET	LITERAL1
-GXOFFSET	LITERAL1
-GYOFFSET	LITERAL1
-GZOFFSET	LITERAL1
-HXOFFSET	LITERAL1
-HYOFFSET	LITERAL1
-HZOFFSET	LITERAL1
-D0MODE	LITERAL1
-D1MODE	LITERAL1
-D2MODE	LITERAL1
-D3MODE	LITERAL1
-D0PWMH	LITERAL1
-D1PWMH	LITERAL1
-D2PWMH	LITERAL1
-D3PWMH	LITERAL1
-D0PWMT	LITERAL1
-D1PWMT	LITERAL1
-D2PWMT	LITERAL1
-D3PWMT	LITERAL1
-IICADDR	LITERAL1
-LEDOFF	LITERAL1
-GPSBAUD	LITERAL1
-
-YYMM	LITERAL1
-DDHH	LITERAL1
-MMSS	LITERAL1
-MS	LITERAL1
-AX	LITERAL1
-AY	LITERAL1
-AZ	LITERAL1
-GX	LITERAL1
-GY	LITERAL1
-GZ	LITERAL1
-HX	LITERAL1
-HY	LITERAL1
-HZ	LITERAL1
-Roll	LITERAL1
-Pitch	LITERAL1
-Yaw	LITERAL1
-TEMP	LITERAL1
-D0Status	LITERAL1
-D1Status	LITERAL1
-D2Status	LITERAL1
-D3Status	LITERAL1
-PressureL	LITERAL1
-PressureH	LITERAL1
-HeightL	LITERAL1
-HeightH	LITERAL1
-LonL	LITERAL1
-LonH	LITERAL1
-LatL	LITERAL1
-LatH	LITERAL1
-GPSHeight	LITERAL1
-GPSYAW	LITERAL1
-GPSVL	LITERAL1
-GPSVH	LITERAL1
-
-DIO_MODE_AIN	LITERAL1
-DIO_MODE_DIN	LITERAL1
-DIO_MODE_DOH	LITERAL1
-DIO_MODE_DOL	LITERAL1
-DIO_MODE_DOPWM	LITERAL1
-DIO_MODE_GPS	LITERAL1

+ 0 - 47
JY901SerialMega2560/examples/JY901SerialMega2560/JY901Serial/JY901Serial.ino

@@ -1,47 +0,0 @@
-#include <Wire.h>
-#include <JY901.h>
-/*
-Test on mega2560.
-JY901   mega2560
-TX <---> 0(Rx)
-*/
-void setup() 
-{
-  Serial.begin(9600);  
-  Serial1.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:");Serial.print((float)JY901.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)JY901.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)JY901.stcAngle.Angle[2]/32768*180);
-  
-  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]);
-  
-  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.print("SN:");Serial.print(JY901.stcSN.sSVNum);Serial.print(" PDOP:");Serial.print((float)JY901.stcSN.sPDOP/100);Serial.print(" HDOP:");Serial.print((float)JY901.stcSN.sHDOP/100);Serial.print(" VDOP:");Serial.println((float)JY901.stcSN.sVDOP/100);
-  
-  Serial.println("");
-  delay(500);
-
-  while (Serial1.available()) 
-  {
-    JY901.CopeSerialData(Serial1.read()); //Call JY901 data cope function
-  }
-
-}

+ 0 - 130
JY901SerialMega2560/keywords.txt

@@ -1,130 +0,0 @@
-JY901	KEYWORD1
-CopeSerialData	KEYWORD2
-StartIIC	KEYWORD2
-CopeSerialData	KEYWORD2
-ReadWord	KEYWORD2
-WriteWord	KEYWORD2
-ReadData	KEYWORD2
-GetTime		KEYWORD2
-GetAcc		KEYWORD2
-GetGyro		KEYWORD2
-GetAngle	KEYWORD2
-GetMag		KEYWORD2
-GetPress	KEYWORD2
-GetDStatus	KEYWORD2
-GetLonLat	KEYWORD2
-GetGPSV		KEYWORD2
-stcTime	LITERAL1
-ucYear	LITERAL1
-ucMonth	LITERAL1
-ucDay	LITERAL1
-ucHour	LITERAL1
-ucMinute	LITERAL1
-ucSecond	LITERAL1
-usMiliSecond	LITERAL1
-
-stcAcc	LITERAL1
-a	LITERAL1
-T	LITERAL1
-
-stcGyro	LITERAL1
-w	LITERAL1
-
-stcAngle	LITERAL1
-Angle	LITERAL1
-
-stcMag	LITERAL1
-h	LITERAL1
-
-stcDStatus	LITERAL1
-sDStatus	LITERAL1
-
-stcPress	LITERAL1
-lPressure	LITERAL1
-lAltitude	LITERAL1
-
-stcLonLat	LITERAL1
-lLon	LITERAL1
-lLat	LITERAL1
-
-stcGPSV	LITERAL1
-sGPSHeight	LITERAL1
-sGPSYaw	LITERAL1
-lGPSVelocity	LITERAL1
-
-stcSN	LITERAL1
-sSVNum	LITERAL1
-sPDOP	LITERAL1
-sHDOP	LITERAL1
-sVDOP	LITERAL1
-
-SAVE	LITERAL1
-CALSW	LITERAL1
-RSW	LITERAL1
-RRATE	LITERAL1
-BAUD	LITERAL1
-AXOFFSET	LITERAL1
-AYOFFSET	LITERAL1
-AZOFFSET	LITERAL1
-GXOFFSET	LITERAL1
-GYOFFSET	LITERAL1
-GZOFFSET	LITERAL1
-HXOFFSET	LITERAL1
-HYOFFSET	LITERAL1
-HZOFFSET	LITERAL1
-D0MODE	LITERAL1
-D1MODE	LITERAL1
-D2MODE	LITERAL1
-D3MODE	LITERAL1
-D0PWMH	LITERAL1
-D1PWMH	LITERAL1
-D2PWMH	LITERAL1
-D3PWMH	LITERAL1
-D0PWMT	LITERAL1
-D1PWMT	LITERAL1
-D2PWMT	LITERAL1
-D3PWMT	LITERAL1
-IICADDR	LITERAL1
-LEDOFF	LITERAL1
-GPSBAUD	LITERAL1
-
-YYMM	LITERAL1
-DDHH	LITERAL1
-MMSS	LITERAL1
-MS	LITERAL1
-AX	LITERAL1
-AY	LITERAL1
-AZ	LITERAL1
-GX	LITERAL1
-GY	LITERAL1
-GZ	LITERAL1
-HX	LITERAL1
-HY	LITERAL1
-HZ	LITERAL1
-Roll	LITERAL1
-Pitch	LITERAL1
-Yaw	LITERAL1
-TEMP	LITERAL1
-D0Status	LITERAL1
-D1Status	LITERAL1
-D2Status	LITERAL1
-D3Status	LITERAL1
-PressureL	LITERAL1
-PressureH	LITERAL1
-HeightL	LITERAL1
-HeightH	LITERAL1
-LonL	LITERAL1
-LonH	LITERAL1
-LatL	LITERAL1
-LatH	LITERAL1
-GPSHeight	LITERAL1
-GPSYAW	LITERAL1
-GPSVL	LITERAL1
-GPSVH	LITERAL1
-
-DIO_MODE_AIN	LITERAL1
-DIO_MODE_DIN	LITERAL1
-DIO_MODE_DOH	LITERAL1
-DIO_MODE_DOL	LITERAL1
-DIO_MODE_DOPWM	LITERAL1
-DIO_MODE_GPS	LITERAL1

+ 125 - 121
Arduino UNOR3/JY901/JY901.cpp → iic_6dof_imu/JY901.cpp

@@ -1,121 +1,125 @@
-#include "JY901.h"
-#include "string.h"
-
-CJY901 ::CJY901 ()
-{
-	ucDevAddr =0x50;
-}
-void CJY901::StartIIC()
-{
-	ucDevAddr = 0x50;
-	Wire.begin();
-}
-void CJY901::StartIIC(unsigned char ucAddr)
-{
-	ucDevAddr = ucAddr;
-	Wire.begin();
-}
-void CJY901 ::CopeSerialData(unsigned char ucData)
-{
-	static unsigned char ucRxBuffer[250];
-	static unsigned char ucRxCnt = 0;	
-	
-	ucRxBuffer[ucRxCnt++]=ucData;
-	if (ucRxBuffer[0]!=0x55) 
-	{
-		ucRxCnt=0;
-		return;
-	}
-	if (ucRxCnt<11) {return;}
-	else
-	{
-		switch(ucRxBuffer[1])
-		{
-			case 0x50:	memcpy(&stcTime,&ucRxBuffer[2],8);break;
-			case 0x51:	memcpy(&stcAcc,&ucRxBuffer[2],8);break;
-			case 0x52:	memcpy(&stcGyro,&ucRxBuffer[2],8);break;
-			case 0x53:	memcpy(&stcAngle,&ucRxBuffer[2],8);break;
-			case 0x54:	memcpy(&stcMag,&ucRxBuffer[2],8);break;
-			case 0x55:	memcpy(&stcDStatus,&ucRxBuffer[2],8);break;
-			case 0x56:	memcpy(&stcPress,&ucRxBuffer[2],8);break;
-			case 0x57:	memcpy(&stcLonLat,&ucRxBuffer[2],8);break;
-			case 0x58:	memcpy(&stcGPSV,&ucRxBuffer[2],8);break;
-		}
-		ucRxCnt=0;
-	}
-}
-void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
-{
-  Wire.beginTransmission(deviceAddr);
-  Wire.write(addressToRead);
-  Wire.endTransmission(false); //endTransmission but keep the connection active
-
-  Wire.requestFrom(deviceAddr, bytesToRead); //Ask for bytes, once done, bus is released by default
-
-  while(Wire.available() < bytesToRead); //Hang out until we get the # of bytes we expect
-
-  for(int x = 0 ; x < bytesToRead ; x++)
-    dest[x] = Wire.read();    
-}
-void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
-{
-  Wire.beginTransmission(deviceAddr);
-  Wire.write(addressToWrite);
-  for(int i = 0 ; i < bytesToRead ; i++)
-  Wire.write(dataToWrite[i]);
-  Wire.endTransmission(); //Stop transmitting
-}
-
-short CJY901::ReadWord(unsigned char ucAddr)
-{
-	short sResult;
-	readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult);
-	return sResult;
-}
-void CJY901::WriteWord(unsigned char ucAddr,short sData)
-{	
-	writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData);
-}
-void CJY901::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
-{
-	readRegisters(ucDevAddr, ucAddr, ucLength, chrData);
-}
-
-void CJY901::GetTime()
-{
-	readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime);	
-}
-void CJY901::GetAcc()
-{
-	readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc);
-}
-void CJY901::GetGyro()
-{
-	readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro);
-}
-
-void CJY901::GetAngle()
-{
-	readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle);
-}
-void CJY901::GetMag()
-{
-	readRegisters(ucDevAddr, HX, 6, (char *)&stcMag);
-}
-void CJY901::GetPress()
-{
-	readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress);
-}
-void CJY901::GetDStatus()
-{
-	readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus);
-}
-void CJY901::GetLonLat()
-{
-	readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat);
-}
-void CJY901::GetGPSV()
-{
-	readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV);
-}
-CJY901 JY901 = CJY901();
+#include "JY901.h"
+#include "string.h"
+
+CJY901 ::CJY901 ()
+{
+	ucDevAddr =0x50;
+}
+void CJY901::StartIIC()
+{
+	ucDevAddr = 0x50;
+	Wire.begin();
+}
+void CJY901::StartIIC(unsigned char ucAddr)
+{
+	ucDevAddr = ucAddr;
+	Wire.begin();
+}
+void CJY901 ::CopeSerialData(unsigned char ucData)
+{
+	static unsigned char ucRxBuffer[250];
+	static unsigned char ucRxCnt = 0;	
+	
+	ucRxBuffer[ucRxCnt++]=ucData;
+	if (ucRxBuffer[0]!=0x55) 
+	{
+		ucRxCnt=0;
+		return;
+	}
+	if (ucRxCnt<11) {return;}
+	else
+	{
+		switch(ucRxBuffer[1])
+		{
+			case 0x50:	memcpy(&stcTime,&ucRxBuffer[2],8);break;
+			case 0x51:	memcpy(&stcAcc,&ucRxBuffer[2],8);break;
+			case 0x52:	memcpy(&stcGyro,&ucRxBuffer[2],8);break;
+			case 0x53:	memcpy(&stcAngle,&ucRxBuffer[2],8);break;
+			case 0x54:	memcpy(&stcMag,&ucRxBuffer[2],8);break;
+			case 0x55:	memcpy(&stcDStatus,&ucRxBuffer[2],8);break;
+			case 0x56:	memcpy(&stcPress,&ucRxBuffer[2],8);break;
+			case 0x57:	memcpy(&stcLonLat,&ucRxBuffer[2],8);break;
+			case 0x58:	memcpy(&stcGPSV,&ucRxBuffer[2],8);break;
+		}
+		ucRxCnt=0;
+	}
+}
+void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
+{
+  Wire.beginTransmission(deviceAddr);
+  Wire.write(addressToRead);
+  Wire.endTransmission(false); //endTransmission but keep the connection active
+
+  Wire.requestFrom(deviceAddr, bytesToRead); //Ask for bytes, once done, bus is released by default
+
+  while(Wire.available() < bytesToRead); //Hang out until we get the # of bytes we expect
+
+  for(int x = 0 ; x < bytesToRead ; x++)
+    dest[x] = Wire.read();    
+}
+void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
+{
+  Wire.beginTransmission(deviceAddr);
+  Wire.write(addressToWrite);
+  for(int i = 0 ; i < bytesToRead ; i++)
+  Wire.write(dataToWrite[i]);
+  Wire.endTransmission(); //Stop transmitting
+}
+
+short CJY901::ReadWord(unsigned char ucAddr)
+{
+	short sResult;
+	readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult);
+	return sResult;
+}
+void CJY901::WriteWord(unsigned char ucAddr,short sData)
+{	
+	writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData);
+}
+void CJY901::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
+{
+	readRegisters(ucDevAddr, ucAddr, ucLength, chrData);
+}
+
+void CJY901::GetTime()
+{
+	readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime);	
+}
+void CJY901::GetAcc()
+{
+	readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc);
+}
+void CJY901::GetGyro()
+{
+	readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro);
+}
+
+void CJY901::GetAngle()
+{
+	readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle);
+}
+void CJY901::GetMag()
+{
+	readRegisters(ucDevAddr, HX, 6, (char *)&stcMag);
+}
+void CJY901::GetPress()
+{
+	readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress);
+}
+void CJY901::GetDStatus()
+{
+	readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus);
+}
+void CJY901::GetLonLat()
+{
+	readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat);
+}
+void CJY901::GetGPSV()
+{
+	readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV);
+}
+void CJY901::GetQuater()
+{
+  readRegisters(ucDevAddr, QUATER, 8, (char *)&stcQuater);
+}
+CJY901 JY901 = CJY901();

+ 174 - 182
JY901SerialMega2560/JY901.h → iic_6dof_imu/JY901.h

@@ -1,182 +1,174 @@
-#ifndef JY901_h
-#define JY901_h
-
-#define SAVE 			0x00
-#define CALSW 		0x01
-#define RSW 			0x02
-#define RRATE			0x03
-#define BAUD 			0x04
-#define AXOFFSET	0x05
-#define AYOFFSET	0x06
-#define AZOFFSET	0x07
-#define GXOFFSET	0x08
-#define GYOFFSET	0x09
-#define GZOFFSET	0x0a
-#define HXOFFSET	0x0b
-#define HYOFFSET	0x0c
-#define HZOFFSET	0x0d
-#define D0MODE		0x0e
-#define D1MODE		0x0f
-#define D2MODE		0x10
-#define D3MODE		0x11
-#define D0PWMH		0x12
-#define D1PWMH		0x13
-#define D2PWMH		0x14
-#define D3PWMH		0x15
-#define D0PWMT		0x16
-#define D1PWMT		0x17
-#define D2PWMT		0x18
-#define D3PWMT		0x19
-#define IICADDR		0x1a
-#define LEDOFF 		0x1b
-#define GPSBAUD		0x1c
-
-#define YYMM				0x30
-#define DDHH				0x31
-#define MMSS				0x32
-#define MS					0x33
-#define AX					0x34
-#define AY					0x35
-#define AZ					0x36
-#define GX					0x37
-#define GY					0x38
-#define GZ					0x39
-#define HX					0x3a
-#define HY					0x3b
-#define HZ					0x3c			
-#define Roll				0x3d
-#define Pitch				0x3e
-#define Yaw					0x3f
-#define TEMP				0x40
-#define D0Status		0x41
-#define D1Status		0x42
-#define D2Status		0x43
-#define D3Status		0x44
-#define PressureL		0x45
-#define PressureH		0x46
-#define HeightL			0x47
-#define HeightH			0x48
-#define LonL				0x49
-#define LonH				0x4a
-#define LatL				0x4b
-#define LatH				0x4c
-#define GPSHeight   0x4d
-#define GPSYAW      0x4e
-#define GPSVL				0x4f
-#define GPSVH				0x50
-      
-#define DIO_MODE_AIN 0
-#define DIO_MODE_DIN 1
-#define DIO_MODE_DOH 2
-#define DIO_MODE_DOL 3
-#define DIO_MODE_DOPWM 4
-#define DIO_MODE_GPS 5		
-
-struct STime
-{
-	unsigned char ucYear;
-	unsigned char ucMonth;
-	unsigned char ucDay;
-	unsigned char ucHour;
-	unsigned char ucMinute;
-	unsigned char ucSecond;
-	unsigned short usMiliSecond;
-};
-struct SAcc
-{
-	short a[3];
-	short T;
-};
-struct SGyro
-{
-	short w[3];
-	short T;
-};
-struct SAngle
-{
-	short Angle[3];
-	short T;
-};
-struct SMag
-{
-	short h[3];
-	short T;
-};
-
-struct SDStatus
-{
-	short sDStatus[4];
-};
-
-struct SPress
-{
-	long lPressure;
-	long lAltitude;
-};
-
-struct SLonLat
-{
-	long lLon;
-	long lLat;
-};
-
-struct SGPSV
-{
-	short sGPSHeight;
-	short sGPSYaw;
-	long lGPSVelocity;
-};
-struct SQuater
-{
-	short q0;
-	short q1;
-	short q2;
-	short q3;
-};
-struct SSN
-{
-	short sSVNum;
-	short sPDOP;
-	short sHDOP;
-	short sVDOP;
-};
-class CJY901 
-{
-  public: 
-	struct STime		stcTime;
-	struct SAcc 		stcAcc;
-	struct SGyro 		stcGyro;
-	struct SAngle 		stcAngle;
-	struct SMag 		stcMag;
-	struct SDStatus 	stcDStatus;
-	struct SPress 		stcPress;
-	struct SLonLat 		stcLonLat;
-	struct SGPSV 		stcGPSV;
-	struct SQuater		stcQuater;
-	struct SSN 		stcSN;
-	
-    CJY901 (); 
-	void StartIIC();
-	void StartIIC(unsigned char ucAddr);
-    void CopeSerialData(unsigned char ucData);
-	short ReadWord(unsigned char ucAddr);
-	void WriteWord(unsigned char ucAddr,short sData);
-	void ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[]);
-	void GetTime();
-	void GetAcc();
-	void GetGyro();
-	void GetAngle();
-	void GetMag();
-	void GetPress();
-	void GetDStatus();
-	void GetLonLat();
-	void GetGPSV();
-	
-  private: 
-	unsigned char ucDevAddr; 
-	void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest);
-	void writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite);
-};
-extern CJY901 JY901;
-#include <Wire.h>
-#endif
+#ifndef JY901_h
+#define JY901_h
+
+#define SAVE 			0x00
+#define CALSW 		0x01
+#define RSW 			0x02
+#define RRATE			0x03
+#define BAUD 			0x04
+#define AXOFFSET	0x05
+#define AYOFFSET	0x06
+#define AZOFFSET	0x07
+#define GXOFFSET	0x08
+#define GYOFFSET	0x09
+#define GZOFFSET	0x0a
+#define HXOFFSET	0x0b
+#define HYOFFSET	0x0c
+#define HZOFFSET	0x0d
+#define D0MODE		0x0e
+#define D1MODE		0x0f
+#define D2MODE		0x10
+#define D3MODE		0x11
+#define D0PWMH		0x12
+#define D1PWMH		0x13
+#define D2PWMH		0x14
+#define D3PWMH		0x15
+#define D0PWMT		0x16
+#define D1PWMT		0x17
+#define D2PWMT		0x18
+#define D3PWMT		0x19
+#define IICADDR		0x1a
+#define LEDOFF 		0x1b
+#define GPSBAUD		0x1c
+
+#define YYMM				0x30
+#define DDHH				0x31
+#define MMSS				0x32
+#define MS					0x33
+#define AX					0x34
+#define AY					0x35
+#define AZ					0x36
+#define GX					0x37
+#define GY					0x38
+#define GZ					0x39
+#define HX					0x3a
+#define HY					0x3b
+#define HZ					0x3c			
+#define Roll				0x3d
+#define Pitch				0x3e
+#define Yaw					0x3f
+#define TEMP				0x40
+#define D0Status		0x41
+#define D1Status		0x42
+#define D2Status		0x43
+#define D3Status		0x44
+#define PressureL		0x45
+#define PressureH		0x46
+#define HeightL			0x47
+#define HeightH			0x48
+#define LonL				0x49
+#define LonH				0x4a
+#define LatL				0x4b
+#define LatH				0x4c
+#define GPSHeight   0x4d
+#define GPSYAW      0x4e
+#define GPSVL				0x4f
+#define GPSVH				0x50
+#define QUATER      0x51
+      
+#define DIO_MODE_AIN 0
+#define DIO_MODE_DIN 1
+#define DIO_MODE_DOH 2
+#define DIO_MODE_DOL 3
+#define DIO_MODE_DOPWM 4
+#define DIO_MODE_GPS 5		
+
+struct STime
+{
+	unsigned char ucYear;
+	unsigned char ucMonth;
+	unsigned char ucDay;
+	unsigned char ucHour;
+	unsigned char ucMinute;
+	unsigned char ucSecond;
+	unsigned short usMiliSecond;
+};
+struct SAcc
+{
+	short a[3];
+	short T;
+};
+struct SGyro
+{
+	short w[3];
+	short T;
+};
+struct SAngle
+{
+	short Angle[3];
+	short T;
+};
+struct SMag
+{
+	short h[3];
+	short T;
+};
+
+struct SDStatus
+{
+	short sDStatus[4];
+};
+
+struct SPress
+{
+	long lPressure;
+	long lAltitude;
+};
+
+struct SLonLat
+{
+	long lLon;
+	long lLat;
+};
+
+struct SGPSV
+{
+	short sGPSHeight;
+	short sGPSYaw;
+	long lGPSVelocity;
+};
+struct SQuater
+{
+  short q[4];
+  short T;
+};
+class CJY901 
+{
+  public: 
+	struct STime		stcTime;
+	struct SAcc 		stcAcc;
+	struct SGyro 		stcGyro;
+	struct SAngle 		stcAngle;
+	struct SMag 		stcMag;
+	struct SDStatus 	stcDStatus;
+	struct SPress 		stcPress;
+	struct SLonLat 		stcLonLat;
+	struct SGPSV 		stcGPSV;
+  struct SQuater     stcQuater;
+	
+    CJY901 (); 
+	void StartIIC();
+	void StartIIC(unsigned char ucAddr);
+    void CopeSerialData(unsigned char ucData);
+	short ReadWord(unsigned char ucAddr);
+	void WriteWord(unsigned char ucAddr,short sData);
+	void ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[]);
+	void GetTime();
+	void GetAcc();
+	void GetGyro();
+	void GetAngle();
+	void GetMag();
+	void GetPress();
+	void GetDStatus();
+	void GetLonLat();
+	void GetGPSV();
+  void GetQuater();
+  
+  private: 
+	unsigned char ucDevAddr; 
+	void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest);
+	void writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite);
+};
+extern CJY901 JY901;
+#include <Wire.h>
+#endif

+ 32 - 0
iic_6dof_imu/iic_6dof_imu.ino

@@ -0,0 +1,32 @@
+#include <Wire.h>
+#include "JY901.h"
+/*
+Test on Uno R3.
+JY901    UnoR3
+SDA <---> SDA
+SCL <---> SCL
+*/
+void setup() 
+{
+  Serial.begin(115200);
+  JY901.StartIIC();
+} 
+
+void loop() 
+{
+  //print received data. Data was received in serialEvent;
+  Serial.println("");
+  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();
+  Serial.print("Angle:");Serial.print((float)JY901.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)JY901.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)JY901.stcAngle.Angle[2]/32768*180);
+
+  JY901.GetQuater();
+  Serial.print("Quater:");Serial.print((float)JY901.stcQuater.q[0]/32768);Serial.print(" ");Serial.print((float)JY901.stcQuater.q[1]/32768);Serial.print(" ");Serial.print((float)JY901.stcQuater.q[2]/32768);Serial.print(" ");Serial.println((float)JY901.stcQuater.q[3]/32768);
+  Serial.println("");
+  delay(500);
+}

+ 122 - 123
JY901SerialMega2560/JY901.cpp → serial_6dof_imu/JY901.cpp

@@ -1,123 +1,122 @@
-#include "JY901.h"
-#include "string.h"
-
-CJY901 ::CJY901 ()
-{
-	ucDevAddr =0x50;
-}
-void CJY901::StartIIC()
-{
-	ucDevAddr = 0x50;
-	Wire.begin();
-}
-void CJY901::StartIIC(unsigned char ucAddr)
-{
-	ucDevAddr = ucAddr;
-	Wire.begin();
-}
-void CJY901 ::CopeSerialData(unsigned char ucData)
-{
-	static unsigned char ucRxBuffer[250];
-	static unsigned char ucRxCnt = 0;	
-	
-	ucRxBuffer[ucRxCnt++]=ucData;
-	if (ucRxBuffer[0]!=0x55) 
-	{
-		ucRxCnt=0;
-		return;
-	}
-	if (ucRxCnt<11) {return;}
-	else
-	{
-		switch(ucRxBuffer[1])
-		{
-			case 0x50:	memcpy(&stcTime,&ucRxBuffer[2],8);break;
-			case 0x51:	memcpy(&stcAcc,&ucRxBuffer[2],8);break;
-			case 0x52:	memcpy(&stcGyro,&ucRxBuffer[2],8);break;
-			case 0x53:	memcpy(&stcAngle,&ucRxBuffer[2],8);break;
-			case 0x54:	memcpy(&stcMag,&ucRxBuffer[2],8);break;
-			case 0x55:	memcpy(&stcDStatus,&ucRxBuffer[2],8);break;
-			case 0x56:	memcpy(&stcPress,&ucRxBuffer[2],8);break;
-			case 0x57:	memcpy(&stcLonLat,&ucRxBuffer[2],8);break;
-			case 0x58:	memcpy(&stcGPSV,&ucRxBuffer[2],8);break;
-			case 0x59:	memcpy(&stcQuater,&ucRxBuffer[2],8);break;
-			case 0x5a:	memcpy(&stcSN,&ucRxBuffer[2],8);break;
-		}
-		ucRxCnt=0;
-	}
-}
-void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
-{
-  Wire.beginTransmission(deviceAddr);
-  Wire.write(addressToRead);
-  Wire.endTransmission(false); //endTransmission but keep the connection active
-
-  Wire.requestFrom(deviceAddr, bytesToRead); //Ask for bytes, once done, bus is released by default
-
-  while(Wire.available() < bytesToRead); //Hang out until we get the # of bytes we expect
-
-  for(int x = 0 ; x < bytesToRead ; x++)
-    dest[x] = Wire.read();    
-}
-void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
-{
-  Wire.beginTransmission(deviceAddr);
-  Wire.write(addressToWrite);
-  for(int i = 0 ; i < bytesToRead ; i++)
-  Wire.write(dataToWrite[i]);
-  Wire.endTransmission(); //Stop transmitting
-}
-
-short CJY901::ReadWord(unsigned char ucAddr)
-{
-	short sResult;
-	readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult);
-	return sResult;
-}
-void CJY901::WriteWord(unsigned char ucAddr,short sData)
-{	
-	writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData);
-}
-void CJY901::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
-{
-	readRegisters(ucDevAddr, ucAddr, ucLength, chrData);
-}
-
-void CJY901::GetTime()
-{
-	readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime);	
-}
-void CJY901::GetAcc()
-{
-	readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc);
-}
-void CJY901::GetGyro()
-{
-	readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro);
-}
-
-void CJY901::GetAngle()
-{
-	readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle);
-}
-void CJY901::GetMag()
-{
-	readRegisters(ucDevAddr, HX, 6, (char *)&stcMag);
-}
-void CJY901::GetPress()
-{
-	readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress);
-}
-void CJY901::GetDStatus()
-{
-	readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus);
-}
-void CJY901::GetLonLat()
-{
-	readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat);
-}
-void CJY901::GetGPSV()
-{
-	readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV);
-}
-CJY901 JY901 = CJY901();
+#include "JY901.h"
+#include "string.h"
+
+CJY901 ::CJY901 ()
+{
+	ucDevAddr =0x50;
+}
+void CJY901::StartIIC()
+{
+	ucDevAddr = 0x50;
+	Wire.begin();
+}
+void CJY901::StartIIC(unsigned char ucAddr)
+{
+	ucDevAddr = ucAddr;
+	Wire.begin();
+}
+void CJY901 ::CopeSerialData(unsigned char ucData)
+{
+	static unsigned char ucRxBuffer[250];
+	static unsigned char ucRxCnt = 0;	
+	
+	ucRxBuffer[ucRxCnt++]=ucData;
+	if (ucRxBuffer[0]!=0x55) 
+	{
+		ucRxCnt=0;
+		return;
+	}
+	if (ucRxCnt<11) {return;}
+	else
+	{
+		switch(ucRxBuffer[1])
+		{
+			case 0x50:	memcpy(&stcTime,&ucRxBuffer[2],8);break;
+			case 0x51:	memcpy(&stcAcc,&ucRxBuffer[2],8);break;
+			case 0x52:	memcpy(&stcGyro,&ucRxBuffer[2],8);break;
+			case 0x53:	memcpy(&stcAngle,&ucRxBuffer[2],8);break;
+			case 0x54:	memcpy(&stcMag,&ucRxBuffer[2],8);break;
+			case 0x55:	memcpy(&stcDStatus,&ucRxBuffer[2],8);break;
+			case 0x56:	memcpy(&stcPress,&ucRxBuffer[2],8);break;
+			case 0x57:	memcpy(&stcLonLat,&ucRxBuffer[2],8);break;
+			case 0x58:	memcpy(&stcGPSV,&ucRxBuffer[2],8);break;
+      case 0x59:  memcpy(&stcQuater,&ucRxBuffer[2],8);break;
+		}
+		ucRxCnt=0;
+	}
+}
+void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest)
+{
+  Wire.beginTransmission(deviceAddr);
+  Wire.write(addressToRead);
+  Wire.endTransmission(false); //endTransmission but keep the connection active
+
+  Wire.requestFrom(deviceAddr, bytesToRead); //Ask for bytes, once done, bus is released by default
+
+  while(Wire.available() < bytesToRead); //Hang out until we get the # of bytes we expect
+
+  for(int x = 0 ; x < bytesToRead ; x++)
+    dest[x] = Wire.read();    
+}
+void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite)
+{
+  Wire.beginTransmission(deviceAddr);
+  Wire.write(addressToWrite);
+  for(int i = 0 ; i < bytesToRead ; i++)
+  Wire.write(dataToWrite[i]);
+  Wire.endTransmission(); //Stop transmitting
+}
+
+short CJY901::ReadWord(unsigned char ucAddr)
+{
+	short sResult;
+	readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult);
+	return sResult;
+}
+void CJY901::WriteWord(unsigned char ucAddr,short sData)
+{	
+	writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData);
+}
+void CJY901::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[])
+{
+	readRegisters(ucDevAddr, ucAddr, ucLength, chrData);
+}
+
+void CJY901::GetTime()
+{
+	readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime);	
+}
+void CJY901::GetAcc()
+{
+	readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc);
+}
+void CJY901::GetGyro()
+{
+	readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro);
+}
+
+void CJY901::GetAngle()
+{
+	readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle);
+}
+void CJY901::GetMag()
+{
+	readRegisters(ucDevAddr, HX, 6, (char *)&stcMag);
+}
+void CJY901::GetPress()
+{
+	readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress);
+}
+void CJY901::GetDStatus()
+{
+	readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus);
+}
+void CJY901::GetLonLat()
+{
+	readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat);
+}
+void CJY901::GetGPSV()
+{
+	readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV);
+}
+CJY901 JY901 = CJY901();

+ 172 - 166
Arduino UNOR3/JY901/JY901.h → serial_6dof_imu/JY901.h

@@ -1,166 +1,172 @@
-#ifndef JY901_h
-#define JY901_h
-
-#define SAVE 			0x00
-#define CALSW 		0x01
-#define RSW 			0x02
-#define RRATE			0x03
-#define BAUD 			0x04
-#define AXOFFSET	0x05
-#define AYOFFSET	0x06
-#define AZOFFSET	0x07
-#define GXOFFSET	0x08
-#define GYOFFSET	0x09
-#define GZOFFSET	0x0a
-#define HXOFFSET	0x0b
-#define HYOFFSET	0x0c
-#define HZOFFSET	0x0d
-#define D0MODE		0x0e
-#define D1MODE		0x0f
-#define D2MODE		0x10
-#define D3MODE		0x11
-#define D0PWMH		0x12
-#define D1PWMH		0x13
-#define D2PWMH		0x14
-#define D3PWMH		0x15
-#define D0PWMT		0x16
-#define D1PWMT		0x17
-#define D2PWMT		0x18
-#define D3PWMT		0x19
-#define IICADDR		0x1a
-#define LEDOFF 		0x1b
-#define GPSBAUD		0x1c
-
-#define YYMM				0x30
-#define DDHH				0x31
-#define MMSS				0x32
-#define MS					0x33
-#define AX					0x34
-#define AY					0x35
-#define AZ					0x36
-#define GX					0x37
-#define GY					0x38
-#define GZ					0x39
-#define HX					0x3a
-#define HY					0x3b
-#define HZ					0x3c			
-#define Roll				0x3d
-#define Pitch				0x3e
-#define Yaw					0x3f
-#define TEMP				0x40
-#define D0Status		0x41
-#define D1Status		0x42
-#define D2Status		0x43
-#define D3Status		0x44
-#define PressureL		0x45
-#define PressureH		0x46
-#define HeightL			0x47
-#define HeightH			0x48
-#define LonL				0x49
-#define LonH				0x4a
-#define LatL				0x4b
-#define LatH				0x4c
-#define GPSHeight   0x4d
-#define GPSYAW      0x4e
-#define GPSVL				0x4f
-#define GPSVH				0x50
-      
-#define DIO_MODE_AIN 0
-#define DIO_MODE_DIN 1
-#define DIO_MODE_DOH 2
-#define DIO_MODE_DOL 3
-#define DIO_MODE_DOPWM 4
-#define DIO_MODE_GPS 5		
-
-struct STime
-{
-	unsigned char ucYear;
-	unsigned char ucMonth;
-	unsigned char ucDay;
-	unsigned char ucHour;
-	unsigned char ucMinute;
-	unsigned char ucSecond;
-	unsigned short usMiliSecond;
-};
-struct SAcc
-{
-	short a[3];
-	short T;
-};
-struct SGyro
-{
-	short w[3];
-	short T;
-};
-struct SAngle
-{
-	short Angle[3];
-	short T;
-};
-struct SMag
-{
-	short h[3];
-	short T;
-};
-
-struct SDStatus
-{
-	short sDStatus[4];
-};
-
-struct SPress
-{
-	long lPressure;
-	long lAltitude;
-};
-
-struct SLonLat
-{
-	long lLon;
-	long lLat;
-};
-
-struct SGPSV
-{
-	short sGPSHeight;
-	short sGPSYaw;
-	long lGPSVelocity;
-};
-class CJY901 
-{
-  public: 
-	struct STime		stcTime;
-	struct SAcc 		stcAcc;
-	struct SGyro 		stcGyro;
-	struct SAngle 		stcAngle;
-	struct SMag 		stcMag;
-	struct SDStatus 	stcDStatus;
-	struct SPress 		stcPress;
-	struct SLonLat 		stcLonLat;
-	struct SGPSV 		stcGPSV;
-	
-    CJY901 (); 
-	void StartIIC();
-	void StartIIC(unsigned char ucAddr);
-    void CopeSerialData(unsigned char ucData);
-	short ReadWord(unsigned char ucAddr);
-	void WriteWord(unsigned char ucAddr,short sData);
-	void ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[]);
-	void GetTime();
-	void GetAcc();
-	void GetGyro();
-	void GetAngle();
-	void GetMag();
-	void GetPress();
-	void GetDStatus();
-	void GetLonLat();
-	void GetGPSV();
-	
-  private: 
-	unsigned char ucDevAddr; 
-	void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest);
-	void writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite);
-};
-extern CJY901 JY901;
-#include <Wire.h>
-#endif
+#ifndef JY901_h
+#define JY901_h
+
+#define SAVE 			0x00
+#define CALSW 		0x01
+#define RSW 			0x02
+#define RRATE			0x03
+#define BAUD 			0x04
+#define AXOFFSET	0x05
+#define AYOFFSET	0x06
+#define AZOFFSET	0x07
+#define GXOFFSET	0x08
+#define GYOFFSET	0x09
+#define GZOFFSET	0x0a
+#define HXOFFSET	0x0b
+#define HYOFFSET	0x0c
+#define HZOFFSET	0x0d
+#define D0MODE		0x0e
+#define D1MODE		0x0f
+#define D2MODE		0x10
+#define D3MODE		0x11
+#define D0PWMH		0x12
+#define D1PWMH		0x13
+#define D2PWMH		0x14
+#define D3PWMH		0x15
+#define D0PWMT		0x16
+#define D1PWMT		0x17
+#define D2PWMT		0x18
+#define D3PWMT		0x19
+#define IICADDR		0x1a
+#define LEDOFF 		0x1b
+#define GPSBAUD		0x1c
+
+#define YYMM				0x30
+#define DDHH				0x31
+#define MMSS				0x32
+#define MS					0x33
+#define AX					0x34
+#define AY					0x35
+#define AZ					0x36
+#define GX					0x37
+#define GY					0x38
+#define GZ					0x39
+#define HX					0x3a
+#define HY					0x3b
+#define HZ					0x3c			
+#define Roll				0x3d
+#define Pitch				0x3e
+#define Yaw					0x3f
+#define TEMP				0x40
+#define D0Status		0x41
+#define D1Status		0x42
+#define D2Status		0x43
+#define D3Status		0x44
+#define PressureL		0x45
+#define PressureH		0x46
+#define HeightL			0x47
+#define HeightH			0x48
+#define LonL				0x49
+#define LonH				0x4a
+#define LatL				0x4b
+#define LatH				0x4c
+#define GPSHeight   0x4d
+#define GPSYAW      0x4e
+#define GPSVL				0x4f
+#define GPSVH				0x50
+      
+#define DIO_MODE_AIN 0
+#define DIO_MODE_DIN 1
+#define DIO_MODE_DOH 2
+#define DIO_MODE_DOL 3
+#define DIO_MODE_DOPWM 4
+#define DIO_MODE_GPS 5		
+
+struct STime
+{
+	unsigned char ucYear;
+	unsigned char ucMonth;
+	unsigned char ucDay;
+	unsigned char ucHour;
+	unsigned char ucMinute;
+	unsigned char ucSecond;
+	unsigned short usMiliSecond;
+};
+struct SAcc
+{
+	short a[3];
+	short T;
+};
+struct SGyro
+{
+	short w[3];
+	short T;
+};
+struct SAngle
+{
+	short Angle[3];
+	short T;
+};
+struct SMag
+{
+	short h[3];
+	short T;
+};
+
+struct SDStatus
+{
+	short sDStatus[4];
+};
+
+struct SPress
+{
+	long lPressure;
+	long lAltitude;
+};
+
+struct SLonLat
+{
+	long lLon;
+	long lLat;
+};
+
+struct SGPSV
+{
+	short sGPSHeight;
+	short sGPSYaw;
+	long lGPSVelocity;
+};
+struct SQuater
+{
+  short q[4];
+  short T;
+};
+class CJY901 
+{
+  public: 
+	struct STime		stcTime;
+	struct SAcc 		stcAcc;
+	struct SGyro 		stcGyro;
+	struct SAngle 		stcAngle;
+	struct SMag 		stcMag;
+	struct SDStatus 	stcDStatus;
+	struct SPress 		stcPress;
+	struct SLonLat 		stcLonLat;
+	struct SGPSV 		stcGPSV;
+  struct SQuater  stcQuater;
+	
+    CJY901 (); 
+	void StartIIC();
+	void StartIIC(unsigned char ucAddr);
+    void CopeSerialData(unsigned char ucData);
+	short ReadWord(unsigned char ucAddr);
+	void WriteWord(unsigned char ucAddr,short sData);
+	void ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[]);
+	void GetTime();
+	void GetAcc();
+	void GetGyro();
+	void GetAngle();
+	void GetMag();
+	void GetPress();
+	void GetDStatus();
+	void GetLonLat();
+	void GetGPSV();
+	
+  private: 
+	unsigned char ucDevAddr; 
+	void readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest);
+	void writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite);
+};
+extern CJY901 JY901;
+#include <Wire.h>
+#endif

+ 41 - 0
serial_6dof_imu/serial_6dof_imu.ino

@@ -0,0 +1,41 @@
+#include <Wire.h>
+#include "JY901.h"
+/*
+Test on Uno R3.
+JY901   UnoR3
+TX <---> 0(Rx)
+*/
+void setup() 
+{
+  Serial.begin(115200);
+}
+
+void loop() 
+{
+  //print received data. Data was received in serialEvent;
+               
+  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:");Serial.print((float)JY901.stcAngle.Angle[0]/32768*180);Serial.print(" ");Serial.print((float)JY901.stcAngle.Angle[1]/32768*180);Serial.print(" ");Serial.println((float)JY901.stcAngle.Angle[2]/32768*180);
+  
+  Serial.print("Quater:");Serial.print((float)JY901.stcQuater.q[0]/32768);Serial.print(" ");Serial.print((float)JY901.stcQuater.q[1]/32768);Serial.print(" ");Serial.print((float)JY901.stcQuater.q[2]/32768);Serial.print(" ");Serial.println((float)JY901.stcQuater.q[3]/32768);
+  
+  Serial.println("");
+  delay(500);
+}
+
+/*
+  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
+  }
+}