Author Topic: GPS tracker with Pic microcontroller and SD card.  (Read 3362 times)

0 Members and 1 Guest are viewing this topic.

Offline GerelectronicTopic starter

  • Contributor
  • Posts: 13
  • Country: it
GPS tracker with Pic microcontroller and SD card.
« on: March 12, 2021, 09:39:38 am »
Hello everyone.
I would like to be able to program a pic (16 or 18) that works like this:
the pic microcontroller must take the coordinates, time and date out of a Gps module and every certain period of time must:
- record them on an SD card;
- send them to the lcd display.
When the SD card is removed, it can be fed into a computer that acquires its data.
The GPS module must have a high reception.
The program must be done with Mikroc.

The basic circuit is shown in the figure, obviously it is only a starting point and you can modify it according to your needs.
In practice, my goal is to create a device capable of memorizing the place, date and time of use of a means of transport on the SD card which will then be inserted into a computer capable of acquiring the data.

Sorry for my bad English.
A big thanks to all those who manage to implement the program on Mikroc and choose the right components.
P.S I'm desperate;) |O :'(
 

Online iMo

  • Super Contributor
  • ***
  • Posts: 4782
  • Country: pm
  • It's important to try new things..
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #1 on: March 12, 2021, 11:06:23 am »
Some remarks:
1. your SDcard's resistive dividers are wired in a wrong way. Mind the Sdcards are 3.3V only devices.
2. the writing larger amount of data fast to an sdcard requires a FIFO buffer, as an sdcard has got so called "write latency" up to 250ms long (based on type) - WL is a "random" event, you cannot write to the card during WL. It may not apply to your data rate, however..
« Last Edit: March 12, 2021, 11:16:12 am by imo »
 
The following users thanked this post: Gerelectronic

Offline GerelectronicTopic starter

  • Contributor
  • Posts: 13
  • Country: it
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #2 on: March 12, 2021, 11:55:33 am »
Thanks a lot Imo. As for the interfacing of the pic with the GPS module, you know something?, because this is what gives me more problems.
Thanks again.
 ^-^
 

Online iMo

  • Super Contributor
  • ***
  • Posts: 4782
  • Country: pm
  • It's important to try new things..
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #3 on: March 12, 2021, 12:33:58 pm »
The GPS modules send out messages 1..10x per second in a "readable text" or in "binary" formats. You have to decide and setup the GPS module and the parser accordingly. Otherwise - the pic16F877 is NOT capable of doing what you want to achieve. It has got only 386bytes of RAM, for handling SDcards you need much more ram. Take an MCU with at least 2kB of ram... In case of the pic family the minimal MCU "capable" for your exercise is something like the 18F252 or 18F452 with 1.5kB of ram, imho. When talking MCHP me personally I would take pic24xxx or dspic33xxx to make my GPS logger happy  :P
Or at least the new atmega3208 or atmega4808 made by MCHP :)

I would highly recommend you to search for an existing solution and do reuse it.. There have been a plethora of GPS trackers published in the last 20 years, imho..
« Last Edit: March 12, 2021, 01:01:48 pm by imo »
 
The following users thanked this post: Gerelectronic

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12859
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #4 on: March 12, 2021, 01:10:18 pm »
Personally I regard MikroC as an abomination, but if you want to work in an expensive closed source 'walled garden' that's up to you.

Also your choice of an 8 bit PIC is already constraining your solution space making it more difficult to implement.  e.g. on Arduino, this shield: https://learn.sparkfun.com/tutorials/gps-logger-shield-hookup-guide/all could have you up and running in an afternoon.  Then, if you need to, miniaturize it by designing a single board carrying the GPS module, SD card socket, AVR MCU and associated parts that fits as a piggy-back board on the back of your LCD module, within its form factor.

However, if you *MUST* use an 8 bit PIC . . .

A SD card has 512 byte sectors.  To be able to write to the card with a FAT filesystem so it can be read on a PC, you *MUST* be able to buffer at least one sector in RAM.   As Imo has pointed out, you need to be able to buffer 250ms of your data stream to be able to reliably write a realtime data stream to the card, so you need significantly more than a single sector's buffer.   You also need enough RAM to handle reading and decoding the NMEA 0183 sentences  from the GPS.   If you are coding 'bare metal' you can probably get away with decoding the NMEA data on the fly and only storing the essential data fields in a compact binary format in a ring buffer, which is then expanded into whatever data format you need the output file to be in to fill the sector buffer.  That could be done in under 1K RAM.  However it would be an absolute PITA to code.   An easier approach would be to have enough RAM for two sector buffers, used in alternation, each written as soon as its full + enough to buffer two full NMEA 0183 sentences so you can simply receive a full sentence before decoding it.   The RAM requirements alone prevent you using a 'classic' midrange (PIC16) part.  There are some enhanced midrange (PIC16F1.....) parts with enough RAM but their interrupt handling is clunky compared to PIC18, and as you have to manage keeping the SPI peripheral 'fed' with sector data being streamed to the SD card without missing characters from the UART, multiple interrupt priorities or even vectored interrupts would be useful.  Therefore I wouldn't even attempt this project on anything less than a PIC18 with a UART, SPI peripheral and 2K RAM. 

