GPS tracker with Pic microcontroller and SD card. - Page 1
Forum section: electronics / general

author: Gerelectronic
author_rank: Contributor
timestamp: March 12, 2021, 09:39:38 am
content: 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;)

author: iMo
author_rank: Super Contributor
timestamp: March 12, 2021, 11:06:23 am
content: 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..

author: Gerelectronic
author_rank: Contributor
timestamp: March 12, 2021, 11:55:33 am
content: 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.

author: iMo
author_rank: Super Contributor
timestamp: March 12, 2021, 12:33:58 pm
content: 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 happyOr at least the new atmega3208 or atmega4808 made by MCHPI 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..

author: Ian.M
author_rank: Super Contributor
timestamp: March 12, 2021, 01:10:18 pm
content: 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/allcould 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.

author: iMo
author_rank: Super Contributor
timestamp: March 12, 2021, 01:43:27 pm
content: 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 examplehttps://www.microchip.com/wwwproducts/en/PIC24HJ128GP502Alternatively18FxxK40 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 Deviceshttps://www.microchip.com/en-us/solutions/low-power

author: Gerelectronic
author_rank: Contributor
timestamp: March 12, 2021, 02:05:24 pm
content: 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.

author: Gerelectronic
author_rank: Contributor
timestamp: March 12, 2021, 02:10:06 pm
content: 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.

author: rstofer
author_rank: Super Contributor
timestamp: March 12, 2021, 04:30:45 pm
content: There's a book about using PICs with SD Cards:https://www.amazon.com/Card-Projects-Using-PIC-Microcontroller-ebook/dp/B003M5HUL2

author: rstofer
author_rank: Super Contributor
timestamp: March 12, 2021, 04:37:52 pm
content: 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

author: DiTBho
author_rank: Super Contributor
timestamp: March 12, 2021, 06:19:53 pm
content: Quote from: rstofer on March 12, 2021, 04:37:52 pmSix 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

author: iMo
author_rank: Super Contributor
timestamp: March 12, 2021, 07:17:53 pm
content: There are two proven sdcard FAT systems for small MCUs people use since ever (at least 10y).SdFat by by Bill GreimanFatFs by Elm-ChanFYI -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 doneBtw, written as an example by my younger brother for ..duinosQuoteDownload is here

author: TomS_
author_rank: Frequent Contributor
timestamp: March 13, 2021, 07:18:33 am
content: Quote from: Gerelectronic on March 12, 2021, 02:10:06 pmWhat 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.

author: Gerelectronic
author_rank: Contributor
timestamp: March 13, 2021, 08:19:27 am
content: Hi DiTBho, could you tell me how you made your filesystem?

author: Gerelectronic
author_rank: Contributor
timestamp: March 13, 2021, 08:23:27 am
content: 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."

author: TomS_
author_rank: Frequent Contributor
timestamp: March 13, 2021, 08:38:36 am
content: No HALs, no libraries, just configuring registers directly.

author: oliviasmithh901
author_rank: Newbie
timestamp: March 20, 2021, 04:28:14 am
content: 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.

author: DiTBho
author_rank: Super Contributor
timestamp: March 20, 2021, 10:53:17 am
content: 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.

author: H.O
author_rank: Frequent Contributor
timestamp: March 25, 2021, 09:35:08 pm
content: 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.

author: Jan Audio
author_rank: Frequent Contributor
timestamp: March 27, 2021, 04:37:13 pm
content: 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.