Image 01

Image 01 Image 01

A&A-Scheduler

The A&A-Scheduler application is designed to work with microcontrollers. A task scheduler designed to control Arduino and other microcontroller platforms using Android devices. Communication with the microcontroller is carried out using a USB UART adapter. A&A-Scheduler automatically recognizes USB UART adapter drivers and attempts to send a request to the microcontroller, waiting for a ready response. After receiving the ready signal, the A&A-Scheduler will send the appropriate commands to the microcontroller according to the planned schedule. A&A-Scheduler runs in the background.

Image 01

Image 02

Image 03

Image 04

To understand how an application works with a microcontroller, let's look at a simple example. The essence of the example is to demonstrate the recognition by the application of the connection of the microcontroller and the processing by the microcontroller of commands coming from the application. To do this, we will use the Arduino NANO platform, a piezo speaker, 5 (pcs) LEDs, 6 (pcs) resistors. The Arduino NANO platform is already integrated with a USB UART controller and has a USB connector. First of all, let's connect NANO with a USB cable to our android device. When the application is launched or if it is running, the android system will ask us for permission for the application to work with the USB UART. At this stage, it doesn't matter whether you approve or deny this request. Next, go to the control screen and click on the item “List of USB devices”. In the window that opens, you will see a line with the name of the USB UART controller (see figure). The next step is to assemble the circuit shown in the figure and connect it to the corresponding pins of the arduino NANO. You need to download the program to the microcontroller. To do this, we will use the "Arduino IDE".

You can check out the sketch below. After uploading the sketch to arduino NANO, you can connect it to our android device. Power for arduino NANO will come from android device. Now you need to approve the system request to allow the application to work with the USB UART. After that, the note-message icon will change to “v”, and the piezo speaker connected to the arduino NANO will beep. As you can see from the sketch, the application works with the microcontroller at a speed of 115200 bit. When a USB UART controller is detected, the application sends a request - stmA and expects a response in the form - rtmA. After receiving a response, the application considers the connection to the microcontroller established and is ready to send the scheduled commands. Before scheduling a task, you can check how the microcontroller responds to commands. After establishing a connection with the microcontroller on the control screen, select the item “Test commands”. In the list that opens, select the required command. It will immediately be transferred to the microcontroller. For example “Commanda2 = 000011A” means that 000011A will be sent. In our example, this means that two LEDs will light up and turn off after 2 seconds.

Download sketch (here):

const int piezo_pin = 4;
const String inOtklik = "stmA";
const String outOtklik = "rtmA";
String command = "";
boolean statusCommand = false;
String inputString = "";
const String ledcomand[31] {"000001A","000010A","000011A",
            "000100A","000101A","000110A","000111A","001000A",
            "001001A","001010A","001011A","001100A","001101A",
            "001110A","001111A","010000A","010001A","010010A",
            "010011A","010100A","010101A","010110A","010111A",
            "011000A","011001A","011010A","011011A","011100A",
            "011101A","011110A","011111A"};
int ledState1 = LOW;
int ledState2 = LOW;
int ledState3 = LOW;
int ledState4 = LOW;
int ledState5 = LOW;
int led1 = 6;
int led2 = 7;
int led3 = 8;
int led4 = 9;
int led5 = 10;
unsigned long startTime = 0;
unsigned long curTime = 0;
long delta = 2000;
//
void toLedOn (String str){
  if (str.length()>5){
    char *chars = str.c_str();
    if(chars[1]=='1')ledState1 = HIGH;
    if(chars[2]=='1')ledState2 = HIGH;
    if(chars[3]=='1')ledState3 = HIGH;
    if(chars[4]=='1')ledState4 = HIGH;
    if(chars[5]=='1')ledState5 = HIGH;
    //digitalWrite(led0, ledState0);
    digitalWrite(led1, ledState1);
    digitalWrite(led2, ledState2);
    digitalWrite(led3, ledState3);
    digitalWrite(led4, ledState4);
    digitalWrite(led5, ledState5);  
  }
  return;
}
void toLedOff (){
  ledState1 = LOW;
  ledState2 = LOW;
  ledState3 = LOW;
  ledState4 = LOW;
  ledState5 = LOW;
  digitalWrite(led1, ledState1);
  digitalWrite(led2, ledState2);
  digitalWrite(led3, ledState3);
  digitalWrite(led4, ledState4);
  digitalWrite(led5, ledState5);    
  return;
}
boolean onCommand (String str){
  boolean ret=false;
  for(int i=0; i<31; ++i){
    if(ledcomand[i]==str){
      ret=true;
      break;
    }
  }
  return ret;
}
void sound1(int l) {
  tone(piezo_pin,600);
  delay(500);
  if (l==2){  
    tone(piezo_pin,900);
    delay(500);
  }  
  noTone(piezo_pin);
  return ;
}
//
void setup() {  
  Serial.begin(115200);
  inputString.reserve(200);
  pinMode(piezo_pin, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  sound1(1);
   
}

void loop() {
  if(statusCommand){
    statusCommand=false;
    if(command == inOtklik){    
      delay(2200);    
      Serial.print(outOtklik);
      sound1(2);      
    }else{
      if(onCommand(command)){
        toLedOn (command);
        startTime = millis();      
      }
    }
  }
  if(startTime != 0){
    curTime = millis();
    if(curTime > startTime+delta){
      startTime=0;
      toLedOff ();
    }
  }
}
void serialEvent() {
  while (Serial.available()) {    
    char inChar = (char)Serial.read();
    inputString += inChar;
    if (inChar == 'A') {
      command = inputString;
      statusCommand = true;
      inputString="";
    }
  }
}