1

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.

  • Does your Tiny have a crystal? That would provider beter timing, but i'm not sure if that is the real problem here. It may indeed be re-using some of the hardware peripherals. And why not use an Atmega328P? – Paul Jan 13 '17 at 7:19
  • 1
    Have you tried contrilling a servo withouth all the other parts of the code? Basically running the servo libraries examples and doing some sweeps. And do you know if you're using a 1mhz (using prescaler) internal clock or 8mhz? – Paul Jan 13 '17 at 7:21
  • As Paul suggested in 2nd comment, see if you can get the servos to sweep back and forth. ¶ If you get them to work with numbers in range 0 to 180, next try out your numbers 1000 to 2000 as the argument to myservo.write. Look at the code for servo::write and you will see that parameter values above 544 are treated as microseconds and used without translation. – James Waldby - jwpat7 Jan 13 '17 at 7:33
  • Yes, I used a 10k pot to test before moving to the ppm stream. jwpat, why would I need to try 1000-2000 if the values should be 0-180 for the servo? – Brad Jan 13 '17 at 13:08
  • Another little detail about the behavior is that the servo twitches in sync with the delay(50) variable. – Brad Jan 13 '17 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.