Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

This tutorial introduces you to the basics of RITDesigner, part of RITDevX project.

THIS IS A WORK IN PROGRES - THINGS CAN CHANGE

Requirements:

  • To run you need to have Java installed

Download:

https://github.com/ricardojlrufino/RITDevX/releases

Download file: rit-designer-VERSION-distribuition.zip

Running:

Unzip the ZIP file wherever you want, and then execute the file:

  • On Linux / Mac: bin\RITDesigner.sh

  • On Windows: bin\RITDesigner.bat .EXE PENDENTE

Interface Overview:

Open Example:

Please open file: /examples/DemoCharts01/interface.ritd

Run simulation:

To run simulation, you need upload sketch to Arduino board.

Open Sketch: (Appdir)/examples/DemoCharts01/DemoCharts01.ino in Arduino IDE

Install OpenDevice library using Arduino Library Manager (Installing Arduino Library )

When you have the sketch running on Arduino, on Designer press F9 or Run → Start

The Controller module will open.
You see connection status notification, after you see “Sync Done“, means that the program connected with the arduino and synchronize all information

To check if the communication is working, click on the button indicated above, it is connected with the Led on pin 13 of the Arduino.

If something is wrong, check the logs (mouse right-click).
Also try to disconnect and connect again. You can also, show logs.

How does it all work?

Now that we have everything working, let's explain how it works.

This is code for your example:

#include <OpenDevice.h>

int temperature = 0;
int humidity = 0;
int lumens = 0;

void setup() {
  //  ODev.clear(); // if you had problems try to clear EEPROM settings.
  ODev.name("MyBoard");

  ODev.addDevice("Led", 13, Device::DIGITAL);
  
  ODev.addSensor("Temperature", readTemperature)->readInterval = 200;
  ODev.addSensor("Humidity", readHumidity)->readInterval = 200;
  ODev.addSensor("Lumens", readLumens)->readInterval = 200;

  ODev.begin(Serial, 115200);
}

void loop() {
  ODev.loop();
}

//==================================================
// Listeners / Commands
//==================================================

value_t readTemperature() {
  // NOTE: Here you can substitute the code that actually reads any sensor.
  if(temperature == 100) temperature = 0;
  return temperature++;
}

value_t readHumidity() {
  if(humidity == 100) humidity = 0;
  return humidity++;
}

value_t readLumens() {
  if(lumens == 100) lumens = 0;
  return lumens++;
}

As already mentioned, we are using the OpenDevice library, it allows communication between Arduino and Application in several ways, including: USB, Bluetooth, Ethernet, WiFi / MQTT.
This library has several ways to send and receive data from the application, in this example we will explain some.
In line 17: We specify that the connection used will be through Serial (USB), using ODev.begin(Serial, 115200);

In order for actions on the interface like (Click on the Led) and it to turn on the Led on the Arduino, we need the name of the Widget to be the same name that we defined in the arduino code using: ODev.addDevice("Led", 13, Device::DIGITAL); // LINE 11

Now to send information from the Arduino to the Application, one way is to define a sensor, using: ODev.addSensor("Name").
Taking line 13 as an example. Note that in this example we are passing a function: readTemperature, it will be responsible for the reading code. (That way any sensor can be read).
Yet in line 13, we define the interval of 200ms that the sensor should be read.

OpenDevice supports some types of sensors, and it is still possible read digital/analog sensors directly without having to pass a function, using: ODev.addSensor ("Switch", 11, Device :: DIGITAL);

How communication work ?

When you add a button and click on it, a command is sent to the Device (Ex. Arduino).
This command follows a communication protocol.

See more details: How communication work

COMPLEMENTAR falar sobre como usar os nomes e os custom commands, talvez explicar um pouco do código.

  • No labels