Running Multiple Servos With Timer/Counters - arduino

I am currently working with a project for school in which I am building a small cart that will scan an area for the most intense source of light and drive towards it. I have programmed an SG90 180 degree servo to scan a 180 degree area, use the info I scanned to create a decision and then turn the cart and drive towards the light. The issue I have run into is that I am using the TIMER/COUNTER1 to create a PWM wave to drive the motors. My issue extends from the fact that I am using FS90R servos to drive the cart which also run on a PWM wave. My timer counter is already running the 180 degree servo and when I go to drive the continuous servos the SG90 turns and while I am scanning one of my wheels turns. This obviously is not how the cart should run. Does anyone have a way to possibly create an interrupt driven PWM wave that does not directly employ the use of the PWM capabilities of the TIMER/COUNTER1 so that I can control all 3 of the servos separately?

There are 6 PWM outputs on the Arduino, two from each timer. If you are using existing libraries to drive the outputs to the servos the libraries might assume the use of timer 1. You would have to dive into the library code to modify the libraries.
Arduino PWM Information
Ensure that you have each servo on a separate PWM output.

Related

Best way to drive high-output leds

In one project I need to drive high-output leds with a microcontroller. I am a beginner in electronics so I would need advice on how to do it...
There are 10 groups of 3 high-output leds. In each group the leds behave the same.
The microcontroller must be able to control for each group of leds :
the switching frequency (on/off)
the brightness with PWM
So it is like two imbricated PWM : one drive the power frequency, and the other the brightness of the leds.
How can I do that ? I have read about LED driver but I have never used them and I do not know what the best solution would be in such a configuration.
If you are familiar with this situation I am all ears. :)
Thanks

Is it possible to connect many (20+) SPI sensors to an Arduino Mega?

I am making a system for measuring whether or not there is vacuum present in big steel containers. They are located up to 100 meters from the control cabinet.
The question is, how many SPI sensors can I successfully use at the same time with an Arduino Mega?
I have two main concerns, and there are probably more things I didn't think about.
Signal strength
The shared lines for CLK, MOSI and MISO will need to be split up at several junction boxes and led to the different sensors. Since the voltage out from the Arduino is fixed, I'm fearing instability because the signal is weaker for some sensors, has someone done something similar? What is the greatest acceptable voltage loss for these lines to an ordinary sensor?
Processing
Will the SPI library be fine coping with this many sensors?
The refresh rate can be set to extremely low, thinking 0.3Hz.
The alternative to all this is to go for 4-20mA sensors and have a 0-5V converter circuit for each sensor, near the controller.
Any inputs would be greatly appreciated!

How to stop an Arduino Servo from moving during the myservo.attach() command

I'm using the default Servo library in Arduino. When my Arduino Uno starts up and it attaches the servo the motor will move a good portion of its range. I can't have this happen for my project, I need it to turn and stay in its current position.
Also I have seen this post but if I am reading it correctly its for a different library.
Why the problem occurs?
RC servos set their position accordingly to width of a pulses sent to them. Usually this width changes in range of ~500 - 2500us, with a frequency of 50Hz. When a servo receives such a signal, it goes to a corresponding position. For example - if it receives pulses 1500us wide, it would go to middle position. When you invoke servo.attach(), Arduino will start sensing pulses of DEFAULT_PULSE_WIDTH which happens to be 1500us.
What can be done about that?
The solution from the linked question applies also to standard Arduino servo library. Find DEFAULT_PULSE_WIDTH and change it's value to 0. If there are no pulses, the servo won't turn. Arduino will start sending signal after first servo.write() call. Remember, that there will be no holding torque until that time.
Possible cause
When your Arduino Uno starts up two things are going on at the same time
Arduino Uno runs it's bootloader and servo pin is in input mode
Servo gets power and moves a bit while getting no signal
After bootloader finished your, program starts and call to attach is perfomred.
I could reproduce the effect with my Arduino starter kid and its includes cheap servo.

How to control a stepper motor using Infrared IR Receiver?

Hi im new to Arduino Uno
My question is how to turn a stepper motor 90 dgree clockwise only when the infrared censored a something and turn anti-clockwise when the second infrared censored something is pressed again?
Stepper motor
Infrared transmitter/receiver pair
your help will be much appreciated
Thanks
Software and hardware my friend, software and hardware.
First, you'll need to connect your sensors to the Arduino and make sure you can read them reliably. You can write a sketch that outputs the values to the serial port and monitor them on your computer.
Second, you'll need to connect your motor. A stepper motor is going to need a driver, such as the "Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit" (link). This kit has sample code you can use to figure out how to drive the motor.
Then you'd connect these two independent pieces together. Write logic that puts the motor in one position when your sensor is sensing, and another when it's not, or use your second sensor to make the second motion.
Note: Stepper motors and the drivers are expensive and maybe not what you really want. For one thing, they use relative motion, not absolute position. If they miss steps (due to hitting something or being manually moved) then they remain in the wrong position until you fix them.
A cheaper and perhaps better solution is to use a hobby servo. They are cheap and use absolute positioning, which means that when you tell them to go somewhere they will always try to get to that position. Also, you can drive them directly from the Arduino without a driver board. One of the built-in Arduino sketches shows how to run them.

PIC or ARDUINO for servo motor controling

Im a PIC fan. I have not used arduino. but I have got a problems when Im going to control servos with pic.
1) when PIc is controlling the servo it cannot do enything else. so during that period it cannot get the sensor readings.
2) after driving the servo to a certain position and now when the pic is doing something else, the pic does not further more generate the pwm signal in the servo connected pin. so the servo may rotate back due to the load.
now my first question is will arduino genarate the pulse continously in the attached pin after the codes
servo s;
s.attach(13);
s.write(120);
or are there eny librarys to control multi servos using PIC in mikroc to avoid the above mentioned problems.
or is it better to use two PICs one to drive servos only and the other for processing and sensor reading, and connect them using I2C.
please I need help from an expert. please reply. thank you...
Yes the Arduino is able to generate the pwm continuously.
Arduino langage is C/C++ with some build in features like analogWrite()for pwm, which make it really easy to program.
Regarding your "when something is running, it can't do anything else" problem, that's one of the major limitation of the Arduino platform as is. You can overcome those limitations by using ISR (Interrupt Service Routine), timers and hardware interrupts.
If you're comfortable with C/C++, you can also use a Real Time Operating System (RTOS) which lets you run think like a regular operating system would: allow cpu time to each task so fast that they seem to run in parallel. But that's not as easy to use as the basic Arduino features, so think carefully if you really need those functions (scheduler, "multi-task", round rubin, etc.)
Hope it helps!
I am planning a similar project, using a PIC16F872, to control a servo motor. I am thinking of using a 32 kHz crystal to have a PWM suitable, of 35Hz and pulse width centred on 1.05 mS. In my case I will first be doing A/D measurements; then when required running the motor. The motor will have a continuous signal until a 'stop' switch gives an interrupt to the PIC.
I should mention that I have modified the servo for continuous running by disconnecting the feedback pot.

Resources