First, about TPYBoardV702
TPYBoardV702 is the only Micropython Development Board in the market that supports the communication positioning function: Supports Python3.0 and above to run directly. Support gps+ Beidou dual-mode positioning, GPRS communication, SMS function, telephone function, onboard temperature and humidity, photosensitive, triaxial accelerometer, buzzer, LCD5110 display. Provide location testing Service platform free of charge. Physical such as:
Second, using TPYBoardV702 to complete the location of temperature and humidity and brightness data collection
1. Specific requirements
Use TPYBoardV702 to complete the location of the latitude and longitude collection, and on the 5110 display display
2, the required devices
TPYBoardV702 Development Board Piece
5110 display Piece
TPYBOARDV702 Board-onboard positioning function without external
3. On-board positioning function and usage introduction
The overall highlight of V702 's development Board is that it can be positioned to obtain some information about the latitude, longitude, height, time, etc. of the current location. In this experiment we are going to use the function of obtaining latitude and longitude.
The main hardware features of this board have been embedded in the development Board, it is very convenient to use, we only need to do simple setup operation can obtain latitude and longitude, and then the data parsing, segmentation and data conversion processing, we can get the latitude and longitude we want, We then display the latitude and longitude on the Development Board by using the display. The following is a concrete way to say the production process.
Third, the main process of production
Let's start with the previous diagram and begin to say the code question.
1, the production process
(1) Preferred what we need to do is to plug the 5100 display into the 702 Development Board of the 5110 display interface;
(2) After the completion of the above work, we need to use the main class library, 5110 of the class library, we need to copy the class Library's. py file to the disk in the Development Board;
(3) After completing the above work, we begin to edit the code of the main (). py file;
(4) Declaration and definition of the class library to be used;
(5) Define the variables we need to use.
(6) We need to use the interface to declare and define, here we mainly use the SPI1 and serial port 4 of the two interfaces, the declaration of the serial port 4, the need to set the serial port baud rate of 115200;
(7) The following start of the main function of the writing, this experiment we use the display, we start the program in the first part of the initialization of the display;
(8) After the completion of the partial initialization of the display, we need to do one of the most important thing is to define the "Y6" pin as the output, and then put: "Y6" pin down for two seconds, and then pull this pin high. Because the "Y6" pin is the control of the entire onboard positioning system on the switch, if we do not use the positioning system, in order to save power, the onboard positioning system is in the closed state, need to use only to pull down the "Y6" pin for more than two seconds;
(9) When the red plug-in LED light on the development Board flashes quickly, it is indicated that the on-board positioning system is starting, when the red plug-in indicator end flash (the indicator light is in a slow flashing or off state), the onboard positioning system has been started;
(10) After the completion of the above work, our quasi-work has been completed, the rest of the need to do is through the serial port 4 to send the corresponding instructions, to obtain the corresponding data, and then the corresponding data conversion, and display on the display.
2, the specific code:
ImportPybImportupcd8544 fromMachineImportSpi,pin fromPybImportUART fromUbinasciiImporthexlify fromUbinasciiImport*LEDs= [Pyb. LED (i) forIinchRange (1,5)]p,l,shuchu=0,0,0spi= Pyb. SPI (1)#din=>x8-mosi/clk=>x6-sck#DIN =>spi (1). MOSI ' X8 ' data flow (Master out, Slave in)#CLK =>spi (1). SCK ' X6 ' SPI clockRST = Pyb. Pin ('X20') CE= Pyb. Pin ('X19') DC= Pyb. Pin ('X18') Light= Pyb. Pin ('X17') lcd_5110=upcd8544. PCD8544 (SPI, RST, CE, DC, light) Count_=0n2= Pin ('Y3', PIN.OUT_PP) N1= Pin ('Y6', PIN.OUT_PP)#defines the on-board positioning System switch pin as outputN1.low () pyb.delay (2000) N1.high () Pyb.delay (10000)#start the on-board positioning system by pulling the level of the low and high switch pinsU2 = UART (4, 115200)#define serial port 4, set baud rate to 115200I='0'W=0d=0q=0G=0j=0defDataconver (Str_,flag):#pre-programmed data processing functions to facilitate late data processingWei_=float (STR_)/100Wei_arr=str (Wei_). Split ('.') Val_=100000ifFlag==0:#Latitudeval_=10000wei_arr[1]=str (float (wei_arr[1])/60*val_). Replace ('.',"') Weidu=wei_arr[0]+'.'+wei_arr[1] returnWeidu whileTrue:pyb. LED (2). On () G=g+1U2.write ('at+gpsloc=1\r\n')#send instructions via serial port, command on-board positioning system for Star Search operationPyb.delay (3000) _dataread=U2.readall ()Print('Search star =', _dataread)#delay, to the system search star response time, improve the efficiency of search stars, and print search resultsPyb.delay (1000) U2.write ('at+gpsloc=0\r\n')#through the serial port to obtain the latitude and longitude instructions, command board positioning System for #经纬度获取Pyb.delay (200) Print('Beidou') _dataread=u2.readall ()#Save the latitude and longitude data obtained by the serial port, if the location signal is not good, the return data can be #能全部为零, this situation will lead to longer positioning period if_dataread!=None:Print('raw data =', _dataread)Print('raw Data length:', Len (_dataread))if60<len (_dataread) <70:#This is where the correct data length is used as the beginning of the processing_dataread = _dataread.decode ('Utf-8') _dataread1=_dataread.split (',')#Turn the data into ' utf-8 ' format and divide the data into "," #隔开 Print('data =', _dataread1)Print(Len (_DATAREAD1),'***') ifLen (_dataread1) >4:#determine the length of the array data converted (or the array's meta-#素个数) as the beginning of the data conversion#******************* latitude Calculation ********************Weidu=_dataread1[1] WD=dataconver (weidu,0)#******************* Longitude calculation ********************Jingdu=_dataread1[2] JD=dataconver (jingdu,1)#using the data conversion function we've done above, we'll turn the data #换成我们可以正常使用的格式#*********************** Time ************************Lcd_5110.lcd_write_string ('Jingdu:', 0,0) lcd_5110.lcd_write_string (str (JD), 0,1) lcd_5110.lcd_write_string ('Weidu:', 0,2) lcd_5110.lcd_write_string (str (WD), 0,3)#The display function in the 5110 Display class library is used to make the data explicit #示
Micropython-gps Tutorial TPYBoardv702 Control 5110 shows the current latitude and longitude