MicroPython: Difference between revisions
Jump to navigation
Jump to search
m (Reverted edits by SteveMnuchin (talk) to last revision by Ⅹ) |
|||
| (One intermediate revision by one other user not shown) | |||
| Line 2: | Line 2: | ||
== programs == | == programs == | ||
=== GPS (NEMA) Reader === | |||
<pre> | |||
import uos | |||
from machine import UART | |||
uos.dupterm(None, 1) | |||
uart = UART(0, baudrate=9600) | |||
nema = '' | |||
def rl(): | |||
if uart.any(): | |||
return uart.readline().decode('UTF-8') | |||
else: | |||
return '' | |||
def capture(lines): | |||
global nema | |||
while lines > 0: | |||
nema = nema + rl() | |||
lines = lines - 1 | |||
def loop(): | |||
global nema | |||
while (1): | |||
capture(10000) | |||
print(nema) | |||
nema = '' | |||
loop() | |||
</pre> | |||
'''Sample Data''' | |||
<pre> | |||
GPRMC,055330.00,A,3741.7213,N12206.5543,W,0.1,54.75,230321,,D*4C | |||
$GPVTG,5.75,T,,M,0.01,N0.02,K,D*08 | |||
$GPGGA,055331.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPGSV,3,1,12,2,80,351,36,23,7,271,35,18,66,02,23,10,46,239,2*7E | |||
$GPGSV,3,,12,51,43,156,4,15,42,074,35,2,36,146,35,16,2,282,33*76 | |||
$GPRMC,055331.0,24251,19,27,21,31,28,13,17,046,2,32,01,191,*76 | |||
0,A,3741.7213,N12206.5543,W,0.0,76.58,230321,,D*43 | |||
$GPVTG,7.58,T,,M,0.00,N0.01,K,D*05 | |||
$GPGGA,055332.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPRMC,055332.00,A,3741.7213,N12206.5543,W,0.0,0.00,230321,,D*7C | |||
$GPVTG,0.0,T,,M,0.00,N,000,K,D*38 | |||
$GPGGA,055333.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPRMC,055333.00,A,3741.7213,N12206.5543,W,0.0,42.86,230321,,D*45 | |||
$GPVTG,4.86,T,,M,0.00,N0.01,K,D*01 | |||
$GPGGA,055334.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPRMC,055334.00,A,3741.7213,N12206.5543,W,0.0,205.12,230321,,D*7E | |||
$GPVTG,05.12,T,,M,0.00N,0.01,K,D*3D | |||
$GPGGA,055335.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPRMC,055335.00,A,3741.7213,N12206.5543,W,0.0,178.56,230321,,D*76 | |||
$GPVTG,78.56,T,,M,0.00N,0.00,K,D*35 | |||
$GPGGA,055336.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPGSV,3,1,12,2,80,351,35,23,7,271,33,18,66,02,20,10,46,239,0*7A | |||
$GPGSV,3,,12,51,43,156,3,15,42,074,34,2,36,146,33,16,2,282,31*7D | |||
$GPRMC,055336.00,A,3741.7213,N12206.5543,W,0.0,243.55,230321,,D*7D | |||
$GPVTG,43.55,T,,M,0.00N,0.01,K,D*3C | |||
$GPGGA,055337.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPRMC,055337.00,A,3741.7213,N12206.5543,W,0.0,1.24,230321,,D*7E | |||
$GPVTG,1.4,T,,M,0.00,N,001,K,D*3E | |||
$GPGGA,055338.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPRMC,055338.00,A,3741.7213,N12206.5543,W,0.0,258.07,230321,,D*7E | |||
$GPVTG,58.07,T,,M,0.00N,0.00,K,D*30 | |||
$GPGGA,055339.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6 | |||
$GPRMC,055339.00,A,3741.7213,N12206.5543,W,0.1,92.33,230321,,D*4D | |||
</pre> | |||
=== solid color neopixels (WS2812b) === | === solid color neopixels (WS2812b) === | ||
| Line 33: | Line 113: | ||
Source and instructions for compiling yourself are available at: https://github.com/micropython/micropython | Source and instructions for compiling yourself are available at: https://github.com/micropython/micropython | ||
== Mac OS X tips == | |||
*Install esptool | |||
**https://stackoverflow.com/questions/17271319/how-do-i-install-pip-on-macos-or-os-x | |||
*Find the Serial | |||
**https://stackoverflow.com/questions/12254378/how-to-find-the-serial-port-number-on-mac-os-x | |||
*Blue USB/Serial Adapter | |||
**https://learn.adafruit.com/adafruits-raspberry-pi-lesson-5-using-a-console-cable/software-installation-mac | |||
Latest revision as of 23:09, 22 March 2021
This is all about micropython.org in particular using it with ESP8266 & ESP32
programs[edit | edit source]
GPS (NEMA) Reader[edit | edit source]
import uos
from machine import UART
uos.dupterm(None, 1)
uart = UART(0, baudrate=9600)
nema = ''
def rl():
if uart.any():
return uart.readline().decode('UTF-8')
else:
return ''
def capture(lines):
global nema
while lines > 0:
nema = nema + rl()
lines = lines - 1
def loop():
global nema
while (1):
capture(10000)
print(nema)
nema = ''
loop()
Sample Data
GPRMC,055330.00,A,3741.7213,N12206.5543,W,0.1,54.75,230321,,D*4C
$GPVTG,5.75,T,,M,0.01,N0.02,K,D*08
$GPGGA,055331.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPGSV,3,1,12,2,80,351,36,23,7,271,35,18,66,02,23,10,46,239,2*7E
$GPGSV,3,,12,51,43,156,4,15,42,074,35,2,36,146,35,16,2,282,33*76
$GPRMC,055331.0,24251,19,27,21,31,28,13,17,046,2,32,01,191,*76
0,A,3741.7213,N12206.5543,W,0.0,76.58,230321,,D*43
$GPVTG,7.58,T,,M,0.00,N0.01,K,D*05
$GPGGA,055332.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPRMC,055332.00,A,3741.7213,N12206.5543,W,0.0,0.00,230321,,D*7C
$GPVTG,0.0,T,,M,0.00,N,000,K,D*38
$GPGGA,055333.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPRMC,055333.00,A,3741.7213,N12206.5543,W,0.0,42.86,230321,,D*45
$GPVTG,4.86,T,,M,0.00,N0.01,K,D*01
$GPGGA,055334.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPRMC,055334.00,A,3741.7213,N12206.5543,W,0.0,205.12,230321,,D*7E
$GPVTG,05.12,T,,M,0.00N,0.01,K,D*3D
$GPGGA,055335.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPRMC,055335.00,A,3741.7213,N12206.5543,W,0.0,178.56,230321,,D*76
$GPVTG,78.56,T,,M,0.00N,0.00,K,D*35
$GPGGA,055336.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPGSV,3,1,12,2,80,351,35,23,7,271,33,18,66,02,20,10,46,239,0*7A
$GPGSV,3,,12,51,43,156,3,15,42,074,34,2,36,146,33,16,2,282,31*7D
$GPRMC,055336.00,A,3741.7213,N12206.5543,W,0.0,243.55,230321,,D*7D
$GPVTG,43.55,T,,M,0.00N,0.01,K,D*3C
$GPGGA,055337.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPRMC,055337.00,A,3741.7213,N12206.5543,W,0.0,1.24,230321,,D*7E
$GPVTG,1.4,T,,M,0.00,N,001,K,D*3E
$GPGGA,055338.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPRMC,055338.00,A,3741.7213,N12206.5543,W,0.0,258.07,230321,,D*7E
$GPVTG,58.07,T,,M,0.00N,0.00,K,D*30
$GPGGA,055339.00,3741.7213,N,1206.5543,W,2,100.97,10.1,M,-251,M,0000,0000*6
$GPRMC,055339.00,A,3741.7213,N12206.5543,W,0.1,92.33,230321,,D*4D
solid color neopixels (WS2812b)[edit | edit source]
from machine import Pin
from neopixel import NeoPixel
NEO_PIN = const(3)
NEO_COUNT = const(72)
neo = Pin(NEO_PIN, Pin.OUT)
np = NeoPixel(neo, NEO_COUNT)
# R G B
color = [0, 20, 20]
def stripColor():
global NEO_COUNT, np, color
for x in range(0, NEO_COUNT):
np[x] = color
np.write()
# update the entire strip with one color
stripColor()
firmware/flashing[edit | edit source]
Instructions for flash and pre-compiled binaries can be found at: https://micropython.org/download
Source and instructions for compiling yourself are available at: https://github.com/micropython/micropython
Mac OS X tips[edit | edit source]
- Find the Serial