Arduino rc transmitter using JR style module with PPM input

Hoping someone can help out with any mistake that has been made ,

Im using James Bruton (XRobots on youtube) latest transmitter code and im having issues to where channels 7-10 are not outputting on the PPM stream ,
I tried using ChatGPT to add the 4 switch functions , but its not working

Im trying to get channel 7-10 to operate using 3 position switches and to send that out on the PPM so that the received servos would rotate as 0 deg when switch low , 180 deg when switch high , and 90 degree when switch is in midpoint

Hope this makes sense as its confusing the heck out of me lol

The code so far is as follows

// sends ten channels of PPM by bit banging.

int ch1 = 1500;       // initial values
int ch2 = 1550;
int ch3 = 1500;
int ch4 = 1500;
int ch5 = 1500;
int ch6 = 1500;
int ch7 = 1500;
int ch8 = 1500;
int ch9 = 1500;
int ch10 = 1500;

// switch input pins
const int switch1 = 2;
const int switch2 = 3;
const int switch3 = 4;
const int switch4 = 5;

void setup() {
  pinMode(9, OUTPUT);       // PPM output pin
  pinMode(switch1, INPUT);
  pinMode(switch2, INPUT);
  pinMode(switch3, INPUT);
  pinMode(switch4, INPUT);
  Serial.begin(115200);     // debug
}


void loop() {



  ch1 = analogRead(A0);          // read analog sticks
  ch1 = map(ch1, 0, 1023, 1000, 2000);
  ch2 = analogRead(A1);
  ch2 = map(ch2, 0, 1023, 1000, 2000);
  ch3 = analogRead(A2);
  ch3 = map(ch3, 0, 1023, 1000, 2000);
  ch4 = analogRead(A3);
  ch4 = map(ch4, 0, 1023, 1000, 2000);
  ch5 = analogRead(A4);
  ch5 = map(ch5, 0, 1023, 1000, 2000);
  ch6 = analogRead(A5);
  ch6 = map(ch6, 0, 1023, 1000, 2000);

  // read the switch positions
  int switchPos1 = digitalRead(switch1);
  int switchPos2 = digitalRead(switch2);
  int switchPos3 = digitalRead(switch3);
  int switchPos4 = digitalRead(switch4);

  // assign the corresponding channel values based on the switch positions
  if (switchPos1 == LOW) {
    ch7 = 1000;
  } else if (switchPos1 == HIGH) {
    ch7 = 2000;
  }else {
    ch7 = 1500;
  }  

  if (switchPos2 == LOW) {
    ch8 = 1000;
  } else if (switchPos2 == HIGH) {
    ch8 = 2000;
  }else {
    ch8 = 1500;
  }

  if (switchPos3 == LOW) {
    ch9 = 1000;
  } else if (switchPos3 == HIGH) {
    ch9 = 2000;
  }else {
    ch9 = 1500;
  }

  if (switchPos4 == LOW) {
    ch10 = 1000;
  } else if (switchPos4 == HIGH) {
    ch10 = 2000;
  }else {
    ch10 = 1500;
  }


  digitalWrite(9, HIGH);
  delayMicroseconds(500);       // pulse
  digitalWrite(9, LOW);
  delayMicroseconds(ch1 - 500); // gap for the remaining period

  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch2 - 500);

  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch3 - 500);

  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch4 - 500);

  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch5 - 500);

  digitalWrite(9, HIGH);          // ch6
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch6 - 500);

  digitalWrite(9, HIGH);          // ch7
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(1000 - 500);

  digitalWrite(9, HIGH);          // ch8
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(1100 - 500);

  digitalWrite(9, HIGH);          // ch9
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(1200 - 500);

  digitalWrite(9, HIGH);          // ch10
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(1300 - 500);


  digitalWrite(9, HIGH);          // sync pulse
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(5000);        // longer gap

}

Too much code, too few comments

so i figured out the missing channels , i didnt edit them into the PPM stream :person_facepalming: :person_facepalming:

but now the switch outputs are only acting as 2 position switches not 3 ??

// sends ten channels of PPM by bit banging.

int ch1 = 1500;       // initial values
int ch2 = 1550;
int ch3 = 1500;
int ch4 = 1500;
int ch5 = 1500;
int ch6 = 1500;
int ch7 = 1500;
int ch8 = 1500;
int ch9 = 1500;
int ch10 = 1500;

// switch input pins
const int switch1 = 2;
const int switch2 = 3;
const int switch3 = 4;
const int switch4 = 5;

void setup() {
  pinMode(9, OUTPUT);       // PPM output pin
  pinMode(switch1, INPUT);
  pinMode(switch2, INPUT);
  pinMode(switch3, INPUT);
  pinMode(switch4, INPUT);
  Serial.begin(115200);     // debug
}


void loop() {



  ch1 = analogRead(A0);          // read analog sticks
  ch1 = map(ch1, 0, 1023, 1000, 2000);
  ch2 = analogRead(A1);
  ch2 = map(ch2, 0, 1023, 1000, 2000);
  ch3 = analogRead(A2);
  ch3 = map(ch3, 0, 1023, 1000, 2000);
  ch4 = analogRead(A3);
  ch4 = map(ch4, 0, 1023, 1000, 2000);
  ch5 = analogRead(A4);
  ch5 = map(ch5, 0, 1023, 1000, 2000);
  ch6 = analogRead(A5);
  ch6 = map(ch6, 0, 1023, 1000, 2000);

  // read the switch positions
  int switchPos1 = digitalRead(switch1);
  int switchPos2 = digitalRead(switch2);
  int switchPos3 = digitalRead(switch3);
  int switchPos4 = digitalRead(switch4);

  // assign the corresponding channel values based on the switch positions
  if (switchPos1 == LOW) {
    ch7 = 1000;
  } else if (switchPos1 == HIGH) {
    ch7 = 2000;
  }else {
    ch7 = 1500;
  }  

  if (switchPos2 == LOW) {
    ch8 = 1000;
  } else if (switchPos2 == HIGH) {
    ch8 = 2000;
  }else {
    ch8 = 1500;
  }

  if (switchPos3 == LOW) {
    ch9 = 1000;
  } else if (switchPos3 == HIGH) {
    ch9 = 2000;
  }else {
    ch9 = 1500;
  }

  if (switchPos4 == LOW) {
    ch10 = 1000;
  } else if (switchPos4 == HIGH) {
    ch10 = 2000;
  }else {
    ch10 = 1500;
  }


  digitalWrite(9, HIGH);
  delayMicroseconds(500);       // pulse
  digitalWrite(9, LOW);
  delayMicroseconds(ch1 - 500); // gap for the remaining period

  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch2 - 500);

  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch3 - 500);

  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch4 - 500);

  digitalWrite(9, HIGH);
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch5 - 500);

  digitalWrite(9, HIGH);          // ch6
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch6 - 500);

  digitalWrite(9, HIGH);          // ch7
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch7 - 500);

  digitalWrite(9, HIGH);          // ch8
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch8 - 500);

  digitalWrite(9, HIGH);          // ch9
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch9 - 500);

  digitalWrite(9, HIGH);          // ch10
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(ch10 - 500);


  digitalWrite(9, HIGH);          // sync pulse
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(5000);        // longer gap

}

Please see reply 2

if you are refering to your variables "switch1" to "switch4", those are set as DIGITAL inputs ie they an ONLY have 2 possible values - HIGH or LOW!

probs easier if i start from scratch , here is the original code and i would like to add 3 position switches for channels 7-10 (if possible)

its for an rc receiver so to finish the 3 position switches would turn a servo to 0 deg at one position , 90 deg when switch is in center and 180 deg when switch is at other position

hope this makes sense and is possible

// sends ten channels of PPM by bit banging.

int ch1 = 1500;       // initial values
int ch2 = 1550;
int ch3 = 1500;
int ch4 = 1500;
int ch5 = 1500;
int ch6 = 1500;


void setup() {
  pinMode(9, OUTPUT);       // PPM output pin
  Serial.begin(115200);     // debug
}
  

void loop() {

 

  ch1 = analogRead(A0);          // read analog sticks
  ch1 = map(ch1, 0,1023,1000,2000);
  ch2 = analogRead(A1);
  ch2 = map(ch2, 0,1023,1000,2000);
  ch3 = analogRead(A2);
  ch3 = map(ch3, 0,1023,1000,2000);
  ch4 = analogRead(A3);
  ch4 = map(ch4, 0,1023,1000,2000);
  ch5 = analogRead(A4);
  ch5 = map(ch5, 0,1023,1000,2000);
  ch6 = analogRead(A5);
  ch6 = map(ch6, 0,1023,1000,2000);


  digitalWrite(9, HIGH);
  delayMicroseconds(500);       // pulse
  digitalWrite(9, LOW);
  delayMicroseconds(ch1-500);   // gap for the remaining period
  
  digitalWrite(9, HIGH);        
  delayMicroseconds(500);
  digitalWrite(9, LOW);     
  delayMicroseconds(ch2-500);   
  
  digitalWrite(9, HIGH);        
  delayMicroseconds(500); 
  digitalWrite(9, LOW);      
  delayMicroseconds(ch3-500);   

  digitalWrite(9, HIGH);
  delayMicroseconds(500);  
  digitalWrite(9, LOW);      
  delayMicroseconds(ch4-500);   

  digitalWrite(9, HIGH);        
  delayMicroseconds(500);
  digitalWrite(9, LOW);        
  delayMicroseconds(ch5-500);   

  digitalWrite(9, HIGH);          // ch6 
  delayMicroseconds(500);
  digitalWrite(9, LOW);      
  delayMicroseconds(ch6-500);

  digitalWrite(9, HIGH);          // ch7 
  delayMicroseconds(500);
  digitalWrite(9, LOW);      
  delayMicroseconds(1000-500);

  digitalWrite(9, HIGH);          // ch8 
  delayMicroseconds(500);
  digitalWrite(9, LOW);      
  delayMicroseconds(1100-500);

  digitalWrite(9, HIGH);          // ch9 
  delayMicroseconds(500);
  digitalWrite(9, LOW);      
  delayMicroseconds(1200-500);

  digitalWrite(9, HIGH);          // ch10 
  delayMicroseconds(500);
  digitalWrite(9, LOW);      
  delayMicroseconds(1300-500);


  digitalWrite(9, HIGH);          // sync pulse
  delayMicroseconds(500);
  digitalWrite(9, LOW);
  delayMicroseconds(5000);        // longer gap 

}
         


as i said this isnt my code , its code supplied by James Bruton (xrobots) on youtube

well tried this original code fully with 6 inputs on the Arduino , and 6 servos on the receiver and its not working , it links all the ppm outputs at the same time , so when any stick on transmitter is moved all of the outputs on receiver move at same time ,

So will end this here as looks like ill be looking else where for an actually working code :frowning: :frowning:

Why not write some instead?
Cut out the middle-man.

i have spent last 2 days trying to write some , but i cant get my head around it , even using ChatGPT to help ,and even used the site fiver and payed a couple different people , and still cant get anything to work

I am clueless when writing a code from scratch ( i can edit code if i understand it )

IMHO you need to use analog ready to emulate something like that. if you've run out of analog inputs, then I would suggest you consider building a circuit like this one.

GOOD LUCK!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.