Hello the title might seem weird but as of now I have only one board so before getting another board I just wanted to testing if its possible and I have seen various post with working codes with two boards but as I didn’t owe two development board so I just thought of doing the same thing with just one board but it does not seems to be working its there something wrong in my code or its not possible in one board(as its not meant to be that way).
I am using UNO as my development board!! and ArduinoThread for running multiple task
#include <Thread.h>
#include <ThreadController.h>
#include <SoftwareSerial.h>
SoftwareSerial serial1(12,13); //Rx Tx 13 --> 6 on the same board
SoftwareSerial serial2(6,7); //Rx Tx 7 --> 12 on the same board
ThreadController controll = ThreadController();
Thread thread_1 = Thread();
Thread thread_2 = Thread();
// callback
void callback_1(){
Serial.println("Sending from Serial 1!!");
serial1.print('1');
}
// callback
void callback_2(){
Serial.println("Sending from Serial 2!!");
serial2.print('2');
}
void setup(){
Serial.begin(9600);
serial1.begin(9600);
serial2.begin(9600);
// Configure callback 1
thread_1.onRun(callback_1);
thread_1.setInterval(10000);
// Configure callback 2
thread_2.onRun(callback_2);
thread_2.setInterval(5000);
// Adds Threads to the controll
controll.add(&thread_2);
controll.add(&thread_1);
}
void loop(){
// run ThreadController
// this will check every thread inside ThreadController,
// if it should run. If yes, he will run it;
controll.run();
if(serial1.available()){
Serial.print("AT Serial 1:");
Serial.print(serial1.read());
Serial.println();
}
if(serial2.available()){
Serial.print("AT Serial 2:");
Serial.print(serial2.read());
Serial.println();
}
}