Hello, nice to meet you. This article is the 5th day of Python Advent Calendar 2014 --Qiita.
I was thinking of writing an article about running Arduino with Python, but I stopped I decided to write about "Micro Python", a microcomputer that runs on Python. (Sleeping in the desk)
Micoro Python is a programming language optimally implemented to run on a microcomputer. Unlike Arduino and Rasberry Pi, you can run a microcomputer entirely with Python!
At Pycon JP 2014, listen to the session Embedded Python with Micro Python. I thought it would be fun and tried it.
Pyboard (28 euros! Cheap?) I will run Micro Python using the micro board called.
On Pyboard
--STM32F405RG Microcontroller --1024KiB flash ROM and 192KiB RAM --Micro USB connector --Micro SD card slot
Etc. are installed. Compatible with Windows, OS X and Linux.
I will move your Pyboard at once.
First, connect the pyboard to your USB cable PC. Next, in the case of Mac, a removable disk called "PYB FLASH" will be displayed on the desktop, so open it. I think there are the following files inside.
--boot.py: The first program to run when Pyboard is connected. A file that describes various Pyboard settings. --main.py: A program that runs after boot.py. A file that describes the main program.
If you connect to pyboard with a USB cable, it will run in the order boot.py-> main.py. Basically, edit "main.py" in this.
For the time being, let's execute the program of L Chika, which is the Hello World of the microcomputer.
Write the following script in main.py.
# main.py -- put your code here!
import pyb
pyb.LED(1).on()
pyb.LED(2).on()
pyb.LED(3).on()
pyb.LED(4).on()
When you finish writing, remove it and try installing it again.
All four LEDs are lit!
An interesting feature of MicroPython is the REPL. The REPL makes it easy to test commands and code.
I will actually try it. For Mac Execute the following command.
screen /dev/tty.usbmodem*
Then the familiar REPL screen will appear.
Micro Python v1.3.3 on 2014-10-02; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> print("hello pyboard!")
hello pyboard!
>>> pyb.LED(1).on()
>>> pyb.LED(2).on()
>>> 1 + 2
3
>>> 1 / 2
0.5
>>> 20 * 'py'
'pypypypypypypypypypypypypypypypypypypypy'
You can try it more and more like this.
I usually use Arduino, but Micro Python is also active in development, and above all, I'm happy to be able to write embedded processing in Python.
Recommended Posts