I tried to attach the 4 servo in this code, but it does not work, please help me.
Best Regards!
/*This program puts the servo values into an array,
reagrdless of channel number, polarity, ppm frame length, etc...
You can even change these while scanning!*/
#define PPM_Pin 3 //this must be 2 or 3
#define multiplier (F_CPU/8000000) //leave this alone
int ppm[16]; //array for storing up to 16 servo signals
byte servo[] = {1,4,5,6,7,8,9,10}; //pin number of servo output
#define servoOut //comment this if you don't want servo output
//#define DEBUG
void setup()
{
Serial.begin(115200);
Serial.println("ready");
#if defined(servoOut)
for(byte i=0; sizeof(servo)-1; i++) pinMode(servo[i], OUTPUT);
#endif
pinMode(PPM_Pin, INPUT);
attachInterrupt(PPM_Pin - 2, read_ppm, CHANGE);
TCCR1A = 0; //reset timer1
TCCR1B = 0;
TCCR1B |= (1 << CS11); //set timer1 to increment every 0,5 us
}
void loop()
{
//You can delete everithing inside loop() and put your own code here
/* int count;
while(ppm[count] != 0){ //print out the servo values
Serial.print(ppm[count]);
Serial.print(" ");
count++;
}
Serial.println("");*/
delay(100); //you can even use delays!!!
}
void read_ppm(){ //leave this alone
static unsigned int pulse;
static unsigned long counter;
static byte channel;
static unsigned long last_micros;
counter = TCNT1;
TCNT1 = 0;
if(counter < 710*multiplier){ //must be a pulse if less than 710us
pulse = counter;
#if defined(servoOut)
if(sizeof(servo) > channel) digitalWrite(servo[channel], HIGH);
if(sizeof(servo) >= channel && channel != 0) digitalWrite(servo[channel-1], LOW);
#endif
}
else if(counter > 1910*multiplier){ //sync pulses over 1910us
channel = 0;
#if defined(DEBUG)
Serial.print("PPM Frame Len: ");
Serial.println(micros() - last_micros);
last_micros = micros();
#endif
}
else{ //servo values between 710us and 2420us will end up here
ppm[channel] = (counter + pulse)/multiplier;
#if defined(DEBUG)
Serial.print(ppm[channel]);
Serial.print(" ");
#endif
channel++;
}
}
Code that writes directly to the Atmel 328 registers is not normally associated with beginners.
I tried to attach the 4 servo in this code,
Why not use the regular Servo library?
but it does not work
Those words provide no useful information from which to help you. You need to tell us what the program actually does and what you want it to do that is different.
thank you very much for the quick answer.
the code is not written by me
"Why not use the regular Servo library?" - because I do not know how, i tried using servo library, I want this code to work, no matter how, please help me.
Rule number one when learning to program: don't use code you don't understand.
That leaves you with two options:
Do some research and try to understand what the code does and how it works.
Look for easier code that you can understand. E.g. using the Servo library.
roro42:
"Why not use the regular Servo library?" - because I do not know how, i tried using servo library, I want this code to work, no matter how, please help me.
There are countless examples online on how to use the Servo library. Do some more research first.
If you still don't understand it, that's fine. Then you can come back here to ask questions. But keep in mind that questions like "it does not work, please help me", or "I do not know how" are completely meaningless. Tell us what you are struggling with, what you do understand, and what you have tried to fix the problems you're facing.
PieterP:
There are countless examples online on how to use the Servo library. Do some more research first.
If you still don't understand it, that's fine. Then you can come back here to ask questions. But keep in mind that questions like "it does not work, please help me", or "I do not know how" are completely meaningless. Tell us what you are struggling with, what you do understand, and what you have tried to fix the problems you're facing.
roro42:
I'm not lazy, just stupid, right now I'm trying....
The Knob and Sweep examples in the IDE both move a single servo using the Servo library. Try those.
When you've got them working make an attempt at your 4 servo program. If it doesn't work for you post your attempt here and tell us in detail what is is doing and what you want it to do that's different.
I have seen many codes with pot and servo, these are simple....works, this is more complicated,must be printed value on the array
I do not understand why nobody wants to help me, to show me example for 1 servo (in this code)
roro42:
I do not understand why nobody wants to help me, to show me example for 1 servo (in this code)
Because nobody can read your mind to see what you want to do.
We don't have a clue what's wrong with the standard Servo examples.
On top of that, you seem to have put zero effort into trying to understand the examples yourself, and you haven't done any debugging. Like myself and many others have stated before: just saying "help, it doesn't work" is completely useless.
Imagine calling a mechanic and asking "there's a problem with my car, how can I fix it". How on Earth is he supposed to know where the problem lies?
roro42:
I have seen many codes with pot and servo, these are simple....works, this is more complicated,must be printed value on the array
I do not understand why nobody wants to help me, to show me example for 1 servo (in this code)
Start with one of the working examples and try extending it in small steps testing after each change. If you get stuck, then post your code and explain why you are stuck.
When you are a beginner and lack experience, that is the most reliable (and quickest) way to achieve your goal.
the examples I have seen they are different how to control a servo at 90 dgr, 180 dgr, or with potentiometer, not with array().....I just want to print out signal on pins 1,4,5,6 to control 4 servo, believe me I tried a week
, it's too complicated for me,I admit to be stupid, If I knew, did not ask here.
If anyone wants to help me, I pay him, via paypal contact cristian275cristian@gmail.com
OK, then just stop. If you're just going to lay down like that then this is over your head. If you want to pay someone to do it then you will have to lay out the specifications. You'll have to be a LOT more exacting than you have shown the proclivity for so far. I doubt you can even get someone to help you for pay unless you can figure out how to communicate what exactly it is that you are trying to do.
I want to build a ppm encoder(i have the code for ppm encoder and it works perfectly )- decoder(the code posted here is a ppm decoder).
i want to decode the signals from the encoder and print out signal for servo.
as far as I know, to the code posted,the servo must be attached using servo library.