To avoid a lot of trouble with level conversion, it makes sense to run the PIC at 3.3V Vdd.  You can get 3.3V GPS modules, and also HD44780 displays, (or most 5V ones can be converted), and the SD card interface will be less troublesome and far more reliable if the PIC and SD card are using the same logic levels rather than resistive dividers.

The GPS interface can often be direct to the PIC's UART pins if it has logic level I/O at the same logic level as your PIC.  If its true NMEA 0183 then its 5V semi-RS232 compatible, and requires inversion and possibly level conversion if you are using 3.3V Vdd.  Some PIC18 UARTs can handle the inversion in internal hardware, only leaving level conversion.  You can use a potential divider for downwards level conversion,  and a N-MOSFET + pullup resistor for upwards level conversion.
« Last Edit: March 12, 2021, 07:53:14 pm by Ian.M »
 
The following users thanked this post: Gerelectronic

Online iMo

  • Super Contributor
  • ***
  • Posts: 4782
  • Country: pm
  • It's important to try new things..
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #5 on: March 12, 2021, 01:43:27 pm »
IMHO, when insisting on PIC the "optimal candidate" would be the pic24xxx with 8kB ram and 128kB flash.
It is a 3.3V chip and with pretty good performance (max Fcpu=40-80MHz, clock=Fcpu/2), so it will be ok with reading/parsing 10 messages per second and writing the stuff to the sdcard without any lost data.
The HD44780 displays usually work fine with 3.3V signals (they need 5V Vcc, however)..
None dividers with the sdcard required then.
The GPS module's Tx/Rx are with 3.3V signals too, afaik.
You have to implement at least 10messages*250ms= ~3-4 records deep FIFO buffer for writing the data records to the sdcard in order to be on the safe side (mind the WL).

For example
https://www.microchip.com/wwwproducts/en/PIC24HJ128GP502

Alternatively
18FxxK40 family with 3.7kB sram and 64-128kB flash..
18F16Q40 family with 4kB sram and 64kB flash..

PS: another thing to consider is the power consumption of the logger.  So you have to consider the power budget too.. [ie. 30-500uA/MHz with various MCHP families].. The SDcards take 40-200++mA when written based on type/capacity..

See - Microchip eXtreme Low Power Devices

https://www.microchip.com/en-us/solutions/low-power
« Last Edit: March 12, 2021, 03:02:47 pm by imo »
 
The following users thanked this post: Gerelectronic

Offline GerelectronicTopic starter

  • Contributor
  • Posts: 13
  • Country: it
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #6 on: March 12, 2021, 02:05:24 pm »
Thanks a lot Imo.
Could you please send me some links on the GPS trackers, because I did a lot of research, but actually all the programs found online and made through Mikroc did not work.
The pic I can change it easily.
In place of Mikroc is there any other software that you think is better for programming Pic?
Thanks so much again.  8)
 

Offline GerelectronicTopic starter

  • Contributor
  • Posts: 13
  • Country: it
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #7 on: March 12, 2021, 02:10:06 pm »
Thanks Ian M.
Actually I use Mikroc, because it is the only professional enough Pic program that I am able to use.
What programming software do you think I should use?
How would you carry out this project?
Should I maybe use another microcontroller?
Thank you very much for everything, the information you have given me is very useful.  ;D :-+
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #8 on: March 12, 2021, 04:30:45 pm »
 
The following users thanked this post: Gerelectronic

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #9 on: March 12, 2021, 04:37:52 pm »
There are MANY of these GPS tracker projects on the Internet, try to Google for them.  No point in reinventing the wheel.

I would probably look at using the Arduino.  Not because it is excellent but because everything that can be done with that chip has been done and it's all over the Internet.  I can select a 3.3V version of the Arduino if it makes the project a little easier.

Start here...

https://youtu.be/9-v5hNuHFq4
 
The following users thanked this post: Gerelectronic

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 3915
  • Country: gb
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #10 on: March 12, 2021, 06:19:53 pm »
There are MANY of these GPS tracker projects on the Internet, try to Google for them.  No point in reinventing the wheel.

