problem with gps :( only 0.0000 instead of real data:(

therion
Sun Jan 14, 2018 6:29 am
Hello
I have very big problem with GPS(NEO-6M) and STM32 (STM32F103C8T6).
I try to recieve gps data, latitude and longtitude, but it dont work.
I have allways only “0.00000” value on screen:( – GPS module is working, led is blinking (when it was blinking on arduino, i had a correct coordinates)
Did anyone of You connect gps module to stm32??

If anyone know how to connect, and can, paste simplest code (and describe pin connection). I am beginner – if i had an working example i could learn how to do what i want. Simplest code, latitude on serial port or something…

Below i paste my code, where is mistake about gps?? Any ideas?
Sorry for my english, i am begginer in stm32 and language skills:)
#include <TinyGPS++.h>
#include <SoftSerialIntAP.h>

#include <Adafruit_GFX_AS.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library

#define TFT_CS PA2
#define TFT_RST PA4
#define TFT_DC PA3
#define TFT_SCK PA5
#define TFT_SDA PA7
#define LCDROTATION 2
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);

// -----------------gps
TinyGPSPlus gps;
static const int RXPin = PB10, TXPin = PB11;
static const uint32_t GPSBaud = 9600;
SoftSerialIntAP ss(15, 16, 3); // (15, 16, 3)???
// -----------------gps

// -----------------lcd screen heading
void wyswietlaniegps()
{
tft.setTextSize(2);
tft.setTextColor(ST7735_GREEN,0x0292);
tft.setCursor(16,1);
tft.print("GPS DATA");
tft.drawLine(0,17,127,17,ST7735_GREEN);
}
// -----------------lcd screen heading

void setup()
{
Serial.begin(9600);

ss.begin(GPSBaud);
while (ss.available() > 0)
gps.encode(ss.read());

tft.initR(INITR_BLACKTAB); // start ekranu
tft.setRotation(LCDROTATION); // ustawienie obrotu ekranu
tft.fillScreen(0x0292); // wypelnienie kolorem RGB565
wyswietlaniegps();}

void loop()
{

Serial.println("TEST");
Serial.println("-----");
Serial.println(gps.location.lat(),6);
Serial.println("_____");
delay(1000);

tft.setTextSize(2);
tft.setTextColor(ST7735_GREEN,0x0292);
tft.setCursor(10,30);
tft.print(gps.location.lat(),5);

tft.setTextSize(2);
tft.setTextColor(ST7735_GREEN,0x0292);
tft.setCursor(10,60);
tft.print(gps.location.lng(),6);

tft.setTextSize(1);
tft.setTextColor(ST7735_GREEN,0x0292);
tft.setCursor(30,90);
tft.print("**TEST**");
}


fpiSTM
Sun Jan 14, 2018 7:39 am
Hi, assuming you use this lib:
https://github.com/mikalhart/TinyGPSPlus

Have you try first the basic example provided with the lib?

Also have you made some search on the forum. ex:
http://stm32duino.com/viewtopic.php?f=1 … it=tinyGPS


therion
Sun Jan 14, 2018 8:20 am
i tried different libraries. On arduino i try basic and full example and it was ok, but not on stm32:(

Yes i was searching on forum, http://stm32duino.com/viewtopic.php?f=1 … it=tinyGPS – too, but i dont understand it, maybe weak english maybe weak c++.
I was looking on other pages, but after whole day didnt find solution:(
Thats why i asking on forum, maybe i doing something wrong with pinouts? i dont know:(

Working simple code would be best fo learn it…
Arduino examples dont work, only “0.00000” instead of real data.
And i dont have idea why.
What is wrong with my code??


stevestrong
Sun Jan 14, 2018 9:05 am
You should try first this example: https://github.com/mikalhart/TinyGPSPlu … xample.ino
Also, be aware that STM32F103C8 is actually working with 3.3V, not 5V.

Instead of SoftwareSerial you could use a hardware serial interface, the STM32F103C8 has 3 UART ports.
If you do this, then line 2 of the example can be deleted.
// The serial connection to the GPS device
#define ss SERIAL1 // SoftwareSerial ss(RXPin, TXPin);
...
ss.begin(GPSBaud); // this will use UART1 pins PA9/PA10


therion
Sun Jan 14, 2018 10:40 am
You should try first this example:i made my code by experimenting on “FullExample” and “Device Example” it not working:(

As You can see in my first code i change tx,rx pins, RXPin = PB10, TXPin = PB11;

STM32 have 3 tx/rx ports.
1: PA9/PA10 – I using it to connect programator
2: PA2/PA3 – lcd tft screen
3: PB10/PB11 – i want to use it to GPS
But i dont know how to do it

I dont know how to use hardware port in gps signal:( i dont know C++, i am hobbyst, and all i can find is too dificult for me:(

Could You change this shortest i can built code, to working code??:
#include <TinyGPS++.h>

// -----------------gps
TinyGPSPlus gps;
#define ss3 Serial3
static const uint32_t GPSBaud = 9600;
// -----------------gps

void setup()
{
Serial.begin(9600);
ss3.begin(GPSBaud);
while (ss3.available() > 0)
gps.encode(ss3.read());
}
void loop()
{
Serial.println("TEST");
Serial.println(gps.location.lat(),6);
Serial.println("_____");
delay(1000);
}


stevestrong
Sun Jan 14, 2018 10:52 am
I have adapted in your post. Try it.
Serial3 Tx = PB10, Rx = PB11. Check your connection (exchange Rx/Tx) if still not working.
Or use different Baudrate.

therion
Sun Jan 14, 2018 11:04 am
compilation error:(

exit status 1
‘SERIAL3’ was not declared in this scope


stevestrong
Sun Jan 14, 2018 11:07 am
Yes, sorry, it should be Serial3.
And you should include the GPS data read in the main loop, like this:
uint32_t time;
void loop()
{
if ( (millis()-time)<1000 )
{
if (ss3.available())
gps.encode(ss3.read());
}
time = millis();
Serial.println("TEST");
Serial.println(gps.location.lat(),6);
Serial.println("_____");
}

therion
Sun Jan 14, 2018 11:33 am
still the same error:(
exit status 1
‘Serial3’ was not declared in this scope

#include <TinyGPS++.h>

// -----------------gps
TinyGPSPlus gps;
#define ss3 Serial3
static const uint32_t GPSBaud = 9600;
// -----------------gps

void setup()
{
Serial.begin(9600);
ss3.begin(GPSBaud);
}
uint32_t time;
void loop()
{
if ( (millis()-time)<1000 )
{
if (ss3.available())
gps.encode(ss3.read());
}
time = millis();
Serial.println("TEST");
Serial.println(gps.location.lat(),6);
Serial.println("_____");
}


stevestrong
Sun Jan 14, 2018 11:49 am
Do you use Arduino IDE? Which version?
Which board? Maple mini or “blue pill”?
Do you use the libmaple core (https://github.com/rogerclarkmelbourne/Arduino_STM32) ?
Add
#include <Arduino.h>

therion
Sun Jan 14, 2018 12:06 pm
Arduino IDE 1.8.5.0
BluePill

#include <Arduino.h>


stevestrong
Sun Jan 14, 2018 12:14 pm
If I understood correctly, you are uploading over Serial1, correct?
That means, you do not have SERIAL_USB defined.
In this case, UART3 is mapped to Serial2, see: https://github.com/rogerclarkmelbourne/ … ial.h#L211
So try Serial2 instead Serial3.
#define ss3 Serial2

therion
Sun Jan 14, 2018 12:55 pm
Yes serial 1 (programator is connected to PA9,PA10)

Ok with this #define ss3 Serial2


stevestrong
Sun Jan 14, 2018 1:06 pm
Monitor the data received from the GPS on PC:
uint32_t time;
void loop()
{
if ( (millis()-time)<1000 )
{
if (ss3.available())
{
char c = ss3.read();
Serial.write(c); // monitor the data from GPS on PC
gps.encode(c);
}
}
time = millis();
Serial.println("TEST");
Serial.println(gps.location.lat(),6);
Serial.println("_____");
}

therion
Sun Jan 14, 2018 7:34 pm
i have really bad feeling about my stm32 future.
Now with thic code i have yhis wierd thing:
it should be only “TEST” i dont understand why there are additional signs (1,9,p…)
1TEST
0.000000
_____
9TEST
0.000000
_____
PTEST
0.000000
_____
.TEST
0.000000
_____
1TEST
0.000000
_____
9TEST
0.000000
_____
STEST
0.000000
_____
2TEST
0.000000

zmemw16
Sun Jan 14, 2018 8:23 pm
try printing in hex line for each ‘c’, they might be non-printable ascii ?
stephen

stevestrong
Sun Jan 14, 2018 9:46 pm
OK, those characters are received from the GPS module, but the example was not quite the one I wanted (i missed a quote, and you put it on the wrong place…).
Now let’s do a very simple test:
void loop()
{
if (ss3.available())
{
char c = ss3.read();
Serial.write(c); // monitor only the data from GPS on PC
}
}

mrburnette
Sun Jan 14, 2018 9:56 pm
[therion – Sun Jan 14, 2018 12:55 pm] –
<…>
I tried to change Baud rate
From baud rate which was working well on aduino (4800):
static const uint32_t GPSBaud = 4800;

therion
Mon Jan 15, 2018 9:29 am
stevestrong is one of our best, work with him and he’ll get you through this rough spot. Ray, You are right, He is :)
By the way thanks for links. I have been earlier on Your site. Youre projects are too difficult for me now but maybe some day:)

Stevestrong Youre code start to working :)
Code void loop()
{
if (ss3.available())
{
char c = ss3.read();
Serial.write(c); // monitor only the data from GPS on PC
}
}


stevestrong
Mon Jan 15, 2018 9:48 am
OK, now let’s go back to the example I suggested before (corrected version):
uint32_t time;
void loop()
{
if ( (millis()-time)<1000 )
{
if (ss3.available())
{
char c = ss3.read();
Serial.write(c); // monitor the data from GPS on PC --- this is optional, can be commented out
gps.encode(c);
} // this line was missing before
}
time = millis();
Serial.println("TEST");
Serial.println(gps.location.lat(),6);
Serial.println("_____");
}

therion
Mon Jan 15, 2018 11:27 am
Gps diode is blinking so it recieve signal, but still on serial pot:
_____
TEST
0.000000
_____
TEST
0.000000

zmemw16
Mon Jan 15, 2018 11:34 am
ivstr led flashing means still trying to get signal lock, steady when it is locked.
usually when i took it outside and enough sky to see i think 3 sats at a minimum.

what i should do is ask what your actual hardware is ?
from ebay/aliexpress etc and can you post the link
or maybe you’ve built your own module ?
if you built your own, the ‘gps’ block has spi, uart & usb i/faces

time for long cable, equally long pole, zip ties and open the window :D
srp


therion
Mon Jan 15, 2018 11:49 am
haha yeah winter -15C outside, and I standing and looking for blinking led:) Neighbours will have fun:)
Im sure that gps blinking led means “I have signal” i tried this with arduino and code from Stevestrong.

Aliexpress module, but before my experiments with stm32 i tried to use it with arduino and it works fine, in home and outside, led blinking had same effect.
Allways:
Led is blinking = data recieved
led off = no data, looking for satelites


mrburnette
Mon Jan 15, 2018 2:57 pm
from the PDF user manual: https://www.terraelectronica.ru/%2Fds%2 … Manual.pdf

After waiting for a while, if the serial debugging assistant lists similar data in its
window as the figure shows below, it means GPS has performed positioning. And
you can see that the LED on the module, which remains on when GPS is unable
to perform the positioning, is flickering now.

When working with GPS (or any serial device) it is very helpful to have a USB-serial adapter or have some type of serial display device.

Other USB-serial:
https://www.adafruit.com/product/70
https://www.adafruit.com/product/3309

Ray

The following is PSoC 4200 C code for a state machine to decode GPS NMEA sentences.
Important stuff begins after the loop statement: for(;;)
The technique for parsing is the same utilized by Adafruit in their GPS library.

/*
main.c
Project: Nokia5110GLCD_PSoC4.cydwr (using bit-bang SPI)
Build date: 20140909 All code by Ray is public domain - OTHER? see Credits-Licenses.txt
UPDATED: 20140909 To include parsing of the month, day, and year
*/

#include <main.h>
#include <stdlib.h> // for function atoi()

#define NewLine() UART_UartPutChar(CR); UART_UartPutChar(LF); // Used to insert a CR/LF
// Prototypes
void initSystem (void);

// Global variables
uint8_t len = GLCD_LCD_WIDTH / 6; // 84 pixels / 6 == 14 ch/line
uint8_t hour, minute, seconds; //, year, month, day;
uint8_t day, month, year;

char buffer[GLCD_LCD_WIDTH / 6 + 1];
char nmea[120];

// double atof(const char *str); // elimited Limor's float implementation

_Bool DayLightSavings; // Pin 3.4
uint8_t GMToffset = 4;
uint8_t Flag = 1;

int main()
{
ForcedReset:; // come here if onboard reset button pushed
DayLightSavings = DSTime_Read(); // Normally true (HIGH)

if(! DayLightSavings) GMToffset += 1;

uint32 c = '\0';
// int8_t x = 0 ; // character position in line 0 ---> 13
// int8_t y = 0 ; // active line pointer 0 ---> 5
int8_t k = 0 ;
initSystem();
Flag = 1; // firstTime since power-on or reset

for(;;)
{
if (Flag == 1) {
GLCD_WRITE("Waiting on GPS") ;
// Flag = 0;
}
c = UART_UartGetChar(); // Get received character or null
if (c)
{
if(c == '$') { // $ start of NMEA sentences
for(k=0; k<5; k++) // need 5 characters for sentence type
{
LED_Write( ~LED_Read() ); // flicker LED for activity
do {
c = UART_UartGetChar();
}
while (! (c));
nmea[k] = c; // G + P + R + M + C
// sprintf(buffer + k, "%c", c) ; // only for debug
}
// DEBUGGING to GLCD
// glcd_tiny_draw_string(0, 3, buffer);
// glcd_write() ; // display
LED_Write( LOW ); // LED off
if (strstr(nmea, "GPRMC"))
{
do {
do {
c = UART_UartGetChar();
LED_Write( ~LED_Read() ); // flicker LED
} while (!(c));
nmea[k] = c;
++k;
} while ( !( c == '*' ) && k < 120) ; // marker
LED_Write( LOW ); // LED off
// Inspiration: Limor Fried's Arduino GPS lib
char *p = nmea;
p = strchr(p, ',') + 1; // position after 1st comma
// float timef = atof(p);
// uint32_t time = timef;
uint32_t time = atoi(p);
hour = time / 10000;
minute = (time % 10000) / 100;
seconds = (time % 100);
// output to GLCD
sprintf(buffer, " %s",""); // clearbuffer

// this corrects time to the West but not the date!!!
if( hour > GMToffset) {
hour = hour - GMToffset;
} else {
hour = (hour + 24) - GMToffset; }

// correct midnight to follow standard format
if (hour == 24) hour = 0;

if (hour < 10) {
if (DayLightSavings) {
sprintf(buffer, "EDT: %d", hour);
} else {
sprintf(buffer, "EST: %d", hour);
}
} else {
if (DayLightSavings) {
sprintf(buffer, "EDT: %d%d", hour);
} else {
sprintf(buffer, "EST: %d%d", hour); }
}
if (minute < 10) {
sprintf(buffer + 7, ":0%d", minute);
} else {
sprintf(buffer + 7, ":%d%d", minute); }
if (seconds < 10) {
sprintf(buffer + 10,":0%d%s", seconds);
} else {
sprintf(buffer + 10, ":%d%d%s", seconds); }
sprintf(buffer + 13, "%s", "\0");
if(Flag == 1)
{
Flag = 0;
glcd_clear() ;
CyDelay(250) ;
}
// OUTPUT the TIME on GLCD
glcd_tiny_draw_string(0, 4, buffer);
glcd_write() ;
// Parse to integer date field
p = strchr(p, ',') +1; // A/V?
p = strchr(p, ',') +1; // lat
p = strchr(p, ',') +1; // N/S?
p = strchr(p, ',') +1; // lon
p = strchr(p, ',') +1; // E/W?
p = strchr(p, ',') +1; // speed
p = strchr(p, ',') +1; // angle
p = strchr(p, ',') +1; // move pass for date DDMMYY
// nmea date field looks like: 090914 (European)
uint32_t fulldate = atoi(p);
day = (fulldate / 10000);
month = (fulldate % 10000) / 100;
year = (fulldate % 100);
sprintf(buffer, " %s",""); // clearbuffer
if (day < 10) {
sprintf(buffer, "0%d", day);
} else {
sprintf(buffer, "%d%d", day); }
if (month < 10) {
sprintf(buffer + 2,"-0%d", month);
} else {
sprintf(buffer + 2,"-%d%d", month); }
sprintf(buffer + 5, "-20%d%d%s", year);
sprintf(buffer + 10,"%s",'\0');
// OUTPUT the DATE on GLCD
glcd_tiny_draw_string(0, 2, buffer);
glcd_write() ;
} // if (strstr(nmea, "GPRMC"))
} // if(c == '$')
} // if(c)
if( ResetSW_Read() == LOW ) // Forced program restart
{
goto ForcedReset;
}
} // for(,,)
} // main()

void initSystem()
{
CyGlobalIntEnable;
LED_Write( HIGH );
UART_Start();
glcd_init();
glcd_set_contrast(75); //0== light 100==full black
GLCD_TEXT_INIT();
init_printf(NULL, putdata); // see main.h
// Announce activity to over serial console in case listening
UART_UartPutString("Hardware Configured\n"); NewLine(); NewLine();
GLCD_WRITE("Terminal V1.00");
GLCD_WRITE("Ray Burnette");
CyDelay(2000);
glcd_clear();
}

/* [] END OF FILE */
Nokia5110GPS_PSoC4.cyprj.Archive03.zip

CODE
file_3727.txtC/C++
main.c
/*

Project: Nokia5110GLCD_PSoC4.cydwr (using bit-bang SPI)
Build date: 20140909 All code by Ray is public domain - OTHER? see Credits-Licenses.txt
UPDATED: 20140909 To include parsing of the month, day, and year
*/

#include <main.h>
#include <stdlib.h> // for function atoi()

#define NewLine() UART_UartPutChar(CR); UART_UartPutChar(LF); // Used to insert a CR/LF
// Prototypes
void initSystem (void);

// Global variables
uint8_t len = GLCD_LCD_WIDTH / 6; // 84 pixels / 6 == 14 ch/line
uint8_t hour, minute, seconds; //, year, month, day;
uint8_t day, month, year;

char buffer[GLCD_LCD_WIDTH / 6 + 1];
char nmea[120];

// double atof(const char *str); // elimited Limor's float implementation

_Bool DayLightSavings; // Pin 3.4
uint8_t GMToffset = 4;
uint8_t Flag = 1;

int main()
{
ForcedReset:; // come here if onboard reset button pushed
DayLightSavings = DSTime_Read(); // Normally true (HIGH)

if(! DayLightSavings) GMToffset += 1;

uint32 c = '\0';
// int8_t x = 0 ; // character position in line 0 ---> 13
// int8_t y = 0 ; // active line pointer 0 ---> 5
int8_t k = 0 ;
initSystem();
Flag = 1; // firstTime since power-on or reset

for(;;)
{
if (Flag == 1) {
GLCD_WRITE("Waiting on GPS") ;
// Flag = 0;
}
c = UART_UartGetChar(); // Get received character or null
if (c)
{
if(c == '$') { // $ start of NMEA sentences
for(k=0; k<5; k++) // need 5 characters for sentence type
{
LED_Write( ~LED_Read() ); // flicker LED for activity
do {
c = UART_UartGetChar();
}
while (! (c));
nmea[k] = c; // G + P + R + M + C
// sprintf(buffer + k, "%c", c) ; // only for debug
}
// DEBUGGING to GLCD
// glcd_tiny_draw_string(0, 3, buffer);
// glcd_write() ; // display
LED_Write( LOW ); // LED off
if (strstr(nmea, "GPRMC"))
{
do {
do {
c = UART_UartGetChar();
LED_Write( ~LED_Read() ); // flicker LED
} while (!(c));
nmea[k] = c;
++k;
} while ( !( c == '*' ) && k < 120) ; // marker
LED_Write( LOW ); // LED off
// Inspiration: Limor Fried's Arduino GPS lib
char *p = nmea;
p = strchr(p, ',') + 1; // position after 1st comma
// float timef = atof(p);
// uint32_t time = timef;
uint32_t time = atoi(p);
hour = time / 10000;
minute = (time % 10000) / 100;
seconds = (time % 100);
// output to GLCD
sprintf(buffer, " %s",""); // clearbuffer

// this corrects time to the West but not the date!!!
if( hour > GMToffset) {
hour = hour - GMToffset;
} else {
hour = (hour + 24) - GMToffset; }

// correct midnight to follow standard format
if (hour == 24) hour = 0;

if (hour < 10) {
if (DayLightSavings) {
sprintf(buffer, "EDT: %d", hour);
} else {
sprintf(buffer, "EST: %d", hour);
}
} else {
if (DayLightSavings) {
sprintf(buffer, "EDT: %d%d", hour);
} else {
sprintf(buffer, "EST: %d%d", hour); }
}
if (minute < 10) {
sprintf(buffer + 7, ":0%d", minute);
} else {
sprintf(buffer + 7, ":%d%d", minute); }
if (seconds < 10) {
sprintf(buffer + 10,":0%d%s", seconds);
} else {
sprintf(buffer + 10, ":%d%d%s", seconds); }
sprintf(buffer + 13, "%s", "\0");
if(Flag == 1)
{
Flag = 0;
glcd_clear() ;
CyDelay(250) ;
}
// OUTPUT the TIME on GLCD
glcd_tiny_draw_string(0, 4, buffer);
glcd_write() ;
// Parse to integer date field
p = strchr(p, ',') +1; // A/V?
p = strchr(p, ',') +1; // lat
p = strchr(p, ',') +1; // N/S?
p = strchr(p, ',') +1; // lon
p = strchr(p, ',') +1; // E/W?
p = strchr(p, ',') +1; // speed
p = strchr(p, ',') +1; // angle
p = strchr(p, ',') +1; // move pass for date DDMMYY
// nmea date field looks like: 090914 (European)
uint32_t fulldate = atoi(p);
day = (fulldate / 10000);
month = (fulldate % 10000) / 100;
year = (fulldate % 100);
sprintf(buffer, " %s",""); // clearbuffer
if (day < 10) {
sprintf(buffer, "0%d", day);
} else {
sprintf(buffer, "%d%d", day); }
if (month < 10) {
sprintf(buffer + 2,"-0%d", month);
} else {
sprintf(buffer + 2,"-%d%d", month); }
sprintf(buffer + 5, "-20%d%d%s", year);
sprintf(buffer + 10,"%s",'\0');
// OUTPUT the DATE on GLCD
glcd_tiny_draw_string(0, 2, buffer);
glcd_write() ;
} // if (strstr(nmea, "GPRMC"))
} // if(c == '$')
} // if(c)
if( ResetSW_Read() == LOW ) // Forced program restart
{
goto ForcedReset;
}
} // for(,,)
} // main()

void initSystem()
{
CyGlobalIntEnable;
LED_Write( HIGH );
UART_Start();
glcd_init();
glcd_set_contrast(75); //0== light 100==full black
GLCD_TEXT_INIT();
init_printf(NULL, putdata); // see main.h
// Announce activity to over serial console in case listening
UART_UartPutString("Hardware Configured\n"); NewLine(); NewLine();
GLCD_WRITE("Terminal V1.00");
GLCD_WRITE("Ray Burnette");
CyDelay(2000);
glcd_clear();
}

/* [] END OF FILE */


therion
Tue Jan 16, 2018 11:02 am
Mrburnette maybe You are right, i don’t like to read manuals like that, because they are in english and usually in technician language.
As You can see my english is wery bad, and it is problem for me. I’m using it when i must. I must use google translator to read/write posts here.

I write about blinking led because of my expeiments and experiencees with aduino.
When led was off there was nothing on screen, when blinking i had correct coordinates, led never be stabile on. Only off or blink status never on even after half hour outside. So in my opinion situation was simple, when LED off – bad, blinking – good:)

I dont have adapter, i am waiting for shipment from china, but it will be in next month.
Unfortunetly Youre code is too dificult for me, i am really begginer. I have made only few simple pojects based on examples:(


stevestrong
Tue Jan 16, 2018 12:24 pm
@therion, your results are somehow not coherent.
If you previously had some characters received from the GPS module, you should get some characters by the last example, too.
You should always test under the same conditions.
So go back and test all previous examples again.

Leave a Reply

Your email address will not be published. Required fields are marked *