标签归档:micropython

micropython GPS noe-6m模块 札记


from machine import Pin, UART, SoftI2C from ssd1306 import SSD1306_I2C import utime, time # i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000) #initializing the I2C method for ESP32 # oled = SSD1306_I2C(128, 64, i2c) gpsModule = UART(0, baudrate=9600) print(gpsModule) buff = bytearray(255) TIMEOUT = False FIX_STATUS = False latitude = "" longitude = "" satellites = "" GPStime = "" def getGPS(gpsModule): global FIX_STATUS, TIMEOUT, latitude, longitude, satellites, GPStime timeout = time.time() + 8 while True: gpsModule.readline() buff = str(gpsModule.readline()) parts = buff.split(',') if (parts[0] == "b'$GPGGA" and len(parts) == 15): if(parts[1] and parts[2] and parts[3] and parts[4] and parts[5] and parts[6] and parts[7]): print(buff) latitude = convertToDegree(parts[2]) if (parts[3] == 'S'): latitude = -latitude longitude = convertToDegree(parts[4]) if (parts[5] == 'W'): longitude = -longitude satellites = parts[7] GPStime = parts[1][0:2] + ":" + parts[1][2:4] + ":" + parts[1][4:6] FIX_STATUS = True break if (time.time() > timeout): TIMEOUT = True break utime.sleep_ms(500) def convertToDegree(RawDegrees): RawAsFloat = float(RawDegrees) firstdigits = int(RawAsFloat/100) nexttwodigits = RawAsFloat - float(firstdigits*100) Converted = float(firstdigits + nexttwodigits/60.0) Converted = '{0:.6f}'.format(Converted) return str(Converted) while True: getGPS(gpsModule) if(FIX_STATUS == True): print("Printing GPS data...") print(" ") print("Latitude: "+latitude) print("Longitude: "+longitude) print("Satellites: " +satellites) print("Time: "+GPStime) print("----------------------") # oled.fill(0) # oled.text("Lat: "+latitude, 0, 0) # oled.text("Lng: "+longitude, 0, 10) # oled.text("Satellites: "+satellites, 0, 20) # oled.text("Time: "+GPStime, 0, 30) # oled.show() FIX_STATUS = False if(TIMEOUT == True): print("No GPS data is found.") TIMEOUT = False
NEO-6M PICO
vcc 3v3
gnd gnd
tx 1
rx 0

需要户外时间较为漫长

NEO-6M GPS Module with ESP32 using MicroPython

NEO-6M 手册

GPS数据遵循NMEA-0183协议,该数据标准是由NMEA(National Marine Electronics Association,美国国家海事电子协会)于1983年制定的。统一标准格式NMEA-0183输出采用ASCII 码,其串行通信的参数为:波特率=4800bps,数据位=8bit,开始位=1bit,停止位=1bit,无奇偶校验。

数据传输以“语句”的方式进行,每个语句均以“$”开头,然后是两个字母的“识别符”和三个字母的“语句名”,接着就是以逗号分割的数据体,语句末尾为校验和,整条语句以回车换行符结束。

NMEA-0183的数据信息有十几种,这些信息的作用分别是:$GPGGA:输出GPS的定位信息;$GPGLL:输出大地坐标信息;$GPZDA:输出UTC时间信息;$GPGSV:输出可见的卫星信息;$GPGST:输出定位标准差信息;$GPGSA:输出卫星DOP值信息;$GPALM:输出卫星星历信息;$GPRMC:输出GPS推荐的最短数据信息等。

一、 输出语句说明:1,$GPRMC语句

(Recommended Minimum Specific GPS/TRANSIT Data-RMC,推荐定位信息1次/1秒)

对于一般的GPS动态定位应用,GPRMC语句完全满足要求。该语句中包括经纬度、速度、时间和磁偏角等字段,这些数据为导航定位应用提供了充分的信息。下表详细说明GPRMC语句中的各个字段:

$GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,,<12>

字段 $GPRMC语句意义——取值范围

<1> UTC时间:hhmmss.ss——000000.00~235959.99

