MicroPython Slides - Wolf Den Electronics

Download Report

Transcript MicroPython Slides - Wolf Den Electronics

PyBoard – the next little thing
MicroPython OS for Arm Cortex M4
John Wolf
WolfDenElectronics.com
Why Python?
 Popular language among scientists
 Interpretive language and can be
scripted too
 Ease of designing code
 Build modular scripts
 Supports OOP
 Basically a shell around C++
 Much easier to learn and implement
 All elements are objects
 Very useful data structures
MicroPython
 Subset of Python 3.4
 Supported by the Python community
 MicroPython.org is the resource site
 Very nearly full implementation
 Restricted to practical elements that
work with a microcontroller chip
 Designed to be the Operating System
on an ARM Cortex processor
 Development board for MicroPython is
the PyBoard – the subject for today
Micro-USB port
User switch
SD card slot
4 colored LEDs
3-axis Accelerometer
Reset switch
Extensive I/O
168MHz clock
1.65”x1.3”
Personalized PyBoard with I/0
Pyb Module Features – I/O code
include pyb
statement allows you access to the PyBoard I/o
pyb.LED(1~4)
.intensity(0~255)
.on()
.off()
.toggle()
pyb.Pin.board.Name (basic syntax)
Y2 = pyb.Pin(‘Y2’, pyb.Pin.OUT_PP)
pyb.Pin.board.Y2
Y2.value(1or 0)
pyb.Pin.PULL_UP or pyb.Pin.PULL_DOWN 40k resistor
Move I/O Statements
pyb.Servo(1~4)
s1 = pyb.Servo(1)
s2 = pyb.Servo(2)
s1.angle(45)
s2.angle(0)
# create a servo object on position X1
# create a servo object on position X2
# move servo 1 to 45 degrees
# move servo 2 to 0 degrees
pyb.Accel() -> accel = pyb.Accel() create object
accel.filtered_xyz()
accel.x(), accel.y(), accel.z() or accel.tilt()
Run some Python statements – demo pyb module
Tasks.py file details what a task does.
Scheduler.py file collects tasks to run, then
the Run() starts the sequence by starting
task 1 thru however many.
In this case, the tasks start over because
of the while loop – continuous
Task have three arguments: task name,
how often to run, and when to start. Here
they all start at once. Everything is in
milliseconds