Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to I²C)

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Tommie »

Try the MWC patch above. I introduced a paperbag worthy mistake while doing the coordinate transformation.

charbot
Posts: 34
Joined: Wed May 23, 2012 8:37 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by charbot »

ok- that patch is for 2.0, right?

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Tommie »

It should work with any version of Multiwii that has tinygps included; you can even swap the few lines by hand if you wish :-)

charbot
Posts: 34
Joined: Wed May 23, 2012 8:37 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by charbot »

Ok- replaced those lines in gps.ino (latest dev version)- and things look way more stable- last 2 digits (lan and lon) change, but seems consistent with I2cGPS performance.
Distance to home still is reading 6084 or something (changes slightly with lan+lon) - also still no flashing ring.

edit- nevermind about Distance to home- it finally reset after unplugging power to the fc a few times.
Last edited by charbot on Wed Jun 13, 2012 7:15 pm, edited 1 time in total.

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Tommie »

I'm not sure whether TinyGPS triggers the "flashing ring" correctly at the moment; it is tied to the variable GPS_Update, which gets toggled by the tinygps code as well as the generic GPS code; it'spossible that these two things cancel each other out, so you won't see the ring flash.

Are you getting >= 5 satellites? Then calibrating your gyo (pitch down, throttle down, yaw left) should set your home position.

charbot
Posts: 34
Joined: Wed May 23, 2012 8:37 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by charbot »

Ok-I think its all working properly. Is there currently any use of the optical function? I have a few ad5050's and some disposable camera lenses to play with.

Not a priority, but it would be helpful if the LED functionality was increased - different "blinks" to indicate the state of GPS connection, (ie: 2 blinks=2d, 3 blinks=3d, ...similar to I2C-gps)

big thanks for the help and for developing such a cool project.

edit-
i keep getting Distance to home in the 6000's everytime I turn on the copter and the GPS first locks. I think that this may be glitch in the GUI- If I recalibrate the gyro (reset home) with the gui connected, the home distance doesnt reset. However If I unplug the usb2serial adapter and reconnect (leaving the quad powered) then the distance resets to 0.

charbot
Posts: 34
Joined: Wed May 23, 2012 8:37 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by charbot »

OK- just did a test flight. I think that there may be a problem- it flew like the gps info had no influence on the craft at all. Toggling poshold- it would continue to drift with no perceivable correction in flight. Return to home- it made no effort to return. Didnt even turn around. Im guessing that the FC is not incorporating the GPS data, even though it is recognized and displayed in the GUI.?

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Tommie »

Try using the latest dev version. There have been some changes, let me see if I can find the appropiate patch...
https://github.com/wertarbyte/multiwii- ... bf319cc9bd

There it is; without that change, GPSPOSHOLD and GPSHOME are ignored when using the TinyGPS.

charbot
Posts: 34
Joined: Wed May 23, 2012 8:37 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by charbot »

Using lastest dev-
tried it- just that one line?

Code: Select all

#if defined(GPS_SERIAL) || defined(TINY_GPS)
- better but still not right. it now responds to RTH, but my 'copter and I seem to disagree where home is. I performed lots of gyro recalib to make sure it knew,but no change. POS still really has no effect- it just keeps on truckin'. I shouldnt have to readjust PID values I set using I2Cgps, right?

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Tommie »

Due to limitiations of my GPS receiver, I wasn't able to test RTH and PH; I'm still waiting for a better one to arrive. I'll check whether some #define locks out TinyGPS from the apporpiate code...

charbot
Posts: 34
Joined: Wed May 23, 2012 8:37 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by charbot »

hey, anyone else get to try out RTH & PH yet?

BTW- here's a tip for those using a arduino as ISP programmer:

I had a hell of a time getting it to work until I found this: (sorry , cant find link now, - Ill edit it in later)

I am using a uno and arduino 1.0- apparently some have trouble flashing and i had to change the baud in both ArduinoISP.ino and programmers.txt, from 19200 to 9600. Works perfectly now.

Pyrofer
Posts: 180
Joined: Sat Apr 14, 2012 2:55 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Pyrofer »

Indeed, I should have posted that when I found out the same thing.

The ArduinoISP sketch included in examples DOES NOT WORK unless you change it to 9600 baud before uploading.

Also, if you have an auto-reseting board you need to disable the reset or when AVRDUDE tries to connect it resets the arduino and wont flash!

I have GPS connected and working and FW all ready to try GPS Pos hold and return home, but I CANT!
The wind has been so bad last 2 days it would blow the quad away from my hand without having it powered let alone try to fly it.