<2> 状态,有效性 ——A表示有效;V表示无效

<3> 纬度格式:ddmm.mmmm——0000.00000~8959.9999 (标准的度分格式)

<4> 南北半球——N北纬;S南纬

<5> 经度格式:dddmm.mmmm——00000.0000~17959.9999(标准的度分格式)

<6> 东西半球——E表示东经;W表示西经

<7> 地面速度——000.00~999.999

<8> 速度方向——000.00~359.99

<9> 日期格式,月日年——010100~123199

<10> 磁偏角,单位:度——00.00~99.99

磁偏角方向——E表示东;W表示西

<12> 模式指示及校验和—— A=自主定位,D=差分,E=估算,N=数据无效

例如:$GPRMC,074529.82,A,2429.6717,N,11804.6973,E,12.623,32.122,010806,,W,A*08

2,$GPGGA语句

(Global Positioning System Fix Data-GGA,GPS定位信息, 输出1次/1秒)

GPS定位主要数据,该语句中包括经纬度、质量因子、HDOP、高程、基准站号等字段。下表详细说明GPGGA语句中的各个字段:

$GPGGA,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,,<12>,,<14>

字段 $GPGGA语句意义——取值范围

<1> UTC时间:hhmmss.ss——000000.00~235959.99

<2> 纬度,格式:ddmm.mmmm ——0000.00000~8959.9999(标准的度分格式)

<3> 南北半球——N北纬;S南纬

<4> 经度格式:dddmm.mmmm ——00000.0000~17959.9999(标准的度分格式)

<5> 东西半球——E表示东经;W表示西经

<6> 质量因子——0=未定位,1=GPS单点定位固定解,2=差分定位,3=PPS解;4=RTK固定解;5=RTK浮点解;6=估计值;7=手工输入模式;8=模拟模式;

<7> 应用解算位置的卫星数——00~12

<8> HDOP,水平图形强度因子——0.500~99.000 ;大于6不可用

<9> 天线高程(海平面)——-9999.9~99999.9

<10> 线线高程单位(m) ——m

大地水准面起伏——地球椭球面相对大地水准面的高度

<12> 大地水准面起伏单位(m) ——m

<13> 差分GPS数据期——差分时间(从最近一次接收到差分信号开始的秒数,如果不是差分定位将为空),不使用DGPS时为空

<14> 基准站号——0000~1023;不使用DGPS时为空

$GPGGA,074529.82,2429.6717,N,11804.6973,E,1,8,1.098,42.110,M,,M,,*76

3,$GPGSV语句

(GPS Satellites in View-GSV,可见卫星信息,1次/5秒)

GPS可见星的方位角、俯仰角、信噪比等每条语句最多包括四颗卫星的信息,每颗卫星的信息有四个数据项,即:(4)-卫星号,(5)-仰角,(6)-方位角,(7)-信噪比

$GPGSV,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>,<12>,<13>,<14>,<15>,<16>,<17>,<18>,<19>

字段 $GPGSV语句意义——取值范围

<1> 总的GSV语句电文数——0~12

<2> 当前GSV语句号

<3> 可视卫星总数——0~32

<4> 卫星号——1~32

<5> 仰角——00~90

<6> 方位角——000~359

<7> 信噪比——00~99dB无表未接收到讯号

<8> 卫星号——1~32

<9> 仰角——00~90

<10> 方位角——000~359

信噪比——00~99dB无表未接收到讯号

<12> 卫星号——1~32

<13> 仰角——00~90

<14> 方位角——000~359

<15> 信噪比——00~99dB 无表示未接收到讯号

<16> 卫星号——1~32

<17> 仰角——00~90

<18> 方位角——000~359

<19> 效验和,格式:*效验和——检查位

$GPGSV,3,1,11,1,83,54,32,3,19,192,28,6,26,57,36,7,51,140,37*7D

$GPGSV,3,2,11,14,40,136,34,16,64,266,36,20,21,293,,22,2,168,*4C

$GPGSV,3,3,11,23,10,321,,25,53,7,40,30,2,46,*48

4,$GPVTG语句

