Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPS first commit #3

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions GPS_CCP/GPS_CCP.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include <Wire.h> //Needed for I2C to GNSS

#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;

#include <MicroNMEA.h> //http://librarymanager/All#MicroNMEA
char nmeaBuffer[100];
MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer));

//CANに必要なもの
#include <SPI.h>
#include <string.h>
#include <CCP_MCP2515.h>

#define CAN0_INT D1
#define CAN0_CS D0

CCP_MCP2515 CCP(CAN0_CS, CAN0_INT);

long CCP_latitude = 0;
long CCP_longitude = 0;

void setup() {
Serial.begin(115200);
Serial.println("SparkFun u-blox Example");

Wire.begin();
myGNSS.begin();


myGNSS.setI2COutput(COM_TYPE_UBX | COM_TYPE_NMEA); //Set the I2C port to output both NMEA and UBX messages
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR

myGNSS.setProcessNMEAMask(SFE_UBLOX_FILTER_NMEA_ALL); // Make sure the library is passing all NMEA messages to processNMEA

myGNSS.setProcessNMEAMask(SFE_UBLOX_FILTER_NMEA_GGA); // Or, we can be kind to MicroNMEA and _only_ pass the GGA messages to it

// CAN
pinMode(CAN0_CS, OUTPUT);
pinMode(CAN0_INT, INPUT);
digitalWrite(CAN0_CS, HIGH);
CCP.begin();
}

void loop() {
myGNSS.checkUblox(); //See if new data is available. Process bytes as they come in.

if (nmea.isValid() == true) {
long latitude_mdeg = nmea.getLatitude();
long longitude_mdeg = nmea.getLongitude();

Serial.print("Latitude (deg): ");
Serial.println(latitude_mdeg / 1000000., 6);
Serial.print("Longitude (deg): ");
Serial.println(longitude_mdeg / 1000000., 6);

byte sndStat1 = CCP.uint32_to_device(CCP_A_GNSS_latitude_udeg, nmea.getLatitude() );
if (sndStat1 == CAN_OK) {
Serial.println("Message Sent Successfully!");
} else {
Serial.println("Error Sending Message...");
}

byte sndStat2 = CCP.uint32_to_device(CCP_A_GNSS_longitude_udeg, nmea.getLongitude() );
if (sndStat2 == CAN_OK) {
Serial.println("Message Sent Successfully!");
} else {
Serial.println("Error Sending Message...");
}
nmea.clear(); // Clear the MicroNMEA storage to make sure we are getting fresh data
}
// // else {
// Serial.println("Waiting for fresh data");
// }

if (!digitalRead(CAN0_INT)) // データ受信確認
{
CCP.read_device();
switch (CCP.id) {
case CCP_A_GNSS_latitude_udeg:
CCP_latitude = CCP.data_uint32();
break;
case CCP_A_GNSS_longitude_udeg:
CCP_longitude = CCP.data_uint32();
break;
default:
break;
}
}

// Serial.print(CCP_latitude);
// Serial.print(",");
// Serial.println(CCP_longitude);

// delay(100); //Don't pound too hard on the I2C bus
}

//This function gets called from the SparkFun u-blox Arduino Library
//As each NMEA character comes in you can specify what to do with it
//Useful for passing to other libraries like tinyGPS, MicroNMEA, or even
//a buffer, radio, etc.
void SFE_UBLOX_GNSS::processNMEA(char incoming) {
//Take the incoming char from the u-blox I2C port and pass it on to the MicroNMEA lib
//for sentence cracking
nmea.process(incoming);
}
26 changes: 26 additions & 0 deletions sketch_GPS2/sketch_GPS2.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <Wire.h> // Needed for I2C to GPS
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS
SFE_UBLOX_GNSS myGNSS;

void setup()
{
Serial.begin(115200);
Serial.println("SparkFun u-blox Example");
Wire.begin();
Serial.println("Hello");
if (myGNSS.begin() == false)
{
Serial.println(F("u-blox GNSS module not detected at default I2C address. Please check wiring. Freezing."));
while (1);
}

// This will pipe all NMEA sentences to the serial port so we can see them
myGNSS.setNMEAOutputPort(Serial);
}

void loop()
{
myGNSS.checkUblox(); // See if new data is available. Process bytes as they come in.
Serial.println("----------------------------");
delay(1000); // Don't pound too hard on the I2C bus
}