I am about to build a tinyGPS, I can't see how its a dead end as it does exactly what the chip on existing GPS units does. there is no such thing as an i2c GPS, they are all serial with an interface chip added.
at least tinyGPS will also convert my sonar and optical flow sensor to i2c too.

Looking forward to better weather to try position hold and return home :)
Cant wait till we can do things like waypoints and programmed routes :)

charbot
Posts: 34
Joined: Wed May 23, 2012 8:37 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by charbot »

yeah hoping I can at least use mine for optical and multiplexed sonar- if my copter will even take off with all the weight.

Pyrofer- make sure you get those two patches tommie posted a page or two back. Without, GPS data is really erratic and RTH and PH are disabled.

Pyrofer
Posts: 180
Joined: Sat Apr 14, 2012 2:55 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Pyrofer »

I did a git pull earlier today, so should be up to date :)
Putting together a DIY TX using a 2.4ghz module from ebay and a PS2 pad using Tommie's code as the base.
Tested my GPS today and it seemed the position, while constant was offset a lot from my real position. A bit worried by this. I don't mind if the position doesn't match up on a map as long as it doesn't suddenly change to being correct! Last thing I want is position hold to keep me perfectly positioned until it decides that it needs to be 10 meters THAT way and slams into a wall.

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by EOSBandi »

Pyrofer wrote:I am about to build a tinyGPS, I can't see how its a dead end as it does exactly what the chip on existing GPS units does. there is no such thing as an i2c GPS, they are all serial with an interface chip added.
at least tinyGPS will also convert my sonar and optical flow sensor to i2c too.


TinyGPS is a good idea, but unfortunately it does not help a lot on the restricted resources of an atmega382 based flight controller.
The GPS code will evolve on the following ways:
With a serial gps (and with a tinyGPS) future additons (such as waypoint based navigation with altitude setting, route following, etc.) will require an atmega1280 or 2560 based flght controller.
Az i2c gps means that the gps parsing and navigational functions are offloaded to a secondary atmega328 processor (http://code.google.com/p/i2c-gps-nav/), with this solution you will be able to use future additions with an atmega328 based FC.
So if you have an atmega328 based FC, then tinyGPS is a dead end for GPS functions, but if you have an atmega1280 or 2560 based FC then you don't need the tinyGPS anyway.

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Tommie »

For 1€, an ATTiny is not a big binding investent; and while the GPS software might outgrow the 328 eventually, adapting is still possible once this happens.

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by EOSBandi »

Tommie wrote:For 1€, an ATTiny is not a big binding investent; and while the GPS software might outgrow the 328 eventually, adapting is still possible once this happens.

Yepp, I agree. With the current functionality set, tinyGPS will work just fine and you'll get PH and RTH functionality. I think that the aim for the 2.1 MW release is PH and RTH. Waypoint navigation and other functions are slated for 2.2 release. What I said it's a dead end for future developments so eventually you'll need to replace it.....

Pyrofer
Posts: 180
Joined: Sat Apr 14, 2012 2:55 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Pyrofer »

So why not just admit the 328p is a dead end and tell people not to use it now?

If the problem is fitting GPS code in, its the 328 that's the problem not the way you attach the GPS.

Or are you saying you can fit all the GPS code for waypoints etc into the 328p? In which case where is the problem?
If you are suggesting everybody gets a second 328p just for GPS parsing you still need to connect the GPS to it, those with a serial GPS would probably still need to convert it to i2c anyway.

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by EOSBandi »

Pyrofer wrote:So why not just admit the 328p is a dead end and tell people not to use it now?

If the problem is fitting GPS code in, its the 328 that's the problem not the way you attach the GPS.

Or are you saying you can fit all the GPS code for waypoints etc into the 328p? In which case where is the problem?
If you are suggesting everybody gets a second 328p just for GPS parsing you still need to connect the GPS to it, those with a serial GPS would probably still need to convert it to i2c anyway.



Pyrofer please, did you check the i2c_gps_nav code ? It uses a serial gps, and connects to the Flight controller via i2c, acting as a real i2c device (complete register set and commands). The waypoint and nav code will fit into an atmega328 IF THERE ARE NO OTHER CODE in it.

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by copterrichie »

EOSBandi wrote:Pyrofer please, did you check the i2c_gps_nav code ? It uses a serial gps, and connects to the Flight controller via i2c, acting as a real i2c device (complete register set and commands). The waypoint and nav code will fit into an atmega328 IF THERE ARE NO OTHER CODE in it.


EOSBandi, code for sonar is not that large, is it possible to offload that code onto i2c_gps_nav?

fiendie
Posts: 151
Joined: Fri Apr 20, 2012 4:22 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by fiendie »

EOSBandi wrote:So if you have an atmega328 based FC, then tinyGPS is a dead end for GPS functions, but if you have an atmega1280 or 2560 based FC then you don't need the tinyGPS anyway.

It's still useful for microcontrollers with enough flash but only one UART like the AT90USB.
You wouldn't be able to connect both a Bluetooth and a GPS module otherwise.

wilco1967
Posts: 156
Joined: Thu Aug 18, 2011 6:04 pm
Location: Winterswijk, Netherlands

Re: HOWTO: Tiny-GPS with ATtiny4313

Post by wilco1967 »

I've just got the Tiny-GPS working, with the ATtiny4313 as recommended.
However, it was not an easy excersize for someone who's not programmer, so here is a little Howto for noobs like me ;)
It took me quite some time before I figured all this out, having no previous experience with programming these devices.
It is NOT using the Arduino methode we're all familiar with from MultiWii.

There might be easier ways.... but this is how I did it..... ymmv

the ATtiny4313 should (on paper) be a one-2-one replacement for the 2313. But that turned out to be slightly more difficult.
I'm only using a Sonar, but the difficult part proved to be getting the 4313 programmed, as it seems to be a relative new component, which is not known to some programs we use.

What you need:
- ATtiny4313.... I've got mine from http://www.ebay.com/itm/221020628909?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1439.l2649#ht_1814wt_1139
- something to use with your ATTiny.... I used this http://www.ebay.com/itm/261009210866#ht_4081wt_1389
- an ASP programmer of some sort.... I've used this USBASP http://www.ebay.com/itm/USBASP-USBISP-AVR-Programmer-USB-ATMEGA8-ATMEGA128-New-/370532286436?pt=LH_DefaultDomain_0&hash=item564571ffe4#ht_3488wt_952
If you've ever used a KK board, or if you re-flashed your Turnigy-9X transmitter to ER9X firmware, you might have one already...

step 1
download the Tiny-GPS software from https://github.com/wertarbyte/tiny-gps
There is a button ZIP (download this repository as a zip file), which get's you all the files at once.

Step 2
unzip the files in a easy location (you will need to go there later with the cmd prompt, so pick a short one to make things easier, like c:\Tiny-GPS). It will probably create another subdirectory, but I recommend to move all the individual files in the c:\Tiny-GPS directory.

Step 3
If you don't have one already, install WinAVR (which contains the C-compiler and a lot of other things I also don't understand). You'll need it to create the .hex file you'll need to burn into the 4313
download http://sourceforge.net/projects/winavr/files/ and install with the default options (I used version WinAVR-20100110-install.exe). It moans about some file not found during install for a couple of seconds, but it installs correctly... don't worry.


Step 4
Go to the c:\Tiny-GPS directory, and edit the config.h file to your liking. (this is the Tiny-GPS config file, not the MultiWii )
if you, like me, will NOT have a GPS connected, you need to de-activate it in the config.h file.... don't comment it like we're used to in MultiWii, but change the 1 into a 0, so #define USE_GPS 1 will become #define USE_GPS 0

Step 4.5 (4 and a half)
You might find out, that editing the config.h is not very straightforward, if you don't have a proper code editor installed.... There might one in WinAVR, but I could not find that, so I used http://download.cnet.com/Notepad/3000-2352_4-10327521.html?tag=mncol;1... The windows default Notepad is no good....

Step 5
So you've edited the config.h.... now it is time to compile the code using 'make'. It took me a long time to figure this one out, but 'make' is part of the WinAVR tools. And... :shock: you need to run it from the cmd prompt in windows (go to the windows start button, and type cmd (enter) at the 'search programs and files)... the black cmd window will now open.

In the cmd window, type
cd c:\gps-tiny

the directory prompt will change to
c:\Tiny-GPS>

So your in the right directory (that's why I recommended it to be a short path)...

now type
make
and enter..... nothing more.....
Make will search for the makefile in the current directory, which tells it what to do...
Make will do it's thing, which only takes a few seconds....

below is what I got in the cmd window

Code: Select all

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\wilco.hijink>cd c:\tiny-gps

c:\Tiny-GPS>make

-------- begin --------
avr-gcc (WinAVR 20100110) 4.3.3
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: tiny-gps.c
avr-gcc -c -mmcu=attiny2313 -I. -gstabs -DF_CPU=8000000UL   -Os -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-
adhlns=tiny-gps.lst  -std=gnu99 -MD -MP -MF .dep/tiny-gps.o.d tiny-gps.c -o tiny
-gps.o

Compiling: nmea.c
avr-gcc -c -mmcu=attiny2313 -I. -gstabs -DF_CPU=8000000UL   -Os -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-
adhlns=nmea.lst  -std=gnu99 -MD -MP -MF .dep/nmea.o.d nmea.c -o nmea.o

Compiling: sonar.c
avr-gcc -c -mmcu=attiny2313 -I. -gstabs -DF_CPU=8000000UL   -Os -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-
adhlns=sonar.lst  -std=gnu99 -MD -MP -MF .dep/sonar.o.d sonar.c -o sonar.o

Compiling: optical.c
avr-gcc -c -mmcu=attiny2313 -I. -gstabs -DF_CPU=8000000UL   -Os -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-
adhlns=optical.lst  -std=gnu99 -MD -MP -MF .dep/optical.o.d optical.c -o optical
.o

Compiling: usiTwiSlave.c
avr-gcc -c -mmcu=attiny2313 -I. -gstabs -DF_CPU=8000000UL   -Os -funsigned-char
-funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-
adhlns=usiTwiSlave.lst  -std=gnu99 -MD -MP -MF .dep/usiTwiSlave.o.d usiTwiSlave.
c -o usiTwiSlave.o

Linking: tiny-gps.elf
avr-gcc -mmcu=attiny2313 -I. -gstabs -DF_CPU=8000000UL   -Os -funsigned-char -fu
nsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adh
lns=tiny-gps.o  -std=gnu99 -MD -MP -MF .dep/tiny-gps.elf.d tiny-gps.o nmea.o son
ar.o optical.o usiTwiSlave.o --output tiny-gps.elf -Wl,-Map=tiny-gps.map,--cref
   -lm

Creating load file for Flash: tiny-gps.hex
avr-objcopy -O ihex -R .eeprom tiny-gps.elf tiny-gps.hex

Creating load file for EEPROM: tiny-gps.eep
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
        --change-section-lma .eeprom=0 -O ihex tiny-gps.elf tiny-gps.eep
c:\WinAVR-20100110\bin\avr-objcopy.exe: --change-section-lma .eeprom=0x00000000
never used

Creating Extended Listing: tiny-gps.lss
avr-objdump -h -S tiny-gps.elf > tiny-gps.lss

Creating Symbol Table: tiny-gps.sym
avr-nm -n tiny-gps.elf > tiny-gps.sym

Size after:
tiny-gps.elf  :
section    size      addr
.text       886         0
.bss         39   8388704
.stab      3900         0
.stabstr   4230         0
Total      9055



-------- end --------


c:\Tiny-GPS>

You can close the cmd window now for the moment..

If you look into the C:\Tiny-GPS directory, you'll notice, some files were added.... one of them should be Tiny-GPS.hex . That is the one we need to flash into the ATtiny 4313

But before we can do that, we need some software again.

Step 6
Get the newest AVRDude version from http://download.savannah.gnu.org/releases/avrdude/avrdude-5.11-Patch7610-win32.zip.
It is important to use this new version, as older versions (for example, included in Arduino, or Eepe (for Turnigy 9X), or WinAVR) do not yet support the ATTiny4313.
unzip the files (2 files + 1 directory) into the same c:\Tiny-GPS directory... make sure the AVRdude.exe and AVRdude.conf are in the Tiny-GPS directory. The giveio directory should reside under Tiny-GPS (so you probably need to move all of them one level up).

Step 7
If you've not already done so, insert your USBASP programmer (no ATTiny connected yet)... Windows 7 will automatically detect it and install the required drivers.

Step 8
Connect your USBASP programmer to your ATTiny4313 as follows:

Code: Select all

USBASP                                    ATTiny4313
---------------------------------------------------------------------------------------------------------
pin 1 (mosi, usually the red wire)        pin 17 (mosi, = 4th from the top on the right, with the small notch at the top)
pin 2 (VCC)                                        pin 20 (top right)
pin 3 (not used)
pin 4 (GND)                                        pin 10 (bottom left)
pin 5 (RST)                                        pin 1 (top left)
pin 6 (not used)
pin 7 (SCK)                                         pin 19 (2nd from top right)
pin 8 (not used)
pin 9 (MISO)                                       pin 18 (3rd from top right)
pin 10 (not used)
Sorry if it doesn't line up properly....

Once you've checked all, insert your USBASP in your computer, and hope nothing smokes.... ;)

Step 9
Flash your Tiny-GPS.hex file using AVRdude
go to the cmd window again
type:
cd c:\tiny-gps <enter>
when in the correct directory, type:
avrdude -c usbasp -p t4313 -U flash:w:tiny-gps.hex -U lfuse:w:0xe4:m -U hfuse:w:0xdb:m -U efuse:w:0xff:m
followed by enter.... AVRdude should do it's thing, and after a few seconds you're ATtiny4313 should be flashed....

Tip: you can copy/paste the above, by right clicking in the CMD window... (CTRL-V does not work here)....

The fuse settings are for the 8MHz clockfrequency... details can be found here [url]
http://www.engbedded.com/fusecalc/[/url]



This is what I get

Code: Select all

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\wilco.hijink>cd c:\tiny-gps

c:\Tiny-GPS>avrdude -c usbasp -p t4313 -U flash:w:tiny-gps.hex -U lfuse:w:0xe4:m
 -U hfuse:w:0xdb:m -U efuse:w:0xff:m

avrdude: warning: cannot set sck period. please check for usbasp firmware update
.
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.07s

avrdude: Device signature = 0x1e920d
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed

         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: warning: cannot set sck period. please check for usbasp firmware update
.
avrdude: reading input file "tiny-gps.hex"
avrdude: input file tiny-gps.hex auto detected as Intel Hex
avrdude: writing flash (886 bytes):

Writing | ################################################## | 100% 0.32s



avrdude: 886 bytes of flash written
avrdude: verifying flash memory against tiny-gps.hex:
avrdude: load data flash data from input file tiny-gps.hex:
avrdude: input file tiny-gps.hex auto detected as Intel Hex
avrdude: input file tiny-gps.hex contains 886 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 0.36s



avrdude: verifying ...
avrdude: 886 bytes of flash verified
avrdude: reading input file "0xe4"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xe4:
avrdude: load data lfuse data from input file 0xe4:
avrdude: input file 0xe4 contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xdb"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xdb:
avrdude: load data hfuse data from input file 0xdb:
avrdude: input file 0xdb contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.02s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0xff"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.01s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0xff:
avrdude: load data efuse data from input file 0xff:
avrdude: input file 0xff contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.


c:\Tiny-GPS>


Now your ATTiny4313 is flashed.
You can disconnect your USBASP programmer, and connect your freshly burned ATTiny to the Multiwii....

Step 10

Use this schematic for connecting
http://www.multiwii.com/forum/download/file.php?id=1225&mode=view

Recommend to provide your Tiny-GPS with 5 VDC (not 3.3), and connect it to the 5V side on any LLC you have on your I2C lines... (so directly to the arduino pins). Your IMU / sensors are often 3.3 devices... GPS / sonar / ATTiny are 5V devices...

Step 11
Activating in MultiWii
On MultiWii (in Arduino), in your config.h (the multiwii one). uncomment
#define TINY_GPS_SONAR
and/or
#define TINY_GPS

If all is OK, it should show GPS data.... Sonar data will be visible in Debug3 in the GUI... currently, the MultiWii code does nothing with sonar data (only show), but there is some code being made to use it for altitude hold... I got an experimental version going (see other thread, here: http://www.multiwii.com/forum/viewtopic.php?p=16641#p16641

Testing.
You could also use this code (in your MultiWii arduino) to test if the Tiny-GPS is communicating.
http://www.multiwii.com/forum/viewtopic.php?p=13899#p13899
Simply open a new sketch in Arduino... paste this code, compile, and upload using the FDTI cable (just like you upload the normal MultiWii program).
In the serial monitor of Arduino (top right corner), you can see the result.... (still using the FTDI cable). You might have to change the baudrate to 9600.

Hope this is helpful.....
Good luck !

Wilco

User avatar
Jonit
Posts: 37
Joined: Sat May 12, 2012 10:12 pm
Location: Slovakia

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Jonit »

Wilco thank you soo much! In a few weeks i'm going to build one so this guide will be very helpful for me as well as for other ppl :)

Katch
Posts: 280
Joined: Thu Aug 04, 2011 1:44 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Katch »

@Tommie

have you done any work on integrating the Optical Flow sensor into your code? The parts have turned up for my Optical Sensor and I wanted to see if I can get one working on your ATTiny board.

Tommie
Posts: 438
Joined: Sun Apr 08, 2012 9:50 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Tommie »

Well, the optical sensor is queried and its movement data is incorporated into the I²C struct; when the struct is read, the data is reset. So you can try doing something practical with it, I haven't done any additional work yet (mostly because the appropiate code hasn't turned up in the multiwii svn yet).

User avatar
Jonit
Posts: 37
Joined: Sat May 12, 2012 10:12 pm
Location: Slovakia

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Jonit »

well, i built a Tiny-GPS for my BT GPS module, so i can use it with my Crius board. I followed Wilco's step by step manual. But communication not work as it should. It is not stable. One time it work (showing the numbers in GUI) and other time not. Even when it is showing the numbers in GUI, they don't match with data showed in MiniGPS tool (i must have connected my BT GPS to some device, otherwise it don't send NMEA sentences). In MiniGPS data are rock solid and are exactly what they should be (+- 3m accuracy), but in GUI they are different and very inaccurate. Here is the video showing my problem (if you pause at 1:08, you can see the difference between correct MiniGPS tool data and inaccurate data shown in GUI): http://www.youtube.com/watch?v=9GnVj8lhCeU&feature=youtu.be
Anyone know where the problem can be?

Jonit

charbot
Posts: 34
Joined: Wed May 23, 2012 8:37 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by charbot »

There is (or at least was, with the prev dev's) necessary patch to get reliable gps data. Look back a few pages-

User avatar
Jonit
Posts: 37
Joined: Sat May 12, 2012 10:12 pm
Location: Slovakia

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Jonit »

ok i applied this patch https://github.com/wertarbyte/multiwii-firmware/commit/b5a4e1840f435f63730e05ebcf0f2ca7c6bc9683.. now in GUI only last 2 digits of GPS coordinates are changing, but i am still 2 km off from my current position :?
BTW: is it okay that i am using my GPS at 115200 baud and sending GLL, GSA, RMC, GSV, VTG and GGA frames? Isn't it too much load for AtTiny ? .. just asking, I have no idea ;)

User avatar
EOSBandi
Posts: 802
Joined: Sun Jun 19, 2011 11:32 am
Location: Budapest, Hungary
Contact:

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by EOSBandi »

Jonit wrote:ok i applied this patch https://github.com/wertarbyte/multiwii-firmware/commit/b5a4e1840f435f63730e05ebcf0f2ca7c6bc9683.. now in GUI only last 2 digits of GPS coordinates are changing, but i am still 2 km off from my current position :?
BTW: is it okay that i am using my GPS at 115200 baud and sending GLL, GSA, RMC, GSV, VTG and GGA frames? Isn't it too much load for AtTiny ? .. just asking, I have no idea ;)


I did not looked into tinygps code, BUT current serial GPS code (dev0618) has an error in nmea parsing, it gives a 2km error on the calculated location. I'll commit a patch today to correct it.

User avatar
Jonit
Posts: 37
Joined: Sat May 12, 2012 10:12 pm
Location: Slovakia

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Jonit »

EOSBandi wrote:I did not looked into tinygps code, BUT current serial GPS code (dev0618) has an error in nmea parsing, it gives a 2km error on the calculated location. I'll commit a patch today to correct it.

I'm using MultiWii_dev_20120606 but i guess it is the same in terms of that.

User avatar
Gaijin
Posts: 82
Joined: Sat Jan 14, 2012 8:00 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by Gaijin »

Re-Post to find the right topic

Just pIcked up a nice ready made AT328 based I2C module, would it be difficult to modify the ATTiny code to run on it?

I have an HC-SRF04 kicking about, between them it could make for a very simple to build and low cost I2C sonar sensor, any thoughts

http://www.rctimer.com/index.php?gOo=goods_details.dwt&goodsid=762&productname=

xpix
Posts: 2
Joined: Wed Jul 11, 2012 10:54 am

Re: HOWTO: Tiny-GPS with ATtiny4313

Post by xpix »

wilco1967 wrote:If all is OK, it should show GPS data.... Sonar data will be visible in Debug3 in the GUI... currently, the MultiWii code does nothing with sonar data (only show), but there is some code being made to use it for altitude hold... I got an experimental version going (see other thread, here: http://www.multiwii.com/forum/viewtopic.php?p=16641#p16641


Thanks wilco for this very good manual, may this is good for a better place (wiki) as a article in this Forum. Anyway, i build an Attiny in an IC Holder ... everything is good. The only one Problem is, if i use this code in the other Thread, then compiler say "SonarAlt" is not declearded. What can i do? ;)

Image

P.S.: I use Multiwii 2.1.

cestb
Posts: 27
Joined: Wed Mar 14, 2012 10:30 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by cestb »

Hi,

i'm trying to make a tinygps using my Mtk3329 serial gps (mw2.1) but i've some strange outputs:
- Coordinates didn't change when i walk with the gps for about 20/25meters
- My position is at 2kms from my real position
- Sometimes coordinates had changed but always at 2Kms of real position and Dist to home didn't change, always 0.

Any idea ?
thks in advance.

crashlander
Posts: 506
Joined: Thu May 05, 2011 8:13 am
Location: Slovenia

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by crashlander »

cestb wrote:Hi,

- Sometimes coordinates had changed but always at 2Kms of real position and Dist to home didn't change, always 0.

thks in advance.


I believe that home pos. is set at arm time so you have to walk with copter armed to se dist. to home change.

Andrej

cestb
Posts: 27
Joined: Wed Mar 14, 2012 10:30 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by cestb »

Ok, i will test that this afternoon and give a feedback

cestb
Posts: 27
Joined: Wed Mar 14, 2012 10:30 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by cestb »

Ok, when i arm, it shows dir to home but dist to home never change, always 0 even i move a lot (20meters)

May someone, who uses a MTK3329, give me his tinygps config.h?
Thks in advance.

cestb
Posts: 27
Joined: Wed Mar 14, 2012 10:30 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by cestb »

Some more tests today :

i succeed in making my gps working at 115200, 10hz with no speed threesold with these commands :
#define GPS_INIT_STRING "$PMTK313,0*2F\r\n$PMTK220,100*2F\r\n$PMTK251,115200*1F\r\n$PMTK397,0*23\r\n"

It's near to be ok but one problem stays here :
When i move the gps, coordinates update during 30s and then freeze during 30s and then update and....
If i look in Wingui, i see that when it froze, there were no ic2 packet received.

Could it the attiny 2313 be too short for this ?

Thks in advance.

cestb
Posts: 27
Joined: Wed Mar 14, 2012 10:30 am

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by cestb »

So,
what i've done :
I use my gps in serial mode directly connected to the AIO
I use the tinySonar only ;)
In serial mode, my position is good.

MatthiasW
Posts: 2
Joined: Fri Sep 09, 2011 7:56 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by MatthiasW »

Hi,
I use a u blox5 GPS receiver (Navilock NL 552ETTL).
How can I change this in Atiny 2313 to 38400 baud and 5Hz? The recipient shall, if the battery is empty, always to 9600 baud.
I know the GPS-Init:
for 38400 Baud:
B5 62 06 00 14 00 01 00 00 00 D0 08 00 00 00 96 00 00 03 00 03 00 00 00 00 00 8F 70
and for 5Hz:
B5 62 06 08 06 00 C8 00 01 00 01 00 DE 6A

How I can this in the Tiny-GPS-Code integrate?

Greetings
Matthias

Sorry for my bad English.

rizky_p
Posts: 14
Joined: Thu Sep 06, 2012 3:57 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by rizky_p »

MatthiasW wrote:Hi,
I use a u blox5 GPS receiver (Navilock NL 552ETTL).
How can I change this in Atiny 2313 to 38400 baud and 5Hz? The recipient shall, if the battery is empty, always to 9600 baud.
I know the GPS-Init:
for 38400 Baud:
B5 62 06 00 14 00 01 00 00 00 D0 08 00 00 00 96 00 00 03 00 03 00 00 00 00 00 8F 70
and for 5Hz:
B5 62 06 08 06 00 C8 00 01 00 01 00 DE 6A

How I can this in the Tiny-GPS-Code integrate?

Greetings
Matthias

Sorry for my bad English.


+1 i also have u-blox 6m neo how to implement init string?

copterrichie
Posts: 2261
Joined: Sat Feb 19, 2011 8:30 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by copterrichie »

Question, have anyone ported over the code from the ATTiny4313 to run on an ATMega328?

Thank you.

dynai
Posts: 32
Joined: Tue Mar 01, 2011 10:01 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by dynai »

Hi everbody,

please HELP!

i've spent the last day trying to get my tinyGPS to work but i can't get it working.. :( (attiny2313 with mtk3339 set to 38400 5hz set to output minimal nema)

from the gps serial i get

Code: Select all

$PGTOP,11,2*6E
$GPGGA,14xx07.600,4xx9.9370,N,009xx.7460,E,1,4,2.9x,x9x.2,M,48.0,M,,*5F
$GPRMC,14xx07.600,A,4xx9.9370,N,009xx.7460,E,0.2x,x3x.71,2xxx12,,,A*65


(x) inserted to scramble

over i2c all i get is

Code: Select all

Request: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255 
Request: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255 255 255 255 255 255
 


any help welcome
kind regards chris
Last edited by dynai on Sun Dec 23, 2012 5:29 pm, edited 1 time in total.

dynai
Posts: 32
Joined: Tue Mar 01, 2011 10:01 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by dynai »

Hi,

me again,

NMEA (MEA) CULPA, ok i don't know what has changed, i just kept trying and now it works! this drove me almost crazy but now its working THANKS FOR THIS GREAT PEACE OF SOFTWARE! MARVELOUS! and now im realy impressed how fast the mtk3339 gets a fix.
if anyone strugles the same problems here is the config and the tinyGPS files, im no longer sure why it now works but it does.

tiny-gps2313.zip
(88.53 KiB) Downloaded 214 times


im using the breakoutboard from adafruit (http://www.adafruit.com/products/746) and used the MiniGPS Tool 1.7.1 to set it to 38400, 5hz and only enabled GGA and RMC.

once again.. thx for TinyGPS :) (wonderfull christmas present)

kind regards Chris

dynai
Posts: 32
Joined: Tue Mar 01, 2011 10:01 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by dynai »

Hi,

so today i finally had time for outdoor testing... and the position is offset by 2km :(
ok im not the first one to stumble upon this and eosbandi has fixed this in his code.
so there has to be a way around this problem...

any suggestions?
im trying to understand what causes the problems but i must confess looking files like the nmea.c is not my daily business ;)
so any help is welcome :)

kind regards Chris

dynai
Posts: 32
Joined: Tue Mar 01, 2011 10:01 pm

Re: Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by dynai »

Hi,

i've hooked my gps now directly to serial and it gives me accurate position, im trying to understand how the "FRACTS" part works as my guess is that something happens with the fractions of a minute. Either when they are transformed to BCD or on their way back to minutes.

can someone explain me what "fracts" means?

eg. i have
byte Value
11: 9 deg
12: 48 mins = 0.8deg
13: 40 longitude fractions of a minute, BCD format
14: 147 longitude fractions of a minute, BCD format

in multiwii i get a position of 9.8000546 -> 9deg 48min 0.19sec
in reality its a position of 9.8128350 -> 9deg 48min 45.74sec that is a discrepance of around 2km when combined with the false values from latitude !!


kind regards Chris

dynai
Posts: 32
Joined: Tue Mar 01, 2011 10:01 pm

ERR:Tiny-GPS integrated into Multiwii (GPS/Sonar/Optical to

Post by dynai »

Hi everyone,

i think i finally can contribute something to the multiwii code :)

i found a fix for the tiny-GPS 2km offset

when i change the GPS.INO code for the TINY_GPS to following lines the position is accurate, think the previous version generated an overflow and therefore calculated the values wrong also did it seem to swap the numbers in the wrong order (think of 1234 became 2143)

Code: Select all

#if defined (TINY_GPS)
  int32_t GPS_coord_to_decimal(struct coord *c) {
  #define GPS_SCALE_FACTOR 10000000L
  uint32_t deg = 0;
  deg = (uint32_t)c->deg * GPS_SCALE_FACTOR;

  uint32_t min = 0;
  //min = (uint32_t)c->min * GPS_SCALE_FACTOR; // moved down
  /* add up the BCD fractions */
  //uint16_t divisor = (uint16_t)GPS_SCALE_FACTOR; // OLD CODE
  uint16_t divisor = 1000;
  for (uint8_t i=0; i<NMEA_MINUTE_FRACTS; i++) {
    uint8_t b = c->frac[i/2];
    //uint8_t n = (i%2 ? b&0x0F : b>>4); // OLD CODE
    uint8_t n = (i%2 ? b>>4 : b&0x0F); // <-- NEW
    min += n * divisor;
    divisor /= 10;
  }
  min *= 1000; // <-- NEW
  min += (uint32_t)c->min * GPS_SCALE_FACTOR; // <-- moved from above
  /* now sum up degrees and minutes */
  return deg +  min/60;
}
#endif


Would be nice if this could make it into the official code after some veryfication by the geniuses behind this project.

kind regards Chris

Post Reply