Six years ago, I started with "I want to record latitude and longitude to an SD card on a stand alone card", and ended up spending five years designing and writing my own filesystem.

Someone had told me "it makes no sense to reinvent the wheel", so I invented something weirder :D
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Online iMo

  • Super Contributor
  • ***
  • Posts: 4782
  • Country: pm
  • It's important to try new things..
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #11 on: March 12, 2021, 07:17:53 pm »
There are two proven sdcard FAT systems for small MCUs people use since ever (at least 10y).
SdFat by by Bill Greiman
FatFs by Elm-Chan

FYI - here is a thread with a well working data logger Demo source for arduinos - it writes 20kB/sec of data on an Sdcard, under FreeRtos, with FIFO, with SdFat. There are posts with details on it..

You need a parser task (the producer - replace the ADC sampling there with GPS message parsing) for getting your data off the NMEA message and the job is done :)
Btw, written as an example by my younger brother for ..duinos :)

Quote
Below you may find a complete Demo I wrote for MapleMini and BluePill and an SDcard connected to SPI1:
1. we sample 8 ADCs, 200x per second,
2. we apply 30Hz FIR low pass filter on each ADC channel measurement,
3. we write the data into the FIFO buffer,
4. in parallel we read the data off the FIFO and write the data onto the SDcard as fast as we can (mind WL),
5. the format we write the data on the Sdcard is .CSV, so you may analyze what is going on in Excel directly,
6. we also log information on the FIFO statuses (the values of counting semaphores) within each record.

Download is here
« Last Edit: March 12, 2021, 08:07:49 pm by imo »
 
The following users thanked this post: Gerelectronic

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #12 on: March 13, 2021, 07:18:33 am »
Actually I use Mikroc, because it is the only professional enough Pic program that I am able to use.
What programming software do you think I should use?
What is wrong with Microchips own tools? MPLABX and XC compilers?

Granted, I believe MikroC comes with some abstraction libraries to make it easier for beginners, but if you're doing that then maybe MPLABX Harmony also works.

But I don't really know - I program everything from scratch. It's not that hard, just requires patience to read the datasheet and understand the various options each peripheral has and configure them accordingly.
 
The following users thanked this post: Gerelectronic

Offline GerelectronicTopic starter

  • Contributor
  • Posts: 13
  • Country: it
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #13 on: March 13, 2021, 08:19:27 am »
Hi DiTBho, could you tell me how you made your filesystem?
 

Offline GerelectronicTopic starter

  • Contributor
  • Posts: 13
  • Country: it
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #14 on: March 13, 2021, 08:23:27 am »
Forgive my ignorance TomS_ but I'm not sure I understand what you mean by this sentence:
"But I don't really know - I program everything from scratch. It's not that difficult, it just requires patience to read the datasheet and understand the various options of each device and configure them accordingly."
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 834
  • Country: gb
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #15 on: March 13, 2021, 08:38:36 am »
No HALs, no libraries, just configuring registers directly.
 
The following users thanked this post: Gerelectronic

Offline oliviasmithh901

  • Newbie
  • !
  • Posts: 4
  • Country: us
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #16 on: March 20, 2021, 04:28:14 am »
IF you ask me, you should go for simulator first. Design your circuit in Proteus simulator and test yoru code there, it's best for beginners, completely test your code without any tension of hardware, soldering, programmer etc. and once you complete your functions then go for actual hardware.

Proteus already has PIC Microcontroller and you can find GPS library for Proteus easily online.
 

Offline DiTBho

  • Super Contributor
  • ***
  • Posts: 3915
  • Country: gb
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #17 on: March 20, 2021, 10:53:17 am »
I remember I recorded some data stream from a GPS to a text file and used it during development rather than having to deal with a real GPS, even because the radio indoor signal was really too bad.
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline H.O

  • Frequent Contributor
  • **
  • Posts: 814
  • Country: se
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #18 on: March 25, 2021, 09:35:08 pm »
Is this some sort of school assignment given the fairly strict specs? If you don't HAVE to interface the SD-card directly thus dealing with all the fielsystem stuff etc you could use an OpenLOG.  All it takes is a serial (bitbanged or UART) connection and it writes ASCII data to .txt file(s) on the card.
 

Offline Jan Audio

  • Frequent Contributor
  • **
  • Posts: 820
  • Country: nl
Re: GPS tracker with Pic microcontroller and SD card.
« Reply #19 on: March 27, 2021, 04:37:13 pm »
You can very easy create a file in your computer on a FAT32 formatted SD-card,
fill it with the exact size you are going to write into it,
that will be multiples of 4096.

Now you dont have to worry about a file system, just get the correct file from the root by reading a few things.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf