SlideShare una empresa de Scribd logo
1 de 17
Python on a Chip
                  PyMite, a Python Virtual Machine



                                                      Jeremy Stott
                                                jeremy@stott.co.nz


Kiwi Pycon 2011              Python on a Chip             jeremy@stott.co.nz
Microcontrollers

• Programming Microcontrollers is
  fun!

• You can build your own toys / evil
  robots

• Even getting lights to blink is fun

• Usually programmed in C,
  sometimes C++




                         http://lighttrees.com/wordpress/archives/category/sculpture
 Kiwi Pycon 2011              Python on a Chip                      jeremy@stott.co.nz
What's wrong with C?!
                                                    #include <stdio.h>
                                                    int l;int main(int o,char **O,
• Nothing is wrong with C                           int I){char c,*D=O[1];if(o>0){
                                                    for(l=0;D[l               ];D[l
                                                    ++]-=10){D    [l++]-=120;D[l]-=
• It's up to the programmer to write good           110;while    (!main(0,O,l))D[l]
                                                    +=   20;    putchar((D[l]+1032)
  code                                              /20   )    ;}putchar(10);}else{
                                                    c=o+      (D[I]+82)%10-(I>l/2)*
                                                    (D[I-l+I]+72)/10-9;D[I]+=I<0?0
• Programmers may suffer from object                :!(o=main(c/10,O,I-1))*((c+999
                                                    )%10-(D[I]+92)%10);}return o;}
  oriented withdrawal syndrome

• Prolonged use of C may cause
  inappropriate outbursts of semi-colons;

• You can't do [Python reference] in C


                                           http://www0.us.ioccc.org/years.html#2001
  Kiwi Pycon 2011           Python on a Chip                       jeremy@stott.co.nz
Introducing: Python-On-A-Chip

●
    http://code.google.com/p/python-on-a-chip/
●
    A project developing PyMite, a Python Virtual Machine
      designed to run on Microcontrollers
●
    A small growing group > 256 mailing list members
●
    Uses 55KB of ROM and 5KB of RAM for "Hello World!"
●
    License:
        ●
            Tools: GNU LGPL v2.1 (Lesser GPL)
        ●
            Virtual Machine: GPL v2 (Non Commercial)


    Kiwi Pycon 2011          Python on a Chip          jeremy@stott.co.nz
Features
It Does:

• Support integers, floats, lists, dicts, functions, modules,
  classes, generators, decorators and closures

• Support 25 out of 29 keywords and 89 out of 112 byte codes
  from Python 2.6

• Stackless green threads

It Doesn't:

• Have a built in compiler

• Support any of Python's standard libraries
 Kiwi Pycon 2011           Python on a Chip            jeremy@stott.co.nz
25 out of 29 Keywords?

PyMite supports the following set of Python's keywords
      and          assert      break           class       continue
      def          del         elif            else        for
      from         global      if              import      in
      is           lambda      not             or          pass
      print        raise       return          while       yield

PyMite does not support these keywords
    except  exec   finally   try

However, they are working on Exceptions




 Kiwi Pycon 2011                Python on a Chip                  jeremy@stott.co.nz
No Standard Libraries?

Instead of supporting Python's libraries, PyMite offer its own set
of modules. Some of which have the same name as their
Python counterparts.
 
PyMite Modules
    dict   func   list   string   sys
As well as many built in functions
      abs(x), bytearray(seq), bytearray(len), chr(i),
      eval(co), globals(), id(o), len(obj), locals(), 
      map(f,s), ord(c), pow(x,y), range(...), sum(s),
      type(obj)




 Kiwi Pycon 2011           Python on a Chip           jeremy@stott.co.nz
Other Interesting Bits

• PyMite only supports 8-bit character strings, so no
  Unicode

• PyMite supports 32-bit signed integers, floats (if
  enabled) but not longs

• You can't override type operators. Eg '__add__()'
  doesn't override '+'




 Kiwi Pycon 2011        Python on a Chip          jeremy@stott.co.nz
Installing under Ubuntu 11.04

The easiest way to get PyMite is to check it out using Mercurial:
$ hg clone https://code.google.com/p/python-on-a-chip/

Install Python 2.6, setuptools and virtualenv
$ sudo apt-get install python2.6 python-setuptools
$ sudo easy_install virtualenv

Create the virtual environment and activate it
$ virtualenv -p python2.6 --no-site-packages ./pymite
$ source pymite/bin/activate




 Kiwi Pycon 2011           Python on a Chip          jeremy@stott.co.nz
Windows?  Almost

Download GNU Make, Python 2.6, SetupTools, and VirtualEnv
http://gnuwin32.sourceforge.net/packages/make.htm
http://www.python.org/getit/releases/2.6.6/
http://pypi.python.org/pypi/setuptools

Install and add their paths to your Path Environment Variable
c:Python26
c:Python26Scripts
c:Program FilesGnuWin32bin

Install and activate VirtualEnv
> easy_install.exe virtualenv
> virtualenv.exe --no-site-packages c:pymite
> c:pymiteScriptsactivate.bat

And then you install a C compiler...
 Kiwi Pycon 2011           Python on a Chip         jeremy@stott.co.nz
Interactive Prompt

To compile for the desktop and launch the interactive prompt
$ make ipm

(make sure you have activated the Python2.6 VirtualEnv)
Test it out
ipm> class Robot():
....     def walk(self, direction):
....         print "Walking %s" % (direction,)
....
ipm> pybot = Robot()
ipm> pybot.walk("to the shops")
Walking to the shops




 Kiwi Pycon 2011            Python on a Chip              jeremy@stott.co.nz
Microcontrollers?

mBed Microcontroller

• 32-bit ARM Processor

• Built-in USB interface

• Powered via USB

• Implements a Mass Storage Device, so programming is as
  easy as copying the binary onto the Flash drive

• Many peripherals eg Ethernet, USB, Can, SPI, etc…

• Online Compiler
 Kiwi Pycon 2011           Python on a Chip     jeremy@stott.co.nz
Kiwi Pycon 2011   Python on a Chip   jeremy@stott.co.nz
Robots!

m3pi from Pololu


•Easy to set up

•Ideal for getting started

•Cost:
– m3pi Robot $150 USD

– mbed Micro $60 USD

•Surprisingly Fast!!


 Kiwi Pycon 2011             Python on a Chip   jeremy@stott.co.nz
What about Wireless?

Nobody likes to follow their robot around with a laptop…

The m3pi has a handy slot for a Digi Zigbee module.

But these $35 WiFi modules fit in the same slot:

RN-XV from Roving Networks
http://rovingnetworks.com/XVee.php

• Have the same pin-out
• Support WPA2
• Make the project awesome!


 Kiwi Pycon 2011               Python on a Chip       jeremy@stott.co.nz
Putting it all together

Compile PyMite for the mbed target
$ make PLATFORM=mbed

Import the resulting .zip archive into the mbed IDE

Import the m3pi library into the mbed IDE

Compile and save the binary onto the mbed microcontroller

Turn on the Robot and connect to the ipm using a python
socket
$ tools/ipm.py –-ipaddress 192.168.1.3 –-port 2000




 Kiwi Pycon 2011          Python on a Chip            jeremy@stott.co.nz
Thank You




                  Any Questions?




Kiwi Pycon 2011      Python on a Chip   jeremy@stott.co.nz

Más contenido relacionado

La actualidad más candente

pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__Renyuan Lyu
 
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...David Beazley (Dabeaz LLC)
 
Python Developer Certification
Python Developer CertificationPython Developer Certification
Python Developer CertificationVskills
 
Python and Machine Learning
Python and Machine LearningPython and Machine Learning
Python and Machine Learningtrygub
 
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...Tsundere Chen
 
Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015Younggun Kim
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Yung-Yu Chen
 
Mixing C++ & Python II: Pybind11
Mixing C++ & Python II: Pybind11Mixing C++ & Python II: Pybind11
Mixing C++ & Python II: Pybind11corehard_by
 
Take advantage of C++ from Python
Take advantage of C++ from PythonTake advantage of C++ from Python
Take advantage of C++ from PythonYung-Yu Chen
 
