Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 745
61  Using Arduino / Project Guidance / Re: Log FuelFlow -Reading 4 frequency inputs (digital on/off) and logging to SD card on: April 15, 2014, 08:26:14 am
The opening braces at lines 74 and 110 are spurious but harmless.

On line 131 it would be better to use the defined constants HIGH and LOW rather than literals 1 and 0.

On line 132 and throughout the remainder of this function I suggest calling micros() once (and saving the result to a local temporary variable) rather than calling it multiple times. As well as saving a tiny amount of processing time, it also avoids inaccuracies if the value changes between these calls.

All time values should be held as unsigned long, not (signed) long.

The code on line 215 seems to be in the wrong place (it is outside the if statement that tests whether the interval has passed). In general, I suggest putting the 'previous time' update as close as you can to the start of the block that executes when the interval has elapsed, so it is always visually obvious that you are updating it in the correct place. Also, I suggest that you update startTime by incrementing it by the interval rather than setting it to 'now'. This avoids timing slip that would otherwise occur if there is any latency between the interval elapsing and your code running that detects that it has elapsed. There will be a similar issue at line 230.

Since pgenPreviousMicros is only ever used inside pgen(), it doesn't need to be a global and could be defined as a static local inside pgen(). By reducing the scope of the variable you no longer need to think about other code when looking at how it may be used, and no longer need to think about this variable when understanding what the other code is doing.

The variable pgenInterval should be defined as unsigned long. Since you're using a value larger than an int in its initialisation expression, I suggest you use 1000000UL to make sure the compiler evaluates this expression using the correct type.

Values which you don't intend to change at runtime should be declared as const.

The issues above might explain why the pulse generation isn't working. If not, I suggest you post your revised code and we can see what else might be causing it.
62  Using Arduino / Project Guidance / Re: nRF24L01 TX'ing instruxns to separate nRF RX'ers on: April 15, 2014, 08:01:40 am
The nRF24L01+ transceivers use addressing to identify the recipient for each message. Just allocate a unique address to each slave, and have the master send to the address of the slave the message is destined for.
63  Using Arduino / Project Guidance / Re: Possible to use photoresistors as digital in? on: April 15, 2014, 07:59:54 am
Yes it is, but you'll need to connect the photoresistor in series with a plain resistor and the value of the plain resistor must be chosen so that the digital input switches between a HIGH and LOW state at the brightness you want it to. You might find it convenient to use a potentiometer here so that you can adjust the value. You would connect the digital input to the junction between the photoresistor and the plain resistor, and the free ends to 5V and ground.
64  Using Arduino / Project Guidance / Re: Simple Finger Switch on: April 15, 2014, 07:55:52 am
Just run the Button example sketch, substituting your two wires connected via your finger in place of the switch. I don't know how much resistance your finger will have - you may need to vary the pull-up resistor to find what works, but if you have a resistor that worked previously I suppose it's likely it will work this time too.
65  Using Arduino / Project Guidance / Re: Arduino multiple motor driver switch system on: April 15, 2014, 07:48:33 am
1. I can control 6 H-Bridges on one Uno. = 12 motors

Just to make sure you have got your sums right:

If you want to drive the motors forwards and reverse, you need one h-bridge per motor.

Some common h-bridge chips provide two h-bridges (one chip drives two motors). Usually, these chips provide separate controls for each motor so they need twice as many pins as a single h-bridge. Make sure you don't confuse the number of driver chips with the number of h-bridges.
66  Using Arduino / Project Guidance / Re: State Machine - recomendattions / opinions ? on: April 14, 2014, 07:23:17 pm
That's my view, too. For the sort of project simple enough to be implemented sensibly on an Arduino I would not usually expect the state machine design to be complicated enough to justify the cost of using a library to implement it. Similarly for managing timed actions - in typical projects the timing requirements are simple enough that there is no need for the complexity and overhead of using timing libraries to manage that. What's more appropriate IMO for this scale of problem is to offer people a sensible design pattern to achieve that behaviour, rather than giving them code.
67  Using Arduino / Project Guidance / Re: Charlieplexing on: April 14, 2014, 07:19:12 pm
Yes, he will be modulating the LEDs much faster than the video framerate. It's common to do this at hundreds of Hz, relying on persistence of vision (in the eye, and in the camera) to make each LED appear to fade.
68  Using Arduino / Programming Questions / Re: millis fonction on: April 14, 2014, 07:17:02 pm
Look at the blink without delay example sketch. If you record the value of millis() at the start of an interval, you can subtract that from the value of millis() taken later on to work out how much time has elapsed since the start of the interval.
69  Using Arduino / Programming Questions / Re: Boat autopilot - PID not centralizing rudder. on: April 14, 2014, 07:15:38 pm
I'm pretty sure you will want the integral term - it is the only way you will eliminate steady state errors. But you need to make sure the PID algorithm does not give it excessive authority and does not integrate it over too long a term.

I'm sure there are much clearer tutorials out there, but my naive approach to PID tuning is to disable everything except the proportional element and make sure that roughly the right amount of feedback is being applied at the correct sense in both directions relative to the set point. This ought to work-ish but oscillate like mad. Then gradually turn up the derivative feedback term to damp down the oscillation. Once that works, add in enough of the integral term to eliminate the steady state error.
70  Using Arduino / Programming Questions / Re: Webcam on: April 14, 2014, 07:07:30 pm
I would ... see on the screen of my PC the images sent me through the webcam has wifi.

If your PC has a connection to the WiFi network and your webcam has a WiFi interface then that seems trivial to implement and doesn't involve an Arduino at any point.
71  Using Arduino / Project Guidance / Re: SD Data Logging with High Sampling Rate on: April 14, 2014, 07:04:16 pm
There was a post in the last couple of weeks from the author of the SD library which demonstrated performing analog reads on multiple inputs and writing the results to SD at better than 1KHz. I suggest you do a search for it, because it demonstrated that what you're asking for is definitely achievable, and gave you working code to achieve it.
72  Using Arduino / Project Guidance / Re: eberspacher d5wz controller (ecu replacement) on: April 14, 2014, 07:01:31 pm
so what i need to do goes something like this:- purge air fan (xxseconds) then off, glow plug(xxseconds) then off,fuel pump (xxtimes)then off, then the fan starts slowly the fuel ignites and the fan builds up speed slowly.
so i also need to know the fuel has ignited(flame sensor signal) and if not we start again, this didn't seem so complicated in my head but now i put it in writing it seem daunting, the over heat and temp sensor would provide a input to stop the fuel, seems fantasy at this time but i would also like 3 temp settings ( fan speed and fuel pump) and a programable timer :-/
i like to jump in there its the only way to learn !!! hope you guys can give me a starting point. forgot to mention the water pump which just needs a 12v on/off

Make sure you have thought carefully through all the failure modes and are willing to deal with the consequences if this device fails in the worst conceivable way at the worst possible moment.

Setting aside the potentially very significant safety issues, the way I'd approach the software design is to divide the sequence you have outlined into a set of discrete states and implement a finite state machine to control them.

For example, the first state would be 'off', and in this state the sketch would do nothing until it detected a 'start' signal. When it gets the 'start' signal it would turn the fan on and go to the 'purging' state. In the purging state it would monitor how long it had been in that state and when that exceeded some threshold it would turn the fan off and go to the 'glow plug' state, and so on. As well as the obvious events I've outlined above I assume you would allow for this thing to be switched off at any point (which would take it through a corresponding shut down sequence) and you would also be applying sanity checks to the various sensor inputs and handle any detected fault conditions appropriately.

Robin2 posted a working example sketch a while ago which demonstrated a good way to implement a finite state machine and manage timed actions.
73  Using Arduino / Project Guidance / Re: Building a lightweight quadcopter on: April 14, 2014, 06:50:35 pm
I would not have thought that shields of any sort were the way to build your own quadcopter. They will be relatively heavy and expensive. I would have thought a better approach would be to use one of the Arduino clones designed for the purpose, which integrates the IMU onto the controller board and uses external high power motor controllers to drive the motors. Brushless motors seem to offer a much better power to weight ratio if you can afford them, in which case you'll need the corresponding controllers.

Unless you particularly want to develop a complex sensor analysis and control algorithm from scratch it would also be sensible to adopt a working autopilot that is compatible with the board you're chosen.
74  Using Arduino / Project Guidance / Re: how to drive robot straight... on: April 14, 2014, 06:46:23 pm
nope

If you want both wheels to travel the same distance then you need to use the encoders to determine how far each wheel has traveled and control the relative speeds to keep the distances equal.
75  Using Arduino / Project Guidance / Re: Charlieplexing on: April 14, 2014, 06:44:18 pm
I suspect you'll find that the pairs of diodes are connected with reverse polarity, relying on the reverse breakdown voltage being greater than the forward voltage to avoid damaging the LED which is powered in reverse. Hence half the LEDs could be controlled active low with the common rail held high, and the other half would be powered active high with the common rail being held low. By modulating each LED fast enough, persistence of vision would make it appear to be a constant brightness. I don't see any separate current-limiting resisters for the LEDs, which is odd.
Pages: 1 ... 3 4 [5] 6 7 ... 745