This article helped me a lot in sending configuration commands to my UBLOX GPS module.
At some point when you want to create configuration commands you may need to calculate the checksum for a UBLOX command. I found that to be a pain in the ***, so created a small sketch to do so.
/*UBlox GPS message checksum calculator
V1.0 by Hans Meijdam
U-Blox checksum calculator.
V1.1 Hans Meijdam, March 2021
This sketch will calculate the UBLOX checksum. The checksum algorithm used is the 8-Bit Fletcher Algorithm, which is used in the TCP standard (RFC 1145).
leave out the first two sync-char of the UBLOX sentence and the last two bytes are the checksum bytes.
expected outcome of the below example should be: CK_A = 91 and CK_B = 84
*/
const static uint8_t myStr[] PROGMEM = {0xB5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0xD0, 0x08, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0x84};
// ====sync=== ============================================== checksum calculated over these bytes =========================================================== =checksum=
//uint16_t prnt; // helper for printing
void setup() {
Serial.begin(9600);
uint8_t CK_A = 0;
uint8_t CK_B = 0;
uint8_t i;
for (i = 0; i < sizeof(myStr) - 4; i++) { // "-4" because leave the first two and the last two bytes out of the checksum calculation.
CK_A = CK_A + pgm_read_byte(&myStr[i + 2]); // "+2" because we skip the first 2 sync bytes
CK_B = CK_B + CK_A;
}
Serial.print(" CK_A = ");
Serial.print(CK_A, HEX);
Serial.print(" and CK_B = ");
Serial.println(CK_B, HEX);
}
void loop() {
}