AI Machine Learning Complete Course: for PHP & Python Devs
AI Machine Learning Complete Course: for PHP & Python DevsAI Machine Learning Complete Course: for PHP & Python Devs
AI Machine Learning Complete Course: for PHP & Python DevsAmr Shawqy
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationGlobalLogic Ukraine
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminarygo-lang
 
Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Max Kleiner
 
Про асинхронность / Максим Щепелин / Web Developer Wargaming
Про асинхронность / Максим Щепелин / Web Developer WargamingПро асинхронность / Максим Щепелин / Web Developer Wargaming
Про асинхронность / Максим Щепелин / Web Developer WargamingPython Meetup
 

La actualidad más candente (20)

pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__pyconjp2015_talk_Translation of Python Program__
pyconjp2015_talk_Translation of Python Program__
 
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
An Embedded Error Recovery and Debugging Mechanism for Scripting Language Ext...
 
PyPy London Demo Evening 2013
PyPy London Demo Evening 2013PyPy London Demo Evening 2013
PyPy London Demo Evening 2013
 
Python Developer Certification
Python Developer CertificationPython Developer Certification
Python Developer Certification
 
Python and Machine Learning
Python and Machine LearningPython and Machine Learning
Python and Machine Learning
 
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
 
Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015Writing Fast Code (JP) - PyCon JP 2015
Writing Fast Code (JP) - PyCon JP 2015
 
Tensorflow 2.0 and Coral Edge TPU
Tensorflow 2.0 and Coral Edge TPU Tensorflow 2.0 and Coral Edge TPU
Tensorflow 2.0 and Coral Edge TPU
 
Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020Notes about moving from python to c++ py contw 2020
Notes about moving from python to c++ py contw 2020
 
Mixing C++ & Python II: Pybind11
Mixing C++ & Python II: Pybind11Mixing C++ & Python II: Pybind11
Mixing C++ & Python II: Pybind11
 
Take advantage of C++ from Python
Take advantage of C++ from PythonTake advantage of C++ from Python
Take advantage of C++ from Python
 
AI Machine Learning Complete Course: for PHP & Python Devs
AI Machine Learning Complete Course: for PHP & Python DevsAI Machine Learning Complete Course: for PHP & Python Devs
AI Machine Learning Complete Course: for PHP & Python Devs
 
Android and cpp
Android and cppAndroid and cpp
Android and cpp
 
Introduction of python
Introduction of pythonIntroduction of python
Introduction of python
 
Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
 
Python in Action (Part 1)
Python in Action (Part 1)Python in Action (Part 1)
Python in Action (Part 1)
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
Golang iran - tutorial go programming language - Preliminary
Golang iran - tutorial  go programming language - PreliminaryGolang iran - tutorial  go programming language - Preliminary
Golang iran - tutorial go programming language - Preliminary
 
Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2Pascal script maxbox_ekon_14_2
Pascal script maxbox_ekon_14_2
 
Про асинхронность / Максим Щепелин / Web Developer Wargaming
Про асинхронность / Максим Щепелин / Web Developer WargamingПро асинхронность / Максим Щепелин / Web Developer Wargaming
Про асинхронность / Максим Щепелин / Web Developer Wargaming
 

Similar a Python on a chip

Writing a Python C extension
Writing a Python C extensionWriting a Python C extension
Writing a Python C extensionSqreen
 
What is Python? (Silicon Valley CodeCamp 2015)
What is Python? (Silicon Valley CodeCamp 2015)What is Python? (Silicon Valley CodeCamp 2015)
What is Python? (Silicon Valley CodeCamp 2015)wesley chun
 
What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)wesley chun
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsHenry Schreiner
 
Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its ApplicationsAbhijeet Singh
 
Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Sapna Tyagi
 
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdfThe Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdfssuser8b3cdd
 
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...Richard Rowland
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitcbenDesigning
 
Startup Camp - Git, Python, Django session
Startup Camp - Git, Python, Django sessionStartup Camp - Git, Python, Django session
Startup Camp - Git, Python, Django sessionJuraj Michálek
 
Qt for Python
Qt for PythonQt for Python
Qt for PythonICS
 
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat Pôle Systematic Paris-Region
 
Introduction to the rapid prototyping with python and linux for embedded systems
Introduction to the rapid prototyping with python and linux for embedded systemsIntroduction to the rapid prototyping with python and linux for embedded systems
Introduction to the rapid prototyping with python and linux for embedded systemsNaohiko Shimizu
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSCisco Russia
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3Youhei Sakurai
 

Similar a Python on a chip (20)

Writing a Python C extension
Writing a Python C extensionWriting a Python C extension
Writing a Python C extension
 
What is Python? (Silicon Valley CodeCamp 2015)
What is Python? (Silicon Valley CodeCamp 2015)What is Python? (Silicon Valley CodeCamp 2015)
What is Python? (Silicon Valley CodeCamp 2015)
 
What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)What is Python? (Silicon Valley CodeCamp 2014)
What is Python? (Silicon Valley CodeCamp 2014)
 
PyCon2022 - Building Python Extensions
PyCon2022 - Building Python ExtensionsPyCon2022 - Building Python Extensions
PyCon2022 - Building Python Extensions
 
What is Python?
What is Python?What is Python?
What is Python?
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its Applications
 
Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425
 
Python on pi
Python on piPython on pi
Python on pi
 
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdfThe Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
 
Python in a real life
Python in a real lifePython in a real life
Python in a real life
 
PySide
PySidePySide
PySide
 
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
Why "Hello World" is a Massive Operation - From Python code to Stack Virtual ...
 
Open frameworks 101_fitc
Open frameworks 101_fitcOpen frameworks 101_fitc
Open frameworks 101_fitc
 
Startup Camp - Git, Python, Django session
Startup Camp - Git, Python, Django sessionStartup Camp - Git, Python, Django session
Startup Camp - Git, Python, Django session
 
Qt for Python
Qt for PythonQt for Python
Qt for Python
 
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
PyParis 2017 / Writing a C Python extension in 2017, Jean-Baptiste Aviat
 
Introduction to the rapid prototyping with python and linux for embedded systems
Introduction to the rapid prototyping with python and linux for embedded systemsIntroduction to the rapid prototyping with python and linux for embedded systems
Introduction to the rapid prototyping with python and linux for embedded systems
 
Возможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OSВозможности интерпретатора Python в NX-OS
Возможности интерпретатора Python в NX-OS
 
Introduction to python 3
Introduction to python 3Introduction to python 3
Introduction to python 3
 

Último

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Scott Andery
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
Enhancing User Experience - Exploring the Latest Features of Tallyman Axis Lo...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