(Track Made Good and Ground Speed-VTG,地面速度信息)

格式:$GPVTG,<1>,T,<2>,M,<3>,N,<4>,K,<5>*hh

字段 $GPVTG语句意义——取值范围

<1> 以真北为参考基准的地面航向——000.000~359.999

<2> 以磁北为参考基准的地面航向——000.000~359.999

<3> 地面速率——000.000~999.999节

<4> 地面速率——0000.0~1851.8公里/小时

<5> 模式指示——A=自主定位,D=差分,E=估算,N=数据无效(仅NMEA0183 3.00版本输出)

<6> hh 校检位

$GPVTG,257.314,T,257.314,M,10.739,N,19.888,K,A*2F

5,$GPGSA语句

(GPS DOP and Active Satellites-GSA,当前卫星信息,1次/1秒)

GSA : GNSS 的当前卫星和精度因子,包括可见卫星PRN号,以及PDOP、HDOP、VDOP。如:

<1> 模式 ——M = 手动, A = 自动。

<2> 定位类型——1 = 未定位, 2 = 二维定位, 3 = 三维定位。

<3> PRN 数字——01 至 32 表天空使用中的卫星编号,最多可接收12颗卫星信息。正在用于解算位置的卫星号(01~32,前面的0也将被传输)。

<4> PDOP位置精度因子——0.5~99.9

<5> HDOP水平精度因子——0.5~99.9

<6> VDOP垂直精度因子——0.5~99.9

<7> Checksum.(检查位).

$GPGSA,<1>,<2>,<3>,<3>,,,,,<3>,<3>,<3>,<4>,<5>,<6>,<7>

$GPGSA,A,3,19,11,03,23,27,13,16,,,,,,3.43,1.67,2.99*0E

6,$GPGLL语句

(输出大地坐标信息)

$GPGLL,<1>,<2>,<3>,<4>,<5>,<6>,<7>*61

字段 $GPGLL语句意义——取值范围

<1> 纬度:ddmm.mmmmm——0000.00000~8959.9999

<2> 南纬或北纬——北纬N,S南纬

<3> 经度:dddmm.mmmmm——0000.00000~17959.99999

<4> 东、西经 ——东经E,西经W

<5> UTC时间——hh:mm:ss

<6> 数据状态——A有效,V无效

$GPGLL,2431.25310,N,11806.15429,E,081401.00,A,A*61

7,$GPZDA 语句

(输出UTC时间和日期信息)

$GPZDA, <1>,<2>,<3>,<4>,<5>*hh

字段 $GPZDA语句意义——取值范围

<1> 时间:hhmmss.ss——0000000.00~235959.99

<2> 日——00~31

<3> 月——00~12

<4> 年——0000~9999

<5> 地方时与世界时之差

<6> 检校位 hh——

$GPZDA,081401.00,14,09,2006,00,00*62

8,$GPGST 语句

(GPS 伪距噪声统计,包括了三维坐标的标准偏差信息)

字段——示例——说明

Sentence ID ——$GPGST

UTC Time——024603.00——UTC time of associated GGA fix

RMS deviation——3.2——Total RMS standard deviation of ranges inputs to the navigation solution

Semi-major deviation——6.6——Standard deviation (meters) of semi-major axis of error ellipse

Semi-minor deviation——4.7——Standard deviation (meters) of semi-minor axis of error ellipse

Semi-major orientation——47.3——Orientation of semi-major axis of error ellipse (true north degrees)

Latitude error deviation——5.8——Standard deviation (meters) of latitude error

Longitude error deviation——5.6——Standard deviation (meters) of longitude error

Altitude error deviation——22.0——Standard deviation (meters) of latitude error

Checksum—— *58

$GPGST,024603.00,3.2,6.6,4.7,47.3,5.8,5.6,22.0*58

9,$GPCN0语句

各颗用于解算的卫星信噪比:

$GPCN0,30,40,35,26,24,36,31,38

二、 输出时间说明:

 GPGGA(1次/1秒)

 GPGSA(1次/1秒)

 GPGSV(1次/5秒)

 GPRMC(1次/1秒)

 另可选用GLL,VTG或SiRF二进制格式.

