Arduino

Arduino in RIOT. More...

Detailed Description

Arduino in RIOT.

About

This module enables users to run unmodified Arduino sketches in RIOT. For this we aim at supporting the full Arduino API.

The support of the Arduino API in RIOT is useful for multiple reasons:

Refer to Arduino API for the actual API documentation

General usage

To run your Arduino sketch in RIOT, just follow these steps:

  1. create an empty application
  2. add the arduino module to your application, your Makefile should now look something like this:
    APPLICATION = YOUR_APP_NAME
    BOARD ?= YOUR_TARGET_PLATFORM
    RIOTBASE ?= PATH_TO_RIOT_ROOT
    USEMODULE += arduino
    include $(RIOTBASE)/Makefile.include
  3. copy your Arduino sktech(es) into your application folder. Currently they must have the file ending *.sketch to be processed.
  4. build, flash, and run your application the usual RIOT-way: simply call make all, make flash, make term, etc.

That's all. As bonus you can of course use any existing RIOT code inside your Arduino sketches - you simply have to add the includes to your sketch and the corresponding modules to your Makefile.

Note
So far, all Arduino sketches MUST have the file ending *.sketch to be recognized by RIOT's build system

Concept

For enabling RIOT to run Arduino sketches, we extended the build system to handle *.sketch files and we implemented the Arduino API using RIOT's native functions.

Extension of the build system

Building Arduino sketches in RIOT is done in a three step process.

First, the make system defines a generated arduino_sketches module placed into Arduino sketches makefile, which is included from the Makefile.include of the RIOT Arduino module. The generated module is added to used modules and build directories.

Second, as prerequisites for the link target, the make system will create the module into /arduino_sketches with an arduino_sketches.cpp source file. Into this file, it copies some Arduino glue code ( pre.snip and post.snip) together with the contents of all *.sketch files contained in the application folder.

Third, the RIOT make system is called as usual, building the generated library with the Arduino code and including it in the final firmware.

Implementation of the Arduino API

For supporting the Arduino API, we have created our own function and class definitions, using the exact same signatures as in the original Arduino header files. These headers are then implemented using standard RIOT APIs, e.g. the peripheral drivers, xtimer, etc.

Add Arduino support to a board

Note
As prerequisite, the board must have support for C++.

To add Arduino support to a board, it has to provide the following:

In RIOT/board/BOARD/include/arduino_board.h:

In addition, you have to add the 'arduino' feature to the board. For this, just add FEATURES_PROVIDED += arduino to the 'other features' section in your board's ‘Makefile.features’.

That's it, your board can now run Ardunio sketches.

Open issues

Todo:

Make it possible to bootstrap Arduino code manually from any RIOT application. Include a pseudomule as e.g. arduino_base, which does not implement a main function calling setup() and loop(), so these functions have to be called manually from a RIOT application.

Implement analog outputs (PWM mapping)

Implement analog inputs (ADC mapping)

Add means to include various Arduino Libraries (maybe as pkg?)

Implement anything else that is missing...

Adapt Arduino build script, so sketches do not have to have the file ending *.sketch anymore

Modules

 Arduino API
 Implementation of the Arduino API in RIOT.
 

Files

file  Arduino.h
 Wrapper to keep source code compatibility for Arduino.h.
 
file  SPI.h
 Wrapper to access the definition of the Arduino 'SPI' interface.
 
file  Wire.h
 Wrapper to keep source code compatibility for Wire.h.
 
adc_t
unsigned int adc_t
Define default ADC type identifier.
Definition: adc.h:72
PORT_A
@ PORT_A
port A
Definition: periph_cpu.h:36
PORT_D
@ PORT_D
port D
Definition: periph_cpu.h:39
arduino_analog_map
static const adc_t arduino_analog_map[]
Look-up table for the Arduino's analog pins.
Definition: arduino_board.h:124
ADC_LINE
#define ADC_LINE(x)
Default ADC line access macro.
Definition: adc.h:86
GPIO_PIN
#define GPIO_PIN(x, y)
Define a CPU specific GPIO pin generator macro.
Definition: periph_cpu.h:35
PORT_B
@ PORT_B
port B
Definition: periph_cpu.h:37
arduino_pinmap
static const gpio_t arduino_pinmap[]
Look-up table for the Arduino's digital pins.
Definition: arduino_board.h:40