Microcomputer with Python

Microcomputer with Python

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)

What is MicroPython?

pyboard

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.

Procedure to Hello World (L Chika)

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.

IMG_0222.jpg

All four LEDs are lit!

Micro Python REPL

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

Microcomputer with Python
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
with syntax (Python)
Zundokokiyoshi with python
Excel with Python
Cast with python
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Learning Python with ChemTHEATER 03
Sequential search with Python
Run Python with VBA
Handling yaml with python
Solve AtCoder 167 with python
Serial communication with python
[Python] Use JSON with Python
Learning Python with ChemTHEATER 05-1
Learn Python with ChemTHEATER
Run prepDE.py with python3
1.1 Getting Started with Python
Collecting tweets with Python
Binarization with OpenCV / Python
3. 3. AI programming with Python
Kernel Method with Python
Non-blocking with Python + uWSGI
Scraping with Python + PhantomJS
Posting tweets with python
Use mecab with Python3
[Python] Redirect with CGIHTTPServer
Operate Kinesis with Python
Getting Started with Python
Use DynamoDB with Python
Zundko getter with python
Handle Excel with python
Ohm's Law with Python
Primality test with python
Run Blender with python
Solve Sudoku with Python
Python starting with Windows 7
Multi-process asynchronously with python
Python programming with Atom
Learning Python with ChemTHEATER 02
Competitive programming with python
Handle rabbimq with python
GRPC starting with Python
Install Voluptuous with Python 2.5