三、坐标系统WGS84

WGS-84坐标系(World Geodetic System)是一种国际上采用的地心坐标系。坐标原点为地球质心,其地心空间直角坐标系的Z轴指向国际时间局(BIH)1984.0定义的协议地极(CTP)方向,X轴指向BIH1984.0的协议子午面和CTP赤道的交点,Y轴与Z轴、X轴垂直构成右手坐标系,称为1984年世界大地坐标系。这是一个国际协议地球参考系统(ITRS),是目前国际上统一采用的大地坐标系。GPS广播星历是以WGS-84坐标系为根据的。

WGS84坐标系,长轴6378137.000m,短轴6356752.314,扁率1/298.257223563。

GY-MCU90640 python UART 树莓派 范例

import serial, time
import datetime as dt
import numpy as np
import cv2

# function to get Emissivity from MCU
def get_emissivity():
    ser.write(serial.to_bytes([0xA5,0x55,0x01,0xFB]))
    read = ser.read(4)
    return read[2]/100

# function to get temperatures from MCU (Celsius degrees x 100)
def get_temp_array(d):

    # getting ambient temperature
    T_a = (int(d[1540]) + int(d[1541])*256)/100

    # getting raw array of pixels temperature
    raw_data = d[4:1540]
    T_array = np.frombuffer(raw_data, dtype=np.int16)

    return T_a, T_array

# function to convert temperatures to pixels on image
def td_to_image(f):
    norm = np.uint8((f/100 - Tmin)*255/(Tmax-Tmin))
    norm.shape = (24,32)
    return norm

########################### Main cycle #################################
# Color map range
Tmax = 40
Tmin = 20

print ('Configuring Serial port')
ser = serial.Serial ('/dev/serial0')
ser.baudrate = 115200

# set frequency of module to 4 Hz
ser.write(serial.to_bytes([0xA5,0x25,0x01,0xCB]))
time.sleep(0.1)

# Starting automatic data colection
ser.write(serial.to_bytes([0xA5,0x35,0x02,0xDC]))
t0 = time.time()

try:
    while True:
        # waiting for data frame
        data = ser.read(1544)

        # The data is ready, let's handle it!
        Ta, temp_array = get_temp_array(data)
        ta_img = td_to_image(temp_array)

        # Image processing
        img = cv2.applyColorMap(ta_img, cv2.COLORMAP_JET)
        img = cv2.resize(img, (320,240), interpolation = cv2.INTER_CUBIC)
        img = cv2.flip(img, 1)

        text = 'Tmin = {:+.1f} Tmax = {:+.1f} FPS = {:.2f}'.format(temp_array.min()/100, temp_array.max()/100, 1/(time.time() - t0))
        cv2.putText(img, text, (5, 15), cv2.FONT_HERSHEY_SIMPLEX, 0.45, (0, 0, 0), 1)
        cv2.imshow('Output', img)

        # if 's' is pressed - saving of picture
        key = cv2.waitKey(1) & 0xFF
        if key == ord("s"):
            fname = 'pic_' + dt.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + '.jpg'
            cv2.imwrite(fname, img)
            print('Saving image ', fname)

        t0 = time.time()

except KeyboardInterrupt:
    # to terminate the cycle
    ser.write(serial.to_bytes([0xA5,0x35,0x01,0xDB]))
    ser.close()
    cv2.destroyAllWindows()
    print(' Stopped')

# just in case 
ser.close()
cv2.destroyAllWindows()

转自:https://github.com/vvkuryshev/GY-MCU90640-RPI-Python

AIR10X 合宙屏幕配合ESP32C3

RT
合宙家的屏幕配上合宙家的esp32C3

插上后
上下左右按钮对应的GPIO为

屏幕 摇杆
放置

遥杆

遥杆按钮 ESP32C3
8
13
5
9
按下 4
from machine import Pin
a=Pin(8,Pin.IN,Pin.PULL_UP)
print(a.value())

屏幕

ST7735

ESP32CAM的使用 (一)

