Reference   Language | Libraries | Comparison | Changes

Ciao

File System connector

Description

This Connector allows to read and write a file on Linux side from an Arduino sketch. Below the steps that you should follow to use the File connector:

  • setup File connector;
  • enable the connector;
  • write a simple sketch;
  • upload the sketch and enjoy.

Setup connector

You can find File Connector configuration file at the following path: /usr/lib/python2.7/ciao/connectors/file/file.json.conf

{
 "name" : "file",
 "description" : "File System connector for Ciao",
 "authors": ["Arduino Team <swdev@arduino.org>;"],
 "repository" : "https://github.com/arduino-org/Ciao",
 "version" : "0.0.1",
 "params" : {
              "root" : "/root",
              "eol" : "\n",
              "read_line" : false,
              "read_max_size" : 1024,
              "default_write_access_mode" : "w"
            },
 "log" :{
          "level" : "debug"
         }
}

The parameters at the beginning are for internal use, do NOT edit them (name, description, version, ciao) unless you know exactly what you are doing.

The configurable part is the one identified by "params" key:

  • “root”: specifies the starting directory for relative Path.
  • “eol”: specifies the End of Line symbol.
  • “read_line”: specifies how to read the file, line by line (true) or entire (false).
  • “read_max_size”: specifies the maximum value that it can be read each time.
  • “default_write_access_mode”: specifies the write access mode, w to overwrite the file, instead a to write in append mode.

Enable connector

Each Ciao connector must have a configuration file for the Ciao Core, this simple file is mandatory to enable the connector.

To enable File connector please edit the file at the following path: /usr/lib/python2.7/ciao/conf/file.ciao.json.conf

{
 "name" : "file",
 "enabled": true,
 "type" : "managed",
 [...]
}

The key enabled must be set to true (boolean value). This is the only parameter you are required to edit in order to enable the File Connector. Once done Ciao Core will be ready and configured to use File Connector.

Example

#include <Ciao.h>
int buttonPin = 5;
int pressed = 0;
void setup() {
  //init Ciao
  Ciao.begin();
  pinMode(buttonPin, INPUT);
}
void loop() {
  //Read digital input
  pressed = digitalRead(buttonPin);
  //Write value into a file in root folder. Root folder is specified into the connector
  //configuration file: /usr/lib/python2.7/ciao/connectors/file/file.json.conf
  //Else you can specify the absolute path for the file, eg: /tmp/my-file.log
  Ciao.write("file", "button.txt", (String)pressed, "w");
  //Delay the operations because IO is slow
  delay(1000);
}
Reference Home

Corrections, suggestions, and new documentation should be posted to the Forum.

The text of the Arduino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.