0:10
hello and welcome to controllers tech
0:13
as promised in the previous video today
0:16
i brought to you another video on the
0:17
gps module where we will interface the
0:20
module with the stm32 microcontroller
0:24
as many of you might be using the neo
0:26
gps modules i have also switched to
0:29
neo6m for this video but it does not
0:32
matter as i have mentioned before the
0:34
output from all the gps modules is
0:39
they all outputs the data in the nmer
0:42
format and that is why you can use this
0:44
method for pretty much every gps module
0:48
if you remember from my previous video
0:51
this is the output of the gps module in
0:56
before starting this video i would want
0:58
you guys to get familiar with the ring
1:02
if you got the ring buffer code to work
1:04
you can go ahead with this one or else
1:07
first try to make that work
1:10
like i said i have switched to neo6m and
1:12
i have connected it with the ft 2 32
1:18
you can see the connection
1:20
the led on the 6m is blinking this means
1:24
that we have the fix on the signal
1:29
the t-x pin from the 6 em is connected
1:32
to the r-x pin of the ft-232
1:35
it's also connected to the r-x pin of
1:38
the uart-1 of the blue pill but for now
1:40
let's focus on the ft 232
1:46
the module is powered with 5 volts
1:49
supply from the blue pill
1:55
you can see the data it is transmitting
1:59
it's basically the same format as the
2:17
now i am going to connect the module to
2:19
3.3 volt supply and we will see the uart
2:29
you can see the output
2:31
if you are getting something like this
2:33
make sure you provide proper voltage
2:38
here i have switched back to 5 volts and
2:41
the transmission begins again
2:47
let's keep these things in mind and
2:50
create a new stm32 project
2:59
i am going to use stm 32 f103 3
3:05
give some name to the project and click
3:16
enable the external high speed crystal
3:20
also we need to enable the serial wire
3:25
there is 8 megahertz crystal on board
3:27
and let's run the system at maximum 72
3:36
all right now we will enable the uart
3:40
since the data incoming is of uncertain
3:42
length we need to use some circular or
3:45
ring buffer for the uart
3:48
i already did a video on it few years
3:50
ago and if you have made it work you are
3:52
good to go with this tutorial also
3:56
i would recommend that you watch that
3:58
video first if you haven't did it yet as
4:01
this code will heavily depend on that
4:07
let's enable the uart interrupt now
4:15
9600 board by default
4:18
i am relocating the uart pins for my
4:23
pv7 is the rx pin and pv6 is the tx pin
4:28
this is it click save to generate the
4:44
this here is the ring buffer code that i
4:49
here are the steps provided for this
4:51
particular code to work
4:55
i have already downloaded the ring
4:56
buffer files and now we will copy them
4:59
into the project along with the nmer
5:02
files i have created specifically for
5:12
put the c files into the source
5:14
directory and header files into the
5:28
let's see the ring buffer dot c file
5:32
we need to put this in the interrupt
5:42
first include the uart ring buffer
5:46
now define the uart isr function as
5:50
we need to also define the timeout as
5:54
this is needed for the timeout feature
5:58
inside the systick interrupt handler
6:00
decrease the timeout value
6:06
finally inside the uart interrupt
6:08
handler replace the interrupt handler
6:11
with uart isr function
6:14
make sure you update the correct uart
6:16
instance you are using
6:18
i have modified the rx buffer size to
6:21
512 bytes as there is large data in the
6:26
other than this the ring buffer code is
6:29
pretty much untouched
6:33
let's include the uart ring buffer
6:37
also include the nme a header file in
6:42
this is how the nme a header file looks
6:48
note that it only have two functions to
6:51
decode g-g-a and r-m-c
6:55
if you have watched my previous video on
6:57
gps you will know what these terms means
7:01
these two gives enough information for
7:08
all right let's initialize the ring
7:10
buffer now and build the code to check
7:19
there are no errors we can go ahead
7:23
let's debug the code once
7:26
this is to make sure if we are receiving
7:28
the data in the rx buffer or not
7:31
let's add the rx buffer to the live
7:43
let's see the buffer itself
7:46
here you can see we got the rmc string
7:48
or if you get any other string also it's
7:53
the main thing that we are checking is
7:55
if we are able to receive data or not
7:58
all right so the rx buffer is receiving
8:01
data and we are good to go
8:04
let's define an array to store the g g a
8:07
data and another one for the rmc data
8:13
next we will define this g p s structure
8:18
actually the decode functions take
8:20
respective structures as the parameters
8:22
but g p s structure contains both of
8:25
them and therefore we will only define
8:45
give some delay after initializing the
8:51
now we will wait for the gg a string in
9:02
if the string is detected the function
9:07
this function also includes the timeout
9:09
feature just in case if the string is
9:12
not detected it will timeout and the
9:14
execution will continue to the next
9:18
if the string is detected in the
9:20
incoming buffer we will copy up to the
9:22
star mark and we will save this data in
9:24
the ggr buffer we created earlier so
9:28
basically it will wait for this gga and
9:30
once found it will copy up to this star
9:35
this entire data in the middle will be
9:37
saved in rgr buffer which we will
9:41
after copying the data we will call the
9:46
the first parameter is the ggr buffer
9:49
where the data was saved
9:51
and the second parameter is the g g s
9:55
here we will pass the address of the g g
9:58
a struct element of the gps structure
10:01
let's build the code to check for any
10:08
all right we are good to go so let's
10:11
debug this much part first
10:13
add the gps data in the live expression
10:17
g structure have location time altitude
10:21
and the number of satellites
10:23
it also have the means to check if the
10:28
we have time here then the coordinates
10:31
this one indicates that the fix is valid
10:35
4 is the number of satellites
10:38
this is the altitude
10:40
all right let's run the code
10:45
we got the hard fault
10:47
let's put a break point inside the wait
10:49
for function and run it 2 3 times
10:53
now remove the break point and let it
10:56
here you can see is fix valid is set to
10:59
1. and if you see the coordinates they
11:02
are pretty much accurate
11:04
time is also correct
11:11
for the time conversion i have included
11:13
this variable and you need to edit it in
11:17
the time part is still needs to be
11:19
tested so if you are getting wrong time
11:22
let me know in the comments
11:24
so everything is working well and we
11:26
were able to decode the gg a parameter
11:32
let's write the same code for the rmc
11:43
this needs to be decode rmc
11:46
all right let's debug the code
12:02
you can see all the parameters are
12:04
pretty much working fine
12:06
the date today is 28 february
12:10
things are working fine and the gps data
12:13
we are getting is also accurate
12:17
let me explain the code so that you guys
12:20
can decode other things also
12:30
let's see the decoding of the gga
12:38
we first skip 6 commas
12:40
if you check the collected data you can
12:43
see this 1 comes after the 6 commas
12:46
we look at the data at this position if
12:48
the value is 1 2 or 6 that means the fix
12:53
for any other value the fix will be
12:55
invalid and we will return with some
12:59
by the way this function returns zero on
13:02
success and other numbers based on where
13:07
if the fix is valid we will continue
13:09
with the decoding and first of all we
13:11
will copy the data between first and
13:15
this data represents the time in utc
13:19
next step would be to extract the time
13:22
and adjust it according to the offset
13:25
this part is still untested and if you
13:27
get any error in time let me know in the
13:31
next task is to get the latitude
13:34
since we have already hit the comma in
13:36
the previous copying we will increment
13:39
the index to reach the first digit of
13:44
now we will copy this entire data into
13:52
after copying this data we will convert
13:54
the string into the number and do the
13:57
necessary calculation to extract the
13:59
latitudes from the data
14:07
we will increment the index again and
14:10
check for the north or south parameter
14:18
similarly we will get the longitude data
14:21
convert it into the number and extract
14:23
the longitudes from it
14:35
next we will skip the position fix
14:37
checking since we already checked it and
14:39
directly calculate the number of
14:42
used and finally get the altitude data
14:46
and convert it to number format
14:49
similarly we can decode the rmc data and
14:52
extract the date speed and other things
14:57
i will comment this code before
14:58
uploading it so that you can understand
15:02
now i know there will be some of you who
15:04
will still ask about how to display it
15:09
so i have decided to include that part
15:14
i am going to use the i-2-c to connect
15:19
this is why i have enabled the i-2-c-1
15:23
everything is set to default here
15:26
you need to include the i2c lcd
15:29
libraries in the project
15:47
now in the main file if the ggs string
15:50
is detected we will set the vcc timeout
15:55
this v-c-c timeout is basically for
15:57
checking if we are receiving the data or
16:01
you need to define it externally in the
16:03
interrupt file just like we did for the
16:07
also similar to timeout we need to
16:10
decrease its counter in the systick
16:19
this is where its defined
16:21
also note that i have defined the flags
16:23
for the g-g-a and r-m-c
16:27
these flags will be set if we receive
16:29
the valid data from the gps module
16:32
also there is lcd buffer which will
16:35
contain the character data respective to
16:40
all right after the g g a string is
16:42
detected we will reset the v c c timeout
16:45
and copy the g g a data into the buffer
16:49
if the decoding results in a success we
16:51
will set the g g a flag to 2 or else set
16:55
it to 1 indicating that the string was
16:57
received but the fix is still invalid
17:01
similar steps for the r m c data also
17:05
now if either of the received data is
17:07
valid we will put the lcd cursor to zero
17:12
then use s print f to convert the
17:13
numerical data into the characters and
17:16
save it in the lcd buffer
17:19
the first half of this will be hours
17:21
minutes and seconds from the ggs
17:25
and the later half will be the date from
17:36
once the converted data is saved into
17:38
the lcd buffer we will send it to the
17:42
then reset the buffer set the cursor to
17:45
the second row and convert the location
17:48
this point 2 f is to convert the float
17:51
data into decimal places
17:53
which is basically the latitude
17:56
the c here indicates the character which
17:59
indicates whether it's north or south
18:02
similarly we have for the longitude and
18:04
the character for east or west
18:07
finally we will send this data to the
18:11
now if the either of the flags is 1
18:13
indicating that the string was received
18:16
but the fix was invalid we will print
18:18
the respective information on the
18:23
notice here that i am not clearing the
18:25
display but instead i choose to go with
18:30
this is to ensure that every time we are
18:32
waiting for the fix the screen shouldn't
18:34
feel like it's refreshing
18:37
finally if the vcc timeout is zero that
18:40
means the gga or rmc strings were not
18:43
detected in the incoming buffer
18:46
this could only mean that either the
18:48
voltage is insufficient or there is some
18:50
problem with the connection between the
18:52
module and the microcontroller
18:55
so here we will print the respective
18:57
information on the display again
19:00
here you can see i have taken some
19:02
pictures for each case
19:04
this is when i provided 3.3 volts to the
19:12
this is when the voltage was fine but
19:21
and this is when everything was all
19:24
so this is it for the video
19:27
i hope you understood the concept well
19:30
decoding the nmea could be better and i
19:33
know there are some libraries available
19:34
to just parse this data but i like to
19:37
use my own code for whatever i can and
19:40
that's the only reason i wrote this
19:43
if you are getting errors in the ring
19:44
buffer library better comment below the
19:46
ring buffer video instead of this one
19:50
you can download the code from the link
19:54
leave comments in case of any doubt
19:58
keep watching and have a nice day ahead