Short Version: Not able to get a servo to move to mapped input from RC remote control PPM signal.
Detailed Verison: I am trying to take an input signal from a hobby RC radio (D4RII receiver ppm stream/one wire) signal and map the values 1000-2000 into 0-180 for a value that is useful for a servo. Initially, I had an issue simply reading the values stored within the array from the TinyPpmReader.h library from DigisparkArduinoIntegration on github.
For background, I am using tiny cores. This was the fist issue that was solved: Accessing Values From Array Within a Library
Second Issue solved: Mapping PPM Signals to Servo Values
Now, the last part of the battle is to get the servos the actually move. I have successfully (with help)
1.Made the single array values available to be read via serial console (Uno to ATtiny85) like this - Serial.println(TinyPpmReader.width_us(3));
2.Successfully mapped the values within the ppm array to 0-180 and validated the values are correctly mapped and printed to the serial console like this - Serial.println(mappedval0);
Couple of questions. Is it possible that since the ATtiny 85 only has Timer0 and Timer1 available that pwm wont work? ATtiny 85 datasheet here. If I understand it correctly, the tinyppmreader library does use an interupt driven process.
I chose to go with the SoftwareSerial library since I don't think it is using any timers (Not really sure). Or, is this just a simple coding issue? What is my mistake? This will compile and the servo does seem to glitch around but not move according to the mapped ppm stream.
Since my search results are now coming up with my previous questions I am hoping this will help others be able to use ppm / servos with the ATiny 85 since it is so small and perfect for many RC related projects.
CODE:
#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>
#include <SoftwareServo.h>
//#include <TinyServo.h>
int val0; // integer to store value
int mappedval0;
#define PPM_INPUT_PIN 4
SoftwareServo myservo;
const int PPM_max_value = 2000; //put the max value of PPM reading result
const int PPM_min_value = 980; //put the min value of PPM reading result
//const byte SERVOS = 1; // how many servos do you have? up to 5 on ATTiny85 and 8 on ATtiny84/2313
//const byte servoPin[SERVOS] = { 1 }; // what pins are your servos on?
// you have the option to give your servos nice names. 0 refers to the first servo pin above, 1 to the second, etc
//#define RIGHTLEGSERVO 0
void setup()
{
Serial.begin(38400);//attiny tx - rx uno does not work at 9600 baud. Set to 38400 @ attiny 1mhz and uno serial console to 38400 baud
TinyPpmReader.attach(PPM_INPUT_PIN); /* Attach TinyPpmReader to PPM_INPUT_PIN pin */
//setupServos();
myservo.attach(0);
}
void loop()
{
val0 =TinyPpmReader.width_us(3); //get PPM reading result from index 4
mappedval0= map(val0, PPM_min_value, PPM_max_value, 0, 180);
myservo.write(mappedval0);
//moveServo(RIGHTLEGSERVO, mappedval0);
//Serial.println(mappedval0);
SoftwareServo::refresh();
delay(50);
}
I have commented out the tinyservo library parts while testing the SoftwareServo library.