So I want to send the signal coming from Flight Controller (FC) through Arduino UNO to ESC of my BLDC motor, I want to do this because I want to manipulate the signal if I receive a Boolean signal to Arduino from my transmitter**(Tx)**... So it's like when Tx giving OFF signal(mode) then I want to redirect the FC signal to my ESC and if Tx giving ON signal(mode) then I want to send my own signal(coded) to the ESC and control it.
I know I can use pluseIn() and read the FC signal then translate back to PWM pin for ESC and if Tx ON (mode) I can use normal Servo.h library and give my own signal. So is there any direct way to do it only using Arduino UNO ?? Like directly sending PWM signal from one pin to another pin??
Yes, but is there any way to directly send the PWM signal from one pin to another pin, because in one case I have to do that. So it don't take any computation power and delay as my method will take (using pulseIn() and converting back to PWM).
If you want to just pass on a signal without delay and/or computation power of your Uno I think you will need an separate component for that.
By using a 74HC157 (4ch multiplexer IC), I built a 4 channel buddybox. To be able to give flying lessons with a model airplane.
An Attiny reads a servo signal (I use ch5 from teacher receiver) and based on that servo signal it will set an out put pin HIGH or LOW. That output pin is connected to the select pin of the 74HC157. The 74HC157 then switches or the ch1-4h from the student receiver to the servo's or the ch1-4 from the teacher's receiver to the servo's.
In your case you would only connect 1 channel and leave the other 3 unconnected.
Thank you for the solution but I don't want to make things complicated and heavy by adding an other electronics.. and I got limited space in my robot I'm also using 3V-5V 8CH level converter as I'll use ESP32 and it'll need that to send the signals... I'm just using UNO for practice until my electronics are shipped.
And I have to manipulate the signal once Tx sends ON mode so I don't know we can do it with that and how.
one doubt for test purpose I'm shorting pin 10 and 9 to pass the data from pin 10 to 9 and then read it like I'm reading pin 11 (PWM_DATA).
And it's not working!!
#define RxDATA 11 // It's PWM_DATA
#define DATAOUT 10 // It's PWM_DATAOUT
#define DATAIN 9 // And here I have connected pin 10 and pin 9 with jumper wire (Short)
void setup(){
Serial.begin(9600);
pinMode(RxDATA, INPUT);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
}
void loop(){
int pwm_data = pulseIn(RxDATA, HIGH, 30000); // To read the data for myself
Serial.print("Rx Data '11': ");
Serial.print(pwm_data);
digitalWrite(DATAOUT, digitalRead(RxDATA)); // Sending pin 11 PWM to pin 10
int tx_data = pulseIn(DATAIN, HIGH, 30000); // Reading the shorted pin 10 and 9 PWM signal
Serial.print(" Data from '10'='9': ");
Serial.println(tx_data);
delay(1000); // For reading purpose (myself)
}
Serial Monitor Rx Data '11': 1474 Data from '10'='9': 0
Rx Data '11': 1986 Data from '10'='9': 0
Rx Data '11': 992 Data from '10'='9': 0
Rx Data '11': 1479 Data from '10'='9': 0
See there is two modes, first mode I have to redirect the signal from FC to ESC (in this direct connection is valid) but in second mode I don't want FC signal to be transmitted to the ESC, I want to manipulate it with my own signal (code) (which I'll do using Servo.h). Please read my post (topic) one more time then it'll be more clear I think.
Bro I tried to connect the servo with Pin10 (which is digitalWrite(DATAOUT, digitalRead(RxDATA))) and it's getting PWM signal from 11 and Servo is not working but when I'm connecting directly Pin11 input to Servo, it is working. So there must be another way of directly sending PWM signal from one Pin to another Pin. digitalRead() and digitalWrite() is not working.
This is not showing any change (removing Or changing delay(1000)) but...
/// digitalWrite(DATAOUT, digitalRead(RxDATA)); // Previous one (Not working)
analogWrite(DATAOUT, analogRead(RxDATA)); // this is working
int readData = analogRead(RxDATA); // To read the real data before sending to DATAOUT
Serial.println(readData);
analogWrite is working but!!
Serial Ouput: Rx Data '11': 1492 Data from '10'='9': 1323 411 Rx Data '11': 1498 Data from '10'='9': 1331 330 Rx Data '11': 1493 Data from '10'='9': 587 328
They are not same... I think because Analog data goes from 0-255 there must be some correlation.
Thank you for your time and help really appreciated @DaveX
Yeah, no you don't use analogWrite(). You are using pulseIn(RxData) to receive signals, use DATAOUT.writeMicroseconds(pwm_data); where pwm_data is the raw signal you want to send back out to whatever without any Arduino data manipulation.
The way you describe your needs is a little vague to me. Are you sure you want to
?
Typically, the TX/RX is king. Flight controllers basically do what Arduinos do; that is, they take raw signals from the RX, do something with them based on external sensor data such as GPS coordinates, compass, Lidar readings, to name a few common ones, and trim the RX signal coming INTO the flight controller to send OUT to the ESCs.
An Arduino is like a second flight controller. It sounds to me like you want to wedge in between the RX and the flight controller and use the Arduino to allow the flight controller to trim the signals, or flick a switch and bypass the flight controller altogether, passing control back to straight TX sticks, is that right?
See above (there is): pulseIn() and writeMicroseconds(). Look up the datasheet for your particular ESCs/servos to find their useable range.
If they are servos, pay particular attention not to over drive them past their published endpoints (where typical ranges are often but not necessarily 1000-2000µs, with 1500µs as the mid point, often corresponding to 90 degrees in a typical servo).
Also,
this timeout seems long. Did the datasheet for your servo/ESC (what make and model?) tell you the signal frequency was 33Hz? the default is I think 20000. It shouldn't matter, I'm just wondering where you got that timeout value.
Never thought of it till I saw your code, but I am going to try this to see if it can be used to invert a SBUS serial signal, before it is read by the UART. Currently I build a transistor inverter to do so, but if this adds hardly any overhead it's simpler.
Just swap the if and else in your code, write it directly to the RX pin (if it is possible to set it to output again) and done.
Thanks a lot @hallowed31 it worked!! though it was not the direct way that I wanted and I still have to convert the PWM data from pin11 with pulseIn() and use Servo.h library as direct DATAOUT was giving Compilation error: request for member 'writeMicroseconds' in '10', which is of non-class type 'int' where 10 is Pin on which DATAOUT is connected,
#include <Servo.h>
Servo DATAOUTservo;
#define RxDATA 11
// #define DATAOUT 10
void setup(){
Serial.begin(9600);
pinMode(RxDATA, INPUT);
// pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
DATAOUTservo.attach(10); // #define DATAOUT 10
}
void loop(){
int pwm_data = pulseIn(RxDATA, HIGH, 30000);
Serial.print("Rx Data '11': ");
Serial.print(pwm_data);
// DATAOUT.writeMicroseconds(pwm_data); // Compilation error: request for member 'writeMicroseconds' in '10', which is of non-class type 'int'
DATAOUTservo.writeMicroseconds(pwm_data); // This taking the converter PWM signal from pin11 using 'pulseIn()' and writing to pin10
int tx_data = pulseIn(DATAIN, HIGH, 30000); // Reading the shorted pin 10 and 9 PWM signal
Serial.print(" Data from '10'='9': ");
Serial.println(tx_data);
delay(500); // For reading purpose (myself)
Serial Monitor:
Rx Data '11': 1985 Data from '10'='9': 1945
Rx Data '11': 1985 Data from '10'='9': 1945
Rx Data '11': 1471 Data from '10'='9': 1437
Rx Data '11': 1481 Data from '10'='9': 1455
There is slight difference from actual data (Raw data RxDATA) and Pin9 data (Which is sorted with pin 10 to compare it's data for test purpose).
And I guess it will use some unnecessary computational power and delay.
Kind of right but in here I don't want to
I want to connect FC => Microcontroller(Arduino UNO) => ESC, see FC calculates very well for Arial manoeuvres using its sensors (as you said compass, accelerometer and all) but in second mode I don't want to use all these sensors and computation of FC to control my ESC (BLDC), I simply want to give my own signal to control ESC(BLDC). But in First mode I directly want to send the signals which is calculated by FC to ESC.
But ya one channel(Wire) from Tx-Rx will be connected to UNO to let it know about First and Second mode.
Yes, it's all the same and same with ESC and Servos (1000-2000µs, with 1500µs as the mid point, often corresponding to 90 degrees in a typical servo).
To be honest I don't know the reason of that, I found this function from GitHub, though I'll try other values.
I have tested Rx Channels and FC output for ESC gives same PWM signals, but FC gives calculated signal using sensors(Like what signal to give according to the situation.