Sketch Reference
This reference describes libraries for writing programs for GR-CITRUS and HTTP API for controlling the web compiler. Refer to the information below when using the GR-CITRUS board for the first time.
About Arduino-like Sketches
The GR-CITRUS board is compatible with Arduino Pro Mini. Most of the pin layout is the same and the libraries are used in almost the same manner. The only key difference is, in Arduino, programs are called "sketches". For simplicity, we call a program a "sketch" for GR-CITRUS as well.
Here's a little explanation about sketches. This is a simple sketch that makes one LED on the GR-CITRUS board flash.
#include <Arduino.h>
void setup(){
pinMode(PIN_LED0, OUTPUT);
}
void loop(){
digitalWrite(PIN_LED0, HIGH);
delay(200);
digitalWrite(PIN_LED0, LOW);
delay(200);
}
Arduino requires a unique description -- setup() and loop()
-- to be included in the description.
The setup() function is called only once after start up. The sketch above is preparing to turn on an LED using the pinMode() library.
The loop() function is then executed repeatedly. The sketch uses the digitalWrite() and delay() libraries to make an LED flash.
Whenever creating a sketch for the GR-CITRUS board, always describe #include <Arduino.h> in the first line.
The best thing about Arduino is its extensive number of libraries. These libraries allow you to do just about anything quite easily, from making LEDs flash, to creating sounds, running motors, and connecting to a network. Check out the contents of each library by selecting LIBRARY in the above menu.
About the Pin Layout
The image below describes the pin layout for the GR-CITRUS board. There are many cases where you will use the library with a pin number.
For example, the following description sets pin2 to LOW:
digitalWrite(2, LOW);
And, the following description reads from the A0 condition:
analogRead(A0);
Basic Library
Digital I/O
Analog I/O
Advanced I/O
Time
Math
Trigonometry
Random Numbers
Bits and Bytes
Interrupts
Serial Comm.
Standard Library
Servo Motor
Character LCD
SPI
I2C (Wire)
SD Card
SD (File Operations)
Periodic Operation
Clock (RTC)
Libraries
You can easily create gadgets using the GR-CITRUS libraries. You can light an LED, measure the time, save the data to an SD card, turn a motor, and communicate using USB.
Basic Library
This is basic output of the digital signal, calculation and interrupt. Similar to the Arduino language, you can use the basic library without additional description, #include and instance generation. For example, the following description:
#include <Arduino.h>
void setup()
{
Serial.begin(9600);
}
void loop(){
Serial.println("Hello");
delay(100);
}
This is a description to start serial communication and output the character of Hello, but it can be written as it is in setup and loop functions.
Standard Library
This is for performing motor control, network communication, memory operation, and other applied operations. You can use it with additional description. For example, the following description for a servo motor.
#include <Arduino.h>
#include <servo.h>
Servo servo0;
void setup()
{
servo0.attach(9);
servo0.write(90); // set servo to mid-point
}
void loop(){
}
This means to attach a servo motor to pin9 and set the angle to 90. Additional description is #include <servo.h> and Servo servo0 that is a generation of instance. Refer to each library page for use.
Web Compiler Control API
This API enables the user to control a project from the web compiler using HTTP communications. For example, easily create a program for a smartphone application.
The general flow in using the API is as follows: Get the project or file information in the web compiler, rewrite the specified file, then download the results of the build.
An API key is required to execute this API.
Open the settings page for details concerning the API key.
An error (null value) is returned if an API is executed while another API is already in progress.
Support
Feel free to go to the Renesas Engineering Community with questions, problems or comments. Other users, both veterans and newbies, are there to help!