Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no daemon?

Sun Jul 02, 2017 7:36 am

hello,
does someone have a C source code (possibly a library) for the GPS sensor Ublox GY-NEO-6M?
What I am looking for is a source/library in C code (e.g. by wiringPi, wiringSerial) via UART, no USB, no GPS daemon ?
For Arduinos I found lots of examples (e.g. tinyGPS lib https://github.com/mikalhart/TinyGPSPlu ... xample.ino ), something simple like that I am searching now for the Raspi.

User avatar
topguy
Posts: 5682
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Sun Jul 02, 2017 11:44 am

What functionality are you looking for ? Its usually nothing special about the uBlox GPS. Its a GPS , it outputs NMEA messages over a serial interface.
Any C-code that parses NMEA messages would be helpful, and any example on how to read lines from a serialport is relevant.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Sun Jul 02, 2017 11:55 am

what's puzzling me is the huge amount of data and I have no idea how and where to start to read by serialDataAvail () and serialGetchar() and where and when to stop in order to get the data in the right order and don't miss or drop some or completely mess them up:

gps.location.lat() // Latitude in degrees (double)
gps.location.lng() // Longitude in degrees (double)
gps.location.rawLat().deg // Raw latitude in whole degrees
gps.location.rawLat().billionths // ... and billionths (u16/u32)
gps.location.rawLng().deg // Raw longitude in whole degrees
gps.location.rawLng().billionths // ... and billionths (u16/u32)
gps.date.value() // Raw date in DDMMYY format (u32)
gps.date.year() // Year (2000+) (u16)
gps.date.month() // Month (1-12) (u8)
gps.date.day() // Day (1-31) (u8)
gps.time.value() // Raw time in HHMMSSCC format (u32)
gps.time.hour() // Hour (0-23) (u8)
gps.time.minute() // Minute (0-59) (u8)
gps.time.second() // Second (0-59) (u8)
gps.time.centisecond() // 100ths of a second (0-99) (u8)
gps.speed.value() // Raw speed in 100ths of a knot (i32)
gps.speed.knots() // Speed in knots (double)
gps.speed.mph() // Speed in miles per hour (double)
gps.speed.mps() // Speed in meters per second (double)
gps.speed.kmph() // Speed in kilometers per hour (double)
gps.course.value() // Raw course in 100ths of a degree (i32)
gps.course.deg() // Course in degrees (double)
gps.altitude.value() // Raw altitude in centimeters (i32)
gps.altitude.meters() // Altitude in meters (double)
gps.altitude.miles() // Altitude in miles (double)
gps.altitude.kilometers() // Altitude in kilometers (double)
gps.altitude.feet() // Altitude in feet (double)
gps.satellites.value() // Number of satellites in use (u32)
gps.hdop.value() // Horizontal Dim. of Precision (100ths-i32)

In other words, I have no idea about this entire task :?

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Mon Jul 03, 2017 6:49 pm

Stiller wrote:In other words, I have no idea about this entire task :?
I got my first GPS module quite recently, so I don't quite familiar with it either.

Firstly, you need connect your module to the Pi. How to use Pi's UART: https://www.raspberrypi.org/documentati ... on/uart.md

The UART interface talk in ASCII.
So you could test your module with sudo cat /etc/serial0 | grep RMC.
You should see something like: GPRMC,235316.000,A,2959.9925,S,12000.0090,E,0.009,75.020,020711,,,A*45

This is a string containing time, position and other info I don't understand either. It's a protocol called NMEA. I found a Chinese document about it: http://www.icofchina.com/xiazai/

But you don't have to parse that string by yourself, there is the gpsd: http://www.catb.org/gpsd/
gpsd is a daemon read the NMEA string (or other binary protocol), and translate it for you.
There is the C library called libgps.

So the whole idea is:
1 Connect the GPS module to Pi via UART
2 Run gpsd on Pi to read the GPS info
3 Programing on client machine using libgps to access the info via network

And I currently trying to solve the cross compile mysteries here. Not figure it out yet. The ARM compiler from Ubuntu repo seems not working very well.

User avatar
bensimmo
Posts: 4156
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Mon Jul 03, 2017 9:11 pm

With the Ublox you can switch it into its native data stream, I would assume that is better than the NMEA data (easy to work out what is what,just goto the NMEA site telling you)

gpsmon switches into native mode normally.

Just look around or write your own... Once you've learned what everything is.

RaspberryPi tends to be less plug and dump someone else code in than Arduino.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 6:03 am

I already looked around but I don't understand anything about what to do.
OTOH, @allfox: what you suggest is using a daemon (gpsd), but as you can read in my thread opening post, I do not want to use that ("no daemon" !), but just (more or less simple) C source code, just like it's used by Arduinos.

Is there really no one who ever achieved to provide a working source code or even a library for the Pi like those which are availabe for Arduino?
Unfortunately I also don't understand C++, just C, so I am also not able to understand the code of the Arduino tinyGPS++ library at all. Finally I actually simply just want to use my GY-NEO-6M GPS sensor with the Pi, to poll position (latitude, longitude), heading, and perhaps number of satellites, speed, and date/time (when no Wifi access outside).

User avatar
bensimmo
Posts: 4156
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 7:57 am

Why not use python* and what's wrong with using a Daemon. You don't need to use it (you just read direct from the serial port stream)
Setup the GPS module on the UART, check it's streaming data to it in, assuming standard UART setup, " cat /dev/serial0 " if you have not got that far, that's the first step. The UBlox GPS is doing the hard work and putting it into a simple standard NMEA format, it a CSV file stream.

Then just read, (so learn how to read a serial stream).
Parse on a keyword (just one of the lines holds pretty much all you 'GGA' one. Search or look at the Arduino code or plenty in Python to see what it all means.
Takes the bits you need and send or write to where every you want it.
No Daemon needed. (The gpsd Daemon does mean you could just run that on the Pi and then read it from anything else via a network of some sort link)

* I don't use C or C++
Unfortunately the Pi is more about teaching people to learn and work it out for themselves and mainly in Python (the 'Pi' part comes from Python originally)

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 8:34 am

as stated in my thread-opening post, I need C code.
I always program in C, no Python at all. So what is possible in C(++) for Arduinos should be possible also for the Pi, and as the Arduinos don't use daemons but straight C(++) code , that shoud be actually also possible for the Pi, which works out of the box, like it does for Arduinos, too.
Stiller wrote:hello,
does someone have a C source code (possibly a library) for the GPS sensor Ublox GY-NEO-6M?
What I am looking for is a source/library in C code (e.g. by wiringPi, wiringSerial) via UART, no USB, no GPS daemon ?
For Arduinos I found lots of examples (e.g. tinyGPS lib https://github.com/mikalhart/TinyGPSPlu ... xample.ino ), something simple like that I am searching now for the Raspi.

User avatar
topguy
Posts: 5682
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 8:45 am

Stiller wrote: Is there really no one who ever achieved to provide a working source code or even a library for the Pi like those which are availabe for Arduino?
Google gives plenty..
* https://github.com/cloudyourcar/minmea
* https://github.com/jacketizer/libnmea
* https://github.com/fhuberts/nmealib
* http://walterdalmut.com/2013/11/23/rasp ... ng-system/ ( points to this: https://github.com/wdalmut/libgps )

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 9:00 am

thank you,
https://github.com/wdalmut/libgps/blob/ ... n_logger.c and https://github.com/jacketizer/libnmea/b ... /minimum.c just give position, no heading, and no number of satellites, time/date. For the both remaining I don't see matching examples, tbh.

User avatar
topguy
Posts: 5682
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 9:18 am

That example only parsed GLL messages ( http://www.gpsinformation.org/dale/nmea.htm#GLL) , which dont have that information.
That library also is capable of parsing RMC messages ( http://www.gpsinformation.org/dale/nmea.htm#RMC ) which contain direction and speed.
Edit: That guy has been lazy, his code only care about location he dont parse the values for speed and direction. You can add it yourself or test one of the other libraries.

Information about satellites and signal strenght are in GSA and GSV messages, but there you need to combine data from more lines so its a little more complex. That library havent bothered with that.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 9:30 am

topguy wrote:That example only parsed GLL messages ( http://www.gpsinformation.org/dale/nmea.htm#GLL) , which dont have that information.
That library also is capable of parsing RMC messages ( http://www.gpsinformation.org/dale/nmea.htm#RMC ) which contain direction and speed.
Edit: That guy has been lazy, his code only care about location he dont parse the values for speed and direction. You can add it yourself or test one of the other libraries.

Information about satellites and signal strenght are in GSA and GSV messages, but there you need to combine data from more lines so its a little more complex. That library havent bothered with that.
hm, I stll don't see quite clear about all that.
Probably it would be best if there was a portation of the tinyGPS++ lib available to be used for the Pi, because this lib provides all and everything, simple, convenient, and ready to use

User avatar
bensimmo
Posts: 4156
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 11:22 am

I was giving information so you could look up and learn and do it yourself. If you wish to be lazy that is up to you.
Python works, Daemon works you can then convert to Come as you wish and understand what the code is doing.
You don't seem to be Programming at all, just using other people code. More 'hacking' as they call it.

So my advise is use Google more until you hit something that works in some repository somewhere.
Raspberry is not the same as Arduino. The community works differently.

First question is can you see the data coming off the GPS as given above?
Without that no library, bodge,hack in any language will work.

User avatar
bensimmo
Posts: 4156
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 12:30 pm

That's what my searches always seem to end up linking to for C.

A search on "libgps Raspberry Pi" brings up lots of thing, but I'm not going to read through them :-)

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 12:30 pm

as stated above:
Stiller wrote:as stated in my thread-opening post, I need C code.
I always program in C, no Python at all. So what is possible in C(++) for Arduinos should be possible also for the Pi, and as the Arduinos don't use daemons but straight C(++) code , that shoud be actually also possible for the Pi, which works out of the box, like it does for Arduinos, too.
Stiller wrote:hello,
does someone have a C source code (possibly a library) for the GPS sensor Ublox GY-NEO-6M?
What I am looking for is a source/library in C code (e.g. by wiringPi, wiringSerial) via UART, no USB, no GPS daemon ?
For Arduinos I found lots of examples (e.g. tinyGPS lib https://github.com/mikalhart/TinyGPSPlu ... xample.ino ), something simple like that I am searching now for the Raspi.
of course the code which one may point to should be tested. And Ididn't ask for reverse engineering of either vague code .
Last edited by Stiller on Tue Jul 04, 2017 12:35 pm, edited 1 time in total.

User avatar
bensimmo
Posts: 4156
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 12:34 pm

As stated the Pi does not work out of the box.
You have to get the hardware working first, this is not Arduino.

Only then can you get the C code working to read the GPS.
You have the links to libgps.
Have fun.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 12:37 pm

if Arduino code can work out of the box, then also Pi code will be able to, presupposed it does actually exist.
Also for several MCPs and PCFs there is C code which works out of the box (e.g., wiringPi code), so why not for the GPS sensor?
At least the GPS code topguy pointed to, doesn't.

User avatar
topguy
Posts: 5682
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 1:18 pm

There is 5+ different Pi models, and at least two different ways of connecting a GPS. There is at least 15 programming languages that you can use to read the data and a myriad of variants of different GPSs.

The people who leave this forum the most disappointed is the ones that comes here looking for very simple recipes that is guaranteed to work for their specific use case.
We can usually only point in the direction you need to walk, we can not walk the path for you.

SteveSpencer
Posts: 351
Joined: Thu Mar 28, 2013 9:19 am
Location: Nottingham, UK

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 1:22 pm

To the original OP - read topguy's comment above. Should you not fully appreciate it, I have explained it below (while topguy was typing their response)

The problem you face is quite simple. The TinyGPS+ library was written for Arduino, in C++. You don't know C++. Lots of other sample code was written in Python. You don't know Python.
Presumably because of the "No C++, No Python", you can't (or won't) reverse engineer existing code.
In addition, you have been advised on things to look at; you searched for "libgps raspberry pi", but won't read any of the resultant articles.

The whole thing about the Pi that many people overlook is that it was designed to get kids interested in computers, by letting them loose on real-world computers that are inexpensive, so breaking one isn't a major deal.

It seems to me, from reading this thread, that what /you/ want is to have someone do all the hard work (producing the library), so you can literally just drop it into your code with next to no effort. Now be honest, where's the learning process in that?

In the past, when I have not been able to find exactly (or in some cases, nothing even close) to what I wanted, then I sat down, and worked through it - I didn't complain no one had done it before, I didn't gripe that someone had only done half of what I wanted. Instead, I got on with learning it, and generally, learned a lot more besides along the way. Then when I'd done what I needed, usually "gave it away", by answering questions.

Comparing platforms won't solve the problem, either. Like the Pi, Arduino is where it is because of the user community. Sure, there are lots of libraries out there for the Arduino and various exotic bits of hardware. Generally, you only have one language option though.
Funnily enough, this is partially true for the Pi. The issue for you is that it is not in a form that you can use straight out of the box. If you used python, you could use quite a lot out of the box.

Pimoroni (a Pi reseller) produce lots of hardware add-ons, as well as fine cases for the Pi range. They also produce libraries for the hardware to allow people to make use of it (check out their SkyWriter, or their Unicorn, or Mote offerings). Now, I don't generally do Python. I like C, and C++, because to me, using a compiled language that isn't format sensitive seems sensible. I learned very early on that they don't do C or C++ libraries generally; they expect (probably correctly) that more people will use Python. I don't, so I learned enough to be able to "reverse-engineer" their code, and produce C/C++ versions for my own use.

It's not THAT difficult, and it all goes towards learning more about what you're trying to achieve.
Steve S
No, I can't think of anything funny that won't offend someone if they want it to...

User avatar
bensimmo
Posts: 4156
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 1:24 pm

Edit/ what they said/edit

If the code is written, in whatever language and it was written recently then it would probably work.
The Pi is not a microcontroller, so the OS it runs on changes over time and the way it works changes over time. That is if you use the same OS.
Baremetal applications of it may work better.
But the serial port would also need somebody to run a script to enable and disable parts as needed to read from the UART device.
Hence why I ask, do you get a data stream off it and get a lock. No code is needed for that. It may also be why other code is not working.
It's not just stick it on the pins and run a C/python/ruby/basic/red/.. program normally.

I've not seen anyone interface directly in native uBlox yet, not even in Python. It's always been read and parse NMEA data.

Hopefully for you somebody will come along with some recent code in C.

While you wait, what are you trying to do with it?

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 2:18 pm

topguy wrote:There is 5+ different Pi models, and at least two different ways of connecting a GPS.
ok, that has not been asked before, I thought UART == UART.
I have a Pi 2 (old one), and UART is at physical pins 8+10
UART works already, "/dev/ttyAMA0".
#include <wiringPi.h>
#include <wiringSerial.h>
int Serial;
//probably for GPS to be initialized by
Serial = serialOpen ("/dev/ttyAMA0", 9600);

so the only thing what's missing is a GPS code that works out of the box, like the tinyGPS++ lib for Arduino, and yes, I really do not want to invent the wheel from the scratch for that device.
With my Arduinos and this tinyGPS++ library it works already, since a couple of years.

User avatar
bensimmo
Posts: 4156
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Tue Jul 04, 2017 3:34 pm

Switch ttyAMA0 to serial0
Not for your use but for future use if you move to a Pi3 or PiZeroW or whatever else comes along.
Not all Pi's use ttyAMA0 but serial0 will always point to the GPIO pins UART.

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Wed Jul 05, 2017 1:27 pm

bensimmo wrote:Switch ttyAMA0 to serial0
Not for your use but for future use if you move to a Pi3 or PiZeroW or whatever else comes along.
Not all Pi's use ttyAMA0 but serial0 will always point to the GPIO pins UART.
yes, I'll gladly do so, given that a GPS code will be available for the Pi that'll work out of the box ;)

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Thu Jul 06, 2017 5:46 pm

I can't believe that the Raspi programmer community (other than the Arduino community) can't provide simple C driver codes for such sensor devices... I think I'll stay with my Arduinos for my sensors where I have functioning code available - and perhaps then interface an Arduino to the Pi, just to make the things finally work. Really embarrassing actually...

User avatar
bensimmo
Posts: 4156
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: Ublox GY-NEO-6M: C code (e.g. wiringPI) via UART, no dae

Thu Jul 06, 2017 7:33 pm

That's up to you, but have you asked the supplier or ublox for some drivers for it?.
Or perhaps be the community and make some for people.

Return to “C/C++”