Hello Friends,
I’m trying to make a speedometer by using an Arduino, I want that the speed is updated as much as possible. That means a high update rate and a LOT OF DATA. Sometimes I got a delayed speed. That is why I (think I) need a higher baud rate. In sketch is a setup-part for the GPS module. You can choose the update rate and the baud rate. I got the setup part of the code from someone else. He included a description : ‘‘delay(5); // simulating a 38400baud pace (or less), otherwise commands are not accepted by the device.’’
He says that you need a baud rate of 38400 or lower. But I want a higher baud rate to let’s say 115200 baud. So this is my problem: the GPS module accepts the 38400 baud command but not the 115200 baud command.
Someone who can help me out?
If you got any tips, they are welcome
My code:
#include <NeoSWSerial.h>//Include Software Serial Library
#include <U8glib.h> // Include the OLED library
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0); // Define a certain part of the OLED library
#include "TinyGPS++.h"// include GPS library
#define u8g_logo_sat_width 19 //
#define u8g_logo_sat_height 19 //
const unsigned char u8g_logo_sat[] = { //
//
0x80, 0x1F, 0x00, 0xF0, 0x70, 0x00, 0x18, 0xC0, 0x00, 0x0C, 0x80, 0x01, //
0x06, 0x02, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x06, 0x03, 0x07, 0x04, //
0x01, 0x07, 0x04, 0x01, 0x07, 0x04, 0x01, 0x07, 0x04, 0x83, 0x0D, 0x04, // GPS ICON Image
0x82, 0x08, 0x02, 0x82, 0x08, 0x02, 0x06, 0x00, 0x03, 0x0C, 0x80, 0x01, //
0x18, 0xC0, 0x00, 0x70, 0x70, 0x00, 0xC0, 0x1F, 0x00, //
//
}; //
NeoSWSerial serial_connection(3, 4); //Define Serial Pins
TinyGPSPlus gps; // Define gps object
//Creating some variables:
double gps_speed;
double Lat;
double Long;
double timehour;
double timedistance;
double traveleddistancesum;
double traveleddistance;
double traveleddistance1;
//GPS Module Setup, this is sent in "void GPSSETUP()"
const unsigned char UBLOX_INIT[] PROGMEM = {
//0xB5,0x62,0x06,0x08,0x06,0x00,0xF4,0x01,0x01,0x00,0x01,0x00,0x0B,0x77//(2 Hz)
//0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A, //(5Hz)
//0xB5,0x62,0x06,0x08,0x06,0x00,0xE8,0x03,0x01,0x00,0x01,0x00,0x01,0x39, //(1Hz)
//0xB5,0x62,0x06,0x08,0x06,0x00,0x64,0x00,0x01,0x00,0x01,0x00,0x7A,0x12, //(10Hz)
//0xB5,0x62,0x06,0x08,0x06,0x00,0xBC,0x02,0x01,0x00,0x01,0x00,0xD4,0x2C,//(1,43 Hz/700 ms)
//0xB5,0x62,0x06,0x08,0x06,0x00,0x58,0x02,0x01,0x00,0x01,0x00,0x70,0xD4, //(1,67Hz/600 ms)
//0xB5,0x62,0x06,0x08,0x06,0x00,0x64,0x00,0x01,0x00,0x01,0x00,0x7A,0x12, //(10Hz)
//0xB5,0x62,0x06,0x08,0x06,0x00,0xC8,0x00,0x01,0x00,0x01,0x00,0xDE,0x6A, //(5Hz)
//0xB5,0x62,0x06,0x08,0x06,0x00,0xE8,0x03,0x01,0x00,0x01,0x00,0x01,0x39 //(1Hz)
0xB5, 0x62, 0x06, 0x08, 0x06, 0x00, 0xFA, 0x00, 0x01, 0x00, 0x01, 0x00, 0x10, 0x96, //(4HZ)
// The next sentence will set the baudrate to the one you choose
//0xB5,0x62,0x06,0x00,0x14,0x00,0x01,0x00,0x00,0x00,0xD0,0x08,0x00,0x00,0x00,0x96,0x00,0x00,0x23,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0xAE,0x6A,
0xB5, 0x62, 0x06, 0x00, 0x14, 0x00, 0x01, 0x00, 0x00, 0x00, 0xD0, 0x08, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, 0x23, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAF, 0x70, // 38400
//0xB5,0x62,0x06,0x00,0x14,0x00,0x01,0x00,0x00,0x00,0xD0,0x08,0x00,0x00,0x00,0xC2,0x01,0x00,0x23,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0xDC,0x5E, //115200
};
void setup() {
Serial.begin(115200);//This opens up communications to the Serial monitor in the Arduino IDE
Serial.println("Welcome to the Speedometer");
GPSSETUP();
delay(1000);
}
void loop() {
// Calculate traveled distance since the arduino is powered:
traveleddistancesum = (gps.speed.mps() * (millis() - timedistance) / 1000);
timedistance = millis();
traveleddistance = ((traveleddistance + traveleddistancesum));
traveleddistance1 = ((traveleddistance) / 1000);
//---------------------------------------------------------------------------------------//
//--------------------------------------Start GPS Prosess--------------------------------//
//---------------------------------------------------------------------------------------//
uint8_t GPSchar; //Creating a variable for the gps data
while (1)
{
if (serial_connection.available() > 0)
{
GPSchar = serial_connection.read();
gps.encode(GPSchar);
Serial.write(GPSchar);
}
if (gps.location.isUpdated() && gps.altitude.isUpdated())
{
break;// if gps location is updated than continue the loop
}
}
// Setting variables:
gps_speed = (gps.speed.kmph());
Lat = (gps.location.lat());
Long = (gps.location.lng());
timehour = (gps.time.hour() + 1);
//---------------------------------------------------------------------------------------//
//--------------------------------Start Printing Prosess---------------------------------//
//---------------------------------------------------------------------------------------//
u8g.firstPage();
do {
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(56, 43);
u8g.print("km/h");
u8g.setFont(u8g_font_profont29r);
u8g.setPrintPos(0, 47);
u8g.print(gps_speed , 0);
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(0, 62);
u8g.print("N");
u8g.setFont(u8g_font_6x10);
u8g.setPrintPos(7, 62);
u8g.print( Lat, 6);
u8g.setPrintPos(73, 62);
u8g.print("E");
u8g.setPrintPos(80, 62);
u8g.print( Long, 6);
u8g.drawLine(0, 52, 128, 52);
u8g.drawLine(0, 22, 128, 22);
u8g.drawLine(89, 22, 89, 52);
u8g.drawXBM(0, 0, u8g_logo_sat_width, u8g_logo_sat_height, u8g_logo_sat);
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(23, 15);
if (((gps.course.deg())) >= 0 && ((gps.course.deg())) <= 22.5) {
u8g.print("Noord");
}
if (((gps.course.deg())) > 22.5 && ((gps.course.deg())) <= 67.5) {
u8g.print("Noord - Oost");
}
if (((gps.course.deg())) > 67.5 && ((gps.course.deg())) <= 112.5 ) {
u8g.print("Oost");
}
if (((gps.course.deg())) > 112.5 && (gps.course.deg()) <= 157.5) {
u8g.print("Zuid - Oost");
}
if ((gps.course.deg()) > 157.5 && (gps.course.deg()) <= 202.5) {
u8g.print("Zuid");
}
if ((gps.course.deg()) > 202.5 && (gps.course.deg()) <= 247.5) {
u8g.print("Zuid - West");
}
if ((gps.course.deg()) > 247.5 && (gps.course.deg()) <= 292.5) {
u8g.print("West");
}
if ((gps.course.deg()) > 292.5 && (gps.course.deg()) <= 337.5) {
u8g.print("Noord - West");
}
if ((gps.course.deg()) > 337.5 && (gps.course.deg()) <= 361) {
u8g.print("Noord");
}
u8g.setPrintPos(92, 49);
u8g.setFont(u8g_font_6x10);
if (traveleddistance < 1000 ) {
u8g.print((traveleddistance), 0);
u8g.setPrintPos(120, 49);
u8g.print("M");
}
if (traveleddistance1 > 1 && traveleddistance1 < 100 ) {
u8g.print((traveleddistance1));
}
if (traveleddistance1 > 100 ) {
u8g.print((traveleddistance1), 1);
}
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(90, 35);
if (timehour > 23) {
u8g.print("00");
}
else {
u8g.print(timehour, 0);
}
u8g.drawLine(89, 38, 128, 38);
u8g.setPrintPos(111, 35);
u8g.setFont(u8g_font_unifont);
u8g.print(gps.time.minute());
if ( (gps.time.second() % 2) == 0) { // this makes the dots blink (in the time bar)
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(105, 35);
u8g.print(":");
}
}
while (u8g.nextPage());
}
//---------------------------------------------------------------------------------------//
//--------------------------------Run the GPS setup once--------------------------------//
//---------------------------------------------------------------------------------------//
void GPSSETUP() {
serial_connection.begin(9600);//
// send configuration data in UBX protocol
for (unsigned int i = 0; i < sizeof(UBLOX_INIT); i++) {
serial_connection.write( pgm_read_byte(UBLOX_INIT + i) );
delay(5); // simulating a 38400baud pace (or less), otherwise commands are not accepted by the device.
}
serial_connection.begin(38400);
//serial_connection.begin(115200);
// send configuration data in UBX protocol
for (unsigned int i = 0; i < sizeof(UBLOX_INIT); i++) {
serial_connection.write( pgm_read_byte(UBLOX_INIT + i) );
delay(5); // simulating a 38400baud pace (or less), otherwise commands are not accepted by the device.
}
}
Stuff I’m using:
Ublox NEO-M7N
Arduino Nano V3.0 Atmega 328P
128x64 I2C OLED display