Python on a chip

  • 1. Python on a Chip PyMite, a Python Virtual Machine Jeremy Stott jeremy@stott.co.nz Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 2. Microcontrollers • Programming Microcontrollers is fun! • You can build your own toys / evil robots • Even getting lights to blink is fun • Usually programmed in C, sometimes C++ http://lighttrees.com/wordpress/archives/category/sculpture Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 3. What's wrong with C?! #include <stdio.h> int l;int main(int o,char **O, • Nothing is wrong with C int I){char c,*D=O[1];if(o>0){ for(l=0;D[l ];D[l ++]-=10){D [l++]-=120;D[l]-= • It's up to the programmer to write good 110;while (!main(0,O,l))D[l] += 20; putchar((D[l]+1032) code /20 ) ;}putchar(10);}else{ c=o+ (D[I]+82)%10-(I>l/2)* (D[I-l+I]+72)/10-9;D[I]+=I<0?0 • Programmers may suffer from object :!(o=main(c/10,O,I-1))*((c+999 )%10-(D[I]+92)%10);}return o;} oriented withdrawal syndrome • Prolonged use of C may cause inappropriate outbursts of semi-colons; • You can't do [Python reference] in C http://www0.us.ioccc.org/years.html#2001 Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 4. Introducing: Python-On-A-Chip ● http://code.google.com/p/python-on-a-chip/ ● A project developing PyMite, a Python Virtual Machine designed to run on Microcontrollers ● A small growing group > 256 mailing list members ● Uses 55KB of ROM and 5KB of RAM for "Hello World!" ● License: ● Tools: GNU LGPL v2.1 (Lesser GPL) ● Virtual Machine: GPL v2 (Non Commercial) Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 5. Features It Does: • Support integers, floats, lists, dicts, functions, modules, classes, generators, decorators and closures • Support 25 out of 29 keywords and 89 out of 112 byte codes from Python 2.6 • Stackless green threads It Doesn't: • Have a built in compiler • Support any of Python's standard libraries Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 6. 25 out of 29 Keywords? PyMite supports the following set of Python's keywords     and      assert    break     class     continue     def      del       elif      else      for     from     global    if        import    in     is       lambda    not       or        pass     print    raise     return    while     yield PyMite does not support these keywords     except  exec   finally   try However, they are working on Exceptions Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 7. No Standard Libraries? Instead of supporting Python's libraries, PyMite offer its own set of modules. Some of which have the same name as their Python counterparts.   PyMite Modules     dict   func   list   string   sys As well as many built in functions     abs(x), bytearray(seq), bytearray(len), chr(i),     eval(co), globals(), id(o), len(obj), locals(),      map(f,s), ord(c), pow(x,y), range(...), sum(s),     type(obj) Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 8. Other Interesting Bits • PyMite only supports 8-bit character strings, so no Unicode • PyMite supports 32-bit signed integers, floats (if enabled) but not longs • You can't override type operators. Eg '__add__()' doesn't override '+' Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 9. Installing under Ubuntu 11.04 The easiest way to get PyMite is to check it out using Mercurial: $ hg clone https://code.google.com/p/python-on-a-chip/ Install Python 2.6, setuptools and virtualenv $ sudo apt-get install python2.6 python-setuptools $ sudo easy_install virtualenv Create the virtual environment and activate it $ virtualenv -p python2.6 --no-site-packages ./pymite $ source pymite/bin/activate Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 10. Windows?  Almost Download GNU Make, Python 2.6, SetupTools, and VirtualEnv http://gnuwin32.sourceforge.net/packages/make.htm http://www.python.org/getit/releases/2.6.6/ http://pypi.python.org/pypi/setuptools Install and add their paths to your Path Environment Variable c:Python26 c:Python26Scripts c:Program FilesGnuWin32bin Install and activate VirtualEnv > easy_install.exe virtualenv > virtualenv.exe --no-site-packages c:pymite > c:pymiteScriptsactivate.bat And then you install a C compiler... Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 11. Interactive Prompt To compile for the desktop and launch the interactive prompt $ make ipm (make sure you have activated the Python2.6 VirtualEnv) Test it out ipm> class Robot(): ....     def walk(self, direction): ....         print "Walking %s" % (direction,) .... ipm> pybot = Robot() ipm> pybot.walk("to the shops") Walking to the shops Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 12. Microcontrollers? mBed Microcontroller • 32-bit ARM Processor • Built-in USB interface • Powered via USB • Implements a Mass Storage Device, so programming is as easy as copying the binary onto the Flash drive • Many peripherals eg Ethernet, USB, Can, SPI, etc… • Online Compiler Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 13. Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 14. Robots! m3pi from Pololu •Easy to set up •Ideal for getting started •Cost: – m3pi Robot $150 USD – mbed Micro $60 USD •Surprisingly Fast!! Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 15. What about Wireless? Nobody likes to follow their robot around with a laptop… The m3pi has a handy slot for a Digi Zigbee module. But these $35 WiFi modules fit in the same slot: RN-XV from Roving Networks http://rovingnetworks.com/XVee.php • Have the same pin-out • Support WPA2 • Make the project awesome! Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 16. Putting it all together Compile PyMite for the mbed target $ make PLATFORM=mbed Import the resulting .zip archive into the mbed IDE Import the m3pi library into the mbed IDE Compile and save the binary onto the mbed microcontroller Turn on the Robot and connect to the ipm using a python socket $ tools/ipm.py –-ipaddress 192.168.1.3 –-port 2000 Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz
  • 17. Thank You Any Questions? Kiwi Pycon 2011 Python on a Chip jeremy@stott.co.nz