ESP32CAM的使用

基础入门

import camera

camera.init(0,format=2)
camera.init(0,format=camera.GRAYSCALE) 
#默认灰度图

camera.init(0,format=3)
camera.init(0,format=camera.JPEG)
#JPG格式

# 相关格式
# JPEG -- 3
# YUV422 -- 1
# GRAYSCALE -- 2
# RGB565 -- 0


camera.framesize(5)
#320X240 设置分辨率 

img=camera.capture()



import uos

from machine import SDCard

#FAT 格式的存储卡

uos.mount(SDCard(),'/sd')
uos.listdir()
uos.chdir('/sd')
uos.listdir()


fg=open("a.jpg","w")
fg.write(img)
fg.close() 

#thonny 使用直接右击下载文件,直接查看,本地空间,OPENMV下的esp32cam有1MB的可用空间,单纯micropython下有2MB的空间


#闪关灯

#GPIO4 为LED补光灯,若长时间使用会有严重的发热问题
from machine import Pin
flash=Pin(4,Pin.OUT)
flash.on() #打开闪关灯
flash.off() #关闭闪关灯



openmv初体验

img参数直接打印为: 分辨率 文件类型 文件大小

在非jpg下 建设使用320×240 的分辨率(默认分辨率)
可用分辨率:

需要250ms (推荐分辨率 可以4FPS)
* camera.framesize(5) 5 :::: {“w”:320, “h”:240, “type”=”grayscale”, “size”:76800} ::: 267 ms
* camera.framesize(6) 6 :::: {“w”:400, “h”:296, “type”=”grayscale”, “size”:118400} ::: 249 ms

需要750ms
* camera.framesize(7) 7 :::: {“w”:480, “h”:320, “type”=”grayscale”, “size”:153600} ::: 770 ms
* camera.framesize(8) 8 :::: {“w”:640, “h”:480, “type”=”grayscale”, “size”:307200} ::: 722 ms
* camera.framesize(9) 9 :::: {“w”:800, “h”:600, “type”=”grayscale”, “size”:480000} ::: 686 ms

需要2000ms(不建议使用)
* camera.framesize(10) 10 :::: {“w”:1024, “h”:768, “type”=”grayscale”, “size”:786432} ::: 2019 ms
* camera.framesize(11) 11 :::: {“w”:1280, “h”:720, “type”=”grayscale”, “size”:921600} ::: 1819 ms
* camera.framesize(12) 12 :::: {“w”:1280, “h”:1024, “type”=”grayscale”, “size”:1310720} ::: 2126 ms
* camera.framesize(13) 13 :::: {“w”:1600, “h”:1200, “type”=”grayscale”, “size”:1920000} ::: 1968 ms

JPG模式下全分辨率可用,但是使用OPENMV建议处理分辨率为320×240 或 400×296

ESP32CAM 处理步骤

  1. 设定相机参数
  2. 拍照
  3. 使用OPENMV处理

使用img(拍摄完的对象)进行处理
使用help(img)查看其方法
和openmv的stm32设备下,除了拍照方面不同,其他方面都差不多,文档地址:
book.openmv.cc
大家做相应的替换

二维码识别:

img.find_qrcodes()
若识别到二维码,就会返回扫描的相关数据。
但是二维码需要使用灰度图片

import time,camera
camera.init(0,format=2)
camera.init(0,format=camera.GRAYSCALE) 
while True:
    img=camera.capture()
    e=img.find_qrcodes()
    if e:
        print(e)
    time.sleep(0.5)

micropython Timer 定时器

micropython

from machine import Timer
y=Timer(12)
p=Timer(16)
y.init(period=9000, mode=Timer.ONE_SHOT, callback=lambda t:print(12))
p.init(period=9000, mode=Timer.PERIODIC, callback=lambda t:print(12))

Timer.ONE_SHOT 一次性

PERIODIC 重复

period=9000 时间9000ms

callback= 回调函数

注意:设置回调函数的必须传参数

def xc(a):#注意a的参数
    print(123)

y.init(period=9000, mode=Timer.ONE_SHOT, callback=xc)