The MicroPython Tutorial

MicroPython natively supports the Pyboard (https://github.com/micropython/pyboard). The Pyboard uses the STM32F405RGT6 MCU (MicroController Unit) which uses the ARM Cortex M4 core, while The WiPy (http://wipy.io/) is an Internet-of-Things (IoT) development platform which is a circuit board with a Wifi chip.

Running your first script

Once you get connected with Pyboard, There will be a drive 0:/ by the pyboard, and should contain the following 4 files:

  • boot.py -- this script is executed when the pyboard boots up. It sets up various configuration options for the pyboard.
  • main.py -- this is the main script that will contain your Python program. It is executed after boot.py.
  • README.txt -- this contains some very basic information about getting started with the pyboard.
  • pybcdc.inf -- this is a Windows driver file to configure the serial USB device.

The REPL Prompt

REPL stands for Read Evaluate Print Loop, and is the name given to the interactive Micro Python prompt that you can access on the pyboard. Using the REPL is by far the easiest way to test out your code and run commands.




To get a micro python prompt to write instructions directly to the board do,

screen /dev/ttyACM0

This is what you get from the help() function on micro python interpreter.

>>> help()         
Welcome to Micro Python!

For online help please visit http://micropython.org/help/.

Quick overview of commands for the board:
  pyb.info()    -- print some general information
  pyb.gc()      -- run the garbage collector
  pyb.delay(n)  -- wait for n milliseconds
  pyb.Switch()  -- create a switch object
                   Switch methods: (), callback(f)
  pyb.LED(n)    -- create an LED object for LED n (n=1,2,3,4)
                   LED methods: on(), off(), toggle(), intensity()
  pyb.Pin(pin)  -- get a pin, eg pyb.Pin('X1')
  pyb.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p
                   Pin methods: init(..), value([v]), high(), low()
  pyb.ExtInt(pin, m, p, callback) -- create an external interrupt object
  pyb.ADC(pin)  -- make an analog object from a pin
                   ADC methods: read(), read_timed(buf, freq)
  pyb.DAC(port) -- make a DAC object
                   DAC methods: triangle(freq), write(n), write_timed(buf, freq)
  pyb.RTC()     -- make an RTC object; methods: datetime([val])
  pyb.rng()     -- get a 30-bit hardware random number
  pyb.Servo(n)  -- create Servo object for servo n (n=1,2,3,4)
                   Servo methods: calibration(..), angle([x, [t]]), speed([x, [t]])
  pyb.Accel()   -- create an Accelerometer object
                   Accelerometer methods: x(), y(), z(), tilt(), filtered_xyz()

Pins are numbered X1-X12, X17-X22, Y1-Y12, or by their MCU name
Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT_PP, pyb.Pin.OUT_OD
Pin pull modes are: pyb.Pin.PULL_NONE, pyb.Pin.PULL_UP, pyb.Pin.PULL_DOWN
Additional serial bus objects: pyb.I2C(n), pyb.SPI(n), pyb.UART(n)

Control commands:
  CTRL-A        -- on a blank line, enter raw REPL mode
  CTRL-B        -- on a blank line, enter normal REPL mode
  CTRL-C        -- interrupt a running program
  CTRL-D        -- on a blank line, do a soft reset of the board

For further help on a specific object, type help(obj)

To close the screen session do 'Ctrl + a' and 'Ctrl + d' in sequence.


For detail please refer to The tutorial, http://micropython.org/doc/tut-contents.


Read More

Node.js Vs MicroPython for IoT

Here are the major differences between Node.js and MicroPython for IoT.

Node.js

1- Node.js built to handle asynchronous I/O from the ground up that make it good choice for IoT.

2-Dependency resolution with npm is so much better. Although if you have to develop and run the code in both Windows and Linux in rare cases you may see some quirks.

3- Right now there are two new micro-controller boards seeking funding for Node.js - one on Kickstarter ( Espruino), and the other on Dragon Innovation’s new crowdfunding platform(Tessel ).

4- Other framework and boards includes The Thing System , Node Red, noduino, and DeviceJs.

MicroPython

1-Circuit-level control is possible with MicroPython.

2- MicroPython has special commands that interface directly with assembly. Specifically, the assembly accessible to MicroPython is the ARM Thumb-2 instruction set. As an example, the command "mov(R1, 0xff)" would move the hexadecimal number "ff" to register-1.

3- MicroPython natively supports the Pyboard (https://github.com/micropython/pyboard). The Pyboard uses the STM32F405RGT6 MCU (MicroController Unit) which uses the ARM Cortex M4 core. The hardware is 32-bits and runs at 168MHz. The Pyboard supports I2C, UART, SPC, and GPIO.


4-MicroPython is used in the WiPy (http://wipy.io/). The WiPy is an Internet-of-Things (IoT) development platform which is a circuit board with a Wifi chip. Developers can easily program the WiPy and upload new code via Over-The-Air (OTA) updates. The WiPy uses the TI CC3200 MCU (Cortex-M4 @ 80MHz), has 256 kilobytes or RAM, and supports WiFi-Direct. The WiPy can be used to make various wireless devices. The WiPy can also be interfaced with the Pyboard or many other motherboards and circuits via its GPIO pins, I2C bus, or SPI. WiPy's manufacturer is Bestronics (http://bestronics.eu/).

5- Right now LoPy seeking funding on Kickstarter, It is a MicroPython triple-network dev platform which doubles up as a LoRa Nano gateway and Arduino IDE compatible as stretch goal. It include a dual processor (each core running @ 160 MHz) + WiFi + BLE radio System on Chip, network processor handles the WiFi/BLE connectivity and the IPv6 and IPv4 stacks and main processor entirely free to run the user application along with the LoRa stack.

Read More

Node.js - Ideal choice for IoT

There has been a lot of talk lately about the rising popularity of Node.js, but no one expected it would grow this quickly. Built on Google’s V8 open source JavaScript engine, Node.js is known for its speed, scalability and efficiency—making it great for developing data-intensive, real-time applications, that of course, makes Node.js well-suited for the IoT, which is reliant on data-intensive, real-time devices and applications.

Devices within the IoT, such as sensors and wearables, generate large floods of requests. Node.js is well-suited for managing these requests via streams that can be processed and monitored very efficiently. Stream instances are basically Unix pipes. They can be readable, writable or both, and are easy to work with. Streams allow users to pipe requests to each other, or stream data directly to its destination. No caching, no temporary data--just stream from one place to another.

Riding on the widespread popularity of Node.js in combination with low cost prototyping hardware, a new set of projects have emerged letting client side web developers use their skills to start controlling elements in the physical world.

The Thing System

The Thing System is a set of software components and network protocols that aims to fix the Internet of Things. Our steward software is written in node.js making it both portable and easily extensible. It can run on your laptop, or fit onto a small single board computer like the Raspberry Pi.

Node-RED

A visual tool for wiring the Internet of Things, a creation of the IBM Emerging Technology Services team.

noduino

A simple and flexible JavaScript and Node.js Framework for accessing basic Arduino controls from Web Applications using HTML5, Socket.IO and Node.js.

DeviceJS

DeviceJS is a JavaScript based development platform for reacting to sensors and controlling devices. It’s built on top of Google’s V8 JavaScript engine, Node.js and a real-time JSON database. A DeviceJS application can run on a single device, or across many devices in different locations.
 
 
Read More

MicroPython - the future of IoT

MicroPython is a lean and fast implementation of the Python 3 programming language that is optimised to run on a microcontroller. It has advantages over traditional programming software such as C/C++ because it is essentially a live development environment and your write and debug code much faster…in fact 5-10 times faster than C++.

It ensures that the memory size/microcontroller performance is optimised and fit for purpose for the application it serves. Many sensor reading and reporting applications do not require a PC based processor as this would make the total application over priced and under-efficient.

As a programming language it is expressive and versatile and allows the developer or enterprise engineering teams to choose components that are optimised both in terms of price and performance.
Micropython is environmentally friendly. Yes, that right and here’s why: when a device boots up using MicroPython it does not consume memory and thus doesn’t incur current drain.

The tutorial, http://micropython.org/doc/tut-contents, is really nice and easy to follow.

To get a micro python prompt to write instructions directly to the board do,

screen /dev/ttyACM0

This is what you get from the help() function on micro python interpreter.

>>> help()         
Welcome to Micro Python!

For online help please visit http://micropython.org/help/.

Quick overview of commands for the board:
  pyb.info()    -- print some general information
  pyb.gc()      -- run the garbage collector
  pyb.delay(n)  -- wait for n milliseconds
  pyb.Switch()  -- create a switch object
                   Switch methods: (), callback(f)
  pyb.LED(n)    -- create an LED object for LED n (n=1,2,3,4)
                   LED methods: on(), off(), toggle(), intensity()
  pyb.Pin(pin)  -- get a pin, eg pyb.Pin('X1')
  pyb.Pin(pin, m, [p]) -- get a pin and configure it for IO mode m, pull mode p
                   Pin methods: init(..), value([v]), high(), low()
  pyb.ExtInt(pin, m, p, callback) -- create an external interrupt object
  pyb.ADC(pin)  -- make an analog object from a pin
                   ADC methods: read(), read_timed(buf, freq)
  pyb.DAC(port) -- make a DAC object
                   DAC methods: triangle(freq), write(n), write_timed(buf, freq)
  pyb.RTC()     -- make an RTC object; methods: datetime([val])
  pyb.rng()     -- get a 30-bit hardware random number
  pyb.Servo(n)  -- create Servo object for servo n (n=1,2,3,4)
                   Servo methods: calibration(..), angle([x, [t]]), speed([x, [t]])
  pyb.Accel()   -- create an Accelerometer object
                   Accelerometer methods: x(), y(), z(), tilt(), filtered_xyz()

Pins are numbered X1-X12, X17-X22, Y1-Y12, or by their MCU name
Pin IO modes are: pyb.Pin.IN, pyb.Pin.OUT_PP, pyb.Pin.OUT_OD
Pin pull modes are: pyb.Pin.PULL_NONE, pyb.Pin.PULL_UP, pyb.Pin.PULL_DOWN
Additional serial bus objects: pyb.I2C(n), pyb.SPI(n), pyb.UART(n)

Control commands:
  CTRL-A        -- on a blank line, enter raw REPL mode
  CTRL-B        -- on a blank line, enter normal REPL mode
  CTRL-C        -- interrupt a running program
  CTRL-D        -- on a blank line, do a soft reset of the board

For further help on a specific object, type help(obj)

To close the screen session do 'Ctrl + a' and 'Ctrl + d' in sequence.
Read More