Example luat example GPS

How to realize GPS positioning function with development board

brief introduction

GPS positioning is one of the common functions. This paper introduces how to use Air724 development board + 530 development board to demonstrate the GPS positioning function.

stores reserve

1.EVB_Air724UG_A13 A set of development boards and Air530 GPS A set of development board, including SIM card, USB cable, antenna and serial port cable.
2.PC
3. luat development environment: Environment construction method

step

This article takes demo\gps\other DEMO as an example.
Demo download address Demo
1. First, connect Air724 development board and 530 development board through serial port line (Air724TXD is connected to 530RXD, Air724RXD is connected to 530TXD, 530VDD is connected to Air724VMMC,PPS does not need to be connected), and open the voltage domain of VMMC.

pmd.ldoset(15,pmd.LDO_VMMC)

Note: the VMMC pin of Air724 can be used normally only when the voltage domain is turned on. Please refer to the detailed description of the voltage domain for reference LDO power output

2. Call GPS Setuart () interface sets the serial port parameters of data communication between GPS module and GSM module, and calls GPS The setnmeamode() interface sets the NMEA data processing mode.

--gps.setPowerCbFnc,Set serial communication parameters, Air530 The baud rate is 9600
gps.setUart(1,9600,8,uart.PAR_NONE,uart.STOP_1)
-Set only gps.lua Internal processing NEMA data

--If this interface is not called, the default is only gps.lua Internal processing NEMA data
--If gps.lua No internal treatment, put NMEA Data through callback function cb It is provided to external program processing, and the parameter is set to 1,nmeaCb
--If gps.lua And external programs are processed, and the parameter is set to 2,nmeaCb
gps.setNmeaMode(2,nmeaCb)

Note: you must call GPS The GPS module can only be started normally through the setuart() interface

3. Call the test() function to open the GPS application. The test() function has two test methods: always open the GPS and close it after 5 minutes.

--Test code switch, value 1,2
local testIdx = 1
local function test(idx)
    --Type 1 test code
    if idx==1 then
        --After executing the following three lines of code, GPS It will always open and never close
        --because gps.open(gps.DEFAULT,{tag="TEST1",cb=test1Cb}),This is turned on and not called gps.close close
        gps.open(gps.DEFAULT,{tag="TEST1",cb=test1Cb})

        --10 Seconds, if gps If the location is successful, it will be called immediately test2Cb,Then automatically close this“ GPS "Apply"
        --10 When seconds are up, if the location is not successful, it will be called immediately test2Cb,Then automatically close this“ GPS "Apply"
        --gps.open(gps.TIMERORSUC,{tag="TEST2",val=10,cb=test2Cb})

        --300 Seconds, it will be called immediately test3Cb,Then automatically close this“ GPS "Apply"
        --gps.open(gps.TIMER,{tag="TEST3",val=300,cb=test3Cb})
    --Type 2 test code
    elseif idx==2 then
        --Open after executing the following three lines of code GPS After 5 minutes GPS Will close
        gps.open(gps.DEFAULT,{tag="TEST1",cb=test1Cb})
        sys.timerStart(gps.close,300000,gps.DEFAULT,{tag="TEST1"})
        gps.open(gps.TIMERORSUC,{tag="TEST2",val=10,cb=test2Cb})
        gps.open(gps.TIMER,{tag="TEST3",val=60,cb=test3Cb}) 
    end
end

test(testIdx)

Note: three GPS applications are opened in the demo, and the specific ones are opened according to their own needs

4. Open a cycle timer and call printGps() function to print gps related data.

local function printGps()
    if gps.isOpen() then
        local tLocation = gps.getLocation()--Get latitude and longitude information in degrees format
        local speed = gps.getSpeed()
        log.info("testGps.printGps",
            gps.isOpen()--obtain GPS Is the module on,gps.isFix()--obtain GPS Is the module located successfully,
            tLocation.lngType,tLocation.lng,tLocation.latType,tLocation.lat,--Print latitude and longitude
            gps.getAltitude(),--Get altitude
            speed,--Acquisition speed
            gps.getCourse(),--Get bearing
            gps.getViewedSateCnt(),--Get the number of visible satellites
            gps.getUsedSateCnt())--Get the number of satellites used for positioning
    end
end

sys.timerLoopStart(printGps,2000)

5.gps. The setnmeamode() interface will call nmeaCb() function to print NEMA data. When the GPS application is started, it will call the callback function according to conditions.

Function name: nemacb
 Function: NEMA Data processing callback function
 Parameters:
		data: One NEMA data
 Return value: None
]]
local function nmeaCb(nmeaItem)
    log.info("testGps.nmeaCb",nmeaItem)
end

local function test1Cb(tag)
    log.info("testGps.test1Cb",tag)
    printGps()
end

local function test2Cb(tag)
    log.info("testGps.test2Cb",tag)
    printGps()
end

local function test3Cb(tag)
    log.info("testGps.test3Cb",tag)
    printGps()
end

6. After understanding and modifying the demo, download the demo and the corresponding base package to the development board. The download method is not described in detail here, please refer to Burning chapter in environment construction

7. After downloading, restart and check the luatool log to see that the GPS positioning is successful and the GPS related data is printed.

common problem

Relevant information and purchase links

Keywords: IoT lua gps

Added by jmanfffreak on Sun, 23 Jan 2022 04:38:11 +0200