Jump to content

Getting to grips with programming an Arduino Uno


Recommended Posts

If you don't have to go the arduino route, just learn "real" C and use whatever micro & IDE comes to hand, cheaper and more flexible and you'll have learnt a language that employers might actually want.

TI's MSP430 launchpad is dirt cheap, ST's STM32 boards are ludicrously powerful for the money and come with enough bits attached they're almost finished projects bar the wiring. I've got a couple of tubes full of PIC's somewhere if they're of any use to you? Might have a programming board too...

Link to comment
Share on other sites

+1 for Arduino and C

Two analog inputs, a brake pedal input and an PWM output?

cruise control (as said above) edit: too slow.....

Not sure how the PWM will work though

Thought about traction control, but u'd need a bit more than PWM unless you were trying to lock a diff, but then thought that would have been a diff that you may have been trying to lock as traction control via a modulator is another animal. electric fiddle brakes would require a few more DO's too

Its always good advice to comment what you're trying to do in case you need to refer to it or back to it later .

Rob

Link to comment
Share on other sites

+1 for Arduino and C

Two analog inputs, a brake pedal input and an PWM output?

cruise control (as said above) edit: too slow.....

Not sure how the PWM will work though

Thought about traction control, but u'd need a bit more than PWM unless you were trying to lock a diff, but then thought that would have been a diff that you may have been trying to lock as traction control via a modulator is another animal. electric fiddle brakes would require a few more DO's too

Its always good advice to comment what you're trying to do in case you need to refer to it or back to it later .

Rob

i have commented at the side of each step to refresh my memory if i leave it for a while then come back. i just left this out as it gave away what the idea was haha

Link to comment
Share on other sites

.... Haha was trying for a clue....

can't visualise a stepper motor with cruise control as it needs a means to disconnect plus re-engage. Presuming it's going on something non drive by wire then maybe the rover v8 diaphragm with a vaccum pump solution may be an option for you to consider as it can be digital output control

I've seen a good pid library for the arduino which works with digital outputs and would suit a cruise control system

Rob

Link to comment
Share on other sites

How are you reading the speed? Speed is normally a pulsed signal if you use the rangerover or defender transfer box speedo module (sorry can't remember part numbers). It's also and induced via a coil and a magnet so needs conditioning to control and clean up the spike. (Vr sensor maybe)

You'll also need to consider the rpm signal so that the engine is not over rev'd (on a normal c/c system you have a set button which sets the current speed as a set point. However if you tap the brakes (simple digital input signal with debounce) or sometimes clutch as well it disables the c/c but the speed setpoint is still held so if you tap the c/c set again the vehicle will accelerate back up to the previous set speed. However you may have changed gear and not realised when you do this so an rpm limit is also added to prevent over rev'ing the engine. Not essential but should be a considered input to be monitored.

Another scenario... Cruising along with the c/c on and you see something about to happen two choices brake or accelerate. Brake is easy as it disables the c/c. But what happens if you choose to accelerate in a hurry / emergency situation how will the c/c know. The rover v8 uses a bellows under vacuum in the same direction as the throttle cable (think of it as a parallel accelerator) so if you accelerate you have basically over ridden the c/c but the c/c did not hold it off if anything the c/c will see the increased speed and deflate the bellows so when you take your foot off the acc pedal it will give the engine less air and therefore fuel and slow down back to the set speed

If you're doing this with a stepper motor you will need something like a coupling with missing teeth to provide the ease of unrestricted acceleration

Don't get me wrong not trying to dismiss an idea as we all learn from these things and providing solutions or critical appraisal

There are other things to consider too like a watchdog or a charge pump so that it makes sure nothing is corrupt or locked up

Looks like a good interesting project but I'd suggest arduino as there is a huge amount of libraries that you can pull in plus shields that could be used (although there is a huge disclaimer that they are not for automobile use... But that should not stop you prototyping and learning the language)

Rob

Link to comment
Share on other sites

The main concern with a stepper motor, if it's directly coupled to the throttle, is there is no failsafe if the motor driver fails. Stepper motors usually have a resistance to being rotated manually which, in the event of a driver failure means that the throttle return spring on it's own isn't man enough to return the throttle to closed. A driver circuit or electrical failure could easily lead to the throttle being held open, preventing you from slowing down at a time you really need to. Most stepper motors also don't have a position reference so when the system is powered up you have no idea what it's current position is which makes life hard enough when you are using one as an idle air control but near impossible to use for something like a cruise control.

A pwm type valve actuator would be far safer as, without an electrical input, it offers little or no resistance to the actuator being moved by the throttle return spring. It can also be driven without any additional logic circuits as you can drive it using your pwm signal through a suitable transistor. It would effectively use the resistance of the throttle return spring to pull against and allow the throttle to be overridden manually without any further mechanical changes. To keep costs and current down these are often "assisted" by a vacuum taken from the inlet manifold. "Borrowing" such an actuator from a commercial/manufacturers cruise control might be the safest option. Just remember, this is the bit that can kill you (literally) if your software or hardware has a meltdown.

Link to comment
Share on other sites

C is probably the most popular / widespread / universal / useful programming language so worth learning, just be aware that the arduino native development environment hides some of the real goings-on from you.

As is common with many Land Rover-related things, I think you'll find C was superseded by D and shortly after that, E. :offtopic:

  • Like 1
Link to comment
Share on other sites

Don't forget the 'brake and it cuts out' bit....

already written in :) have a look back where i said that C.4 (IIRC) is the brake light switch

How are you reading the speed? Speed is normally a pulsed signal if you use the rangerover or defender transfer box speedo module (sorry can't remember part numbers). It's also and induced via a coil and a magnet so needs conditioning to control and clean up the spike. (Vr sensor maybe)

You'll also need to consider the rpm signal so that the engine is not over rev'd (on a normal c/c system you have a set button which sets the current speed as a set point. However if you tap the brakes (simple digital input signal with debounce) or sometimes clutch as well it disables the c/c but the speed setpoint is still held so if you tap the c/c set again the vehicle will accelerate back up to the previous set speed. However you may have changed gear and not realised when you do this so an rpm limit is also added to prevent over rev'ing the engine. Not essential but should be a considered input to be monitored.

Another scenario... Cruising along with the c/c on and you see something about to happen two choices brake or accelerate. Brake is easy as it disables the c/c. But what happens if you choose to accelerate in a hurry / emergency situation how will the c/c know. The rover v8 uses a bellows under vacuum in the same direction as the throttle cable (think of it as a parallel accelerator) so if you accelerate you have basically over ridden the c/c but the c/c did not hold it off if anything the c/c will see the increased speed and deflate the bellows so when you take your foot off the acc pedal it will give the engine less air and therefore fuel and slow down back to the set speed

If you're doing this with a stepper motor you will need something like a coupling with missing teeth to provide the ease of unrestricted acceleration

Don't get me wrong not trying to dismiss an idea as we all learn from these things and providing solutions or critical appraisal

There are other things to consider too like a watchdog or a charge pump so that it makes sure nothing is corrupt or locked up

Looks like a good interesting project but I'd suggest arduino as there is a huge amount of libraries that you can pull in plus shields that could be used (although there is a huge disclaimer that they are not for automobile use... But that should not stop you prototyping and learning the language)

Rob

reading the alternator rev output so it wont be directly speed related rather rev related. will work the same way in reference to the human interface, however it can also be utilised in neutral as a hand throttle :)

the way i am imagining the interface between stepper motor and throttle, means that i will be able to accelerate past it, the motor will hopefully "push" the throttle round rather than "grab" it, therefore the throttle is free to move more, but not less.

The main concern with a stepper motor, if it's directly coupled to the throttle, is there is no failsafe if the motor driver fails. Stepper motors usually have a resistance to being rotated manually which, in the event of a driver failure means that the throttle return spring on it's own isn't man enough to return the throttle to closed. A driver circuit or electrical failure could easily lead to the throttle being held open, preventing you from slowing down at a time you really need to. Most stepper motors also don't have a position reference so when the system is powered up you have no idea what it's current position is which makes life hard enough when you are using one as an idle air control but near impossible to use for something like a cruise control.

A pwm type valve actuator would be far safer as, without an electrical input, it offers little or no resistance to the actuator being moved by the throttle return spring. It can also be driven without any additional logic circuits as you can drive it using your pwm signal through a suitable transistor. It would effectively use the resistance of the throttle return spring to pull against and allow the throttle to be overridden manually without any further mechanical changes. To keep costs and current down these are often "assisted" by a vacuum taken from the inlet manifold. "Borrowing" such an actuator from a commercial/manufacturers cruise control might be the safest option. Just remember, this is the bit that can kill you (literally) if your software or hardware has a meltdown.

i plan to closely match the stepper motor maximum torque output with the torque required to turn the pump against its return spring, (obviously with a little more omph but not overkill) hopefully with as "low" a spec as i can get away with means that the return springs will fairly easily overcome the motor once deactivated.

there will be a master "board on/off" toggle switch so if the programme itself fails in an "on" state then i can manually cut the power and it will shut down.

having read your posts, it seems like one of these PWM type valve actuators would maybe be a better option though, this is something i plan to look into last. i want to get all the inputs sorted and in a safe programme before i look at actuation at which point i will research into types of actuators and their pros and cons.

i believe the lack of position reference should be relatively irrelevant as i am going to use the alternator rev gauge signal as the engine speed input and therefore just adjust the PWM in relation to this, meaning wherever the throttle is, it will be adjusted according to RPM rather than throttle position. as if i did it to throttle position it would slow down when it meets an incline, whereas reading revs it will compensate and add more throttle.

he hopes... haha :)

please keep an eye out as you have been doing for safety implications as these are of course the most important thing in this scenario. it is however, just a project and if it doesent work safely i am more than happy to just "bin" it until i can make it work (if i can at all)

i hope so far that i have covered all the bases where it comes to safety so if you have more questions i will more than happily answer

Link to comment
Share on other sites

The simplest form of cruise control I've seen offered as a commercial kit for throttle cabled vehicles is an electromagnet..... laugh as you may, but I've come across one of the offerings.... basically enable the cruise control and it fixes the throttle linkage in that position until you disable it or touch the brake..... doesn't work very well on hills in my opinion, but hey ho they are all options that have been tried.

Yes as has been said before, all of this can go horribly wrong, (but so can some of the home mechanic tasks too) .... but that's why it's sometimes better to collaborative work / bounce ideas.

I don't know enough about the pic / basic

Suggest out of interest you have a read of the manual for the RR classic with cruise control as the cruise controller has a pinout and is easy enough to follow through it's logic (or pilfer bits), .... it can also be used stand alone ...... if you want to avoid the head scratching ....

(30 second search of google ....

http://www.landroverresource.com/docs/rangerover/Range_Rover_Classic_Manual_1995.pdf

http://macassemble.com/lrm/range_rover/Range%20Rover%20Classic%20Electrical%20Troubleshooting.pdf

If you want an intelligent stepper motor controller that requires very little programming and keeps tabs on where it is, I'd suggest have a read of the datasheets here... http://www.st.com/web/catalog/sense_power/FM142/CL851/SC1794/SS1498/LN1723/PF248592?sc=internet/analog/product/248592.jsp

Or search for L6470 dSpin .... there is a company in Ireland who make a dual L6470 sheild for the Arduino Uno http://altelectronics.co.uk/shop/arduino/arduino-stepper-motor-shield/prod_84.html

It runs on SPI [again sorry easily done on arduino via library, not sure on pic]

Is this off topic? Someone let me know and I'll b off, no offence taken & delete as you wish.

Rob

Link to comment
Share on other sites

The simplest cruise control I've heard of was done by Bob Pease using a handfull of transistors as a response to some vastly overblown "fuzzy logic" marketing bull someone sent him. The hard part about cruise control (or any closed loop system) is getting the PID loop tuned correctly to prevent potentially hilarious malfunctions. There's a fair overview of the issues in this article. How you physically move the actuators to control the system is kinda secondary, plenty of cars have stepper actuated throttles these days, from my other half's Ibiza to the mighty LS1, you'd hope they were confident enough of the safety/reliability...

Link to comment
Share on other sites

BTW, LR tend to actuate things using small PWM vacuum solenoids - look at the EGR valve on TD5 & TD4, turbo actuator on TD4, and various others. Using a small valve to move a larger actuator means you don't have to drive large currents into a big coil or stepper. Vacuum is readily available & gives a good amount of force.

Link to comment
Share on other sites

Yes I can concur that there is no general issue in using a stepper motor in any application, but with a stepper in this potential application (non-drive by wire throttle with a parrallel throttle cable and a stepper motor it probably needs a little more consideration of the fail safe aspect.

A spring acting as a throttle linkage return spring of sufficient torsional force to close a throttle + return a stepper motor to home is one way to do it.

Yup, my LS7 has a drive by wire throttle which I intend to fully utilise again (no way I would go back to a cable with a GMPP ECU!), but it also has a fail safe close should the power fail and the throttle has two potentiometers which act in tandem to confirm the throttle signal. I also intend to use a cruise control with it through the use of two digital to analogue converter chips and a microprocessor, and PID loop with various road speed signals and brake pedal and clutch pedal disengagement. In essence copying the potentiometers in their "cruise" position.

There is an off the shelf system available for the LS from Spanky's Rod Shop .... cost is a little vague ... but I thought once I got my bad of bits together its something on the wish list long term http://spankysrodshop.net/index.php?option=com_content&view=article&id=35:cruise-control&catid=16:engine-accessories&Itemid=7 and have a go at copying / integrating in principle.

Link to comment
Share on other sites

There is a difference in implementation between a cruise control/throttle control controlled by the engine ECU (fly by wire) and an external cruise control that is not linked to the engine ECU. An engine ECU using fly by wire and a stepper motor has the ability to monitor throttle input vs rpm vs target rpm. It can use these to detect a runaway situation and use other means to close down the engine (spark cut for a petrol engine or fuel cut for a diesel).

With an external cruise control, not controlled by the engine ECU, the only failsafe is via a mechanical throttle return spring. You could mitigate this by adding a throttle position sensor allowing the external cruise control to detect a problem and perhaps kill the ignition or similar via a relay. Worth considering during the planning stages I guess...

Link to comment
Share on other sites

Very few of the failure modes are safe in this. You need some "hard" way of killing/disengaging it such that it cannot override the driver if the software locks up.

Even being stuck at zero throttle is quite nasty in the wrong place, as my other half found out: faulty brake light switch means ECU thinks brakes are on = won't allow any throttle, very inconvenient when the switch goes faulty as you're coming down a slip-road to join fast-moving traffic :blink:

Link to comment
Share on other sites

as mentioned above nige, i do plan to have a hard "on/off" switch to the power feed, such as any car with cruise has the "cruise on/off" button/switch which then enables the rest of the functions etc.

i believe killing the board and therefore the throttle feed will give it some degree of failsafe.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We use cookies to ensure you get the best experience. By using our website you agree to our Cookie Policy