Show Posts
Pages: 1 ... 101 102 [103] 104 105 ... 114
1531  Using Arduino / Sensors / Re: Suggestions on IR communication on: March 02, 2012, 03:54:58 am

As the previous poster has suggested, then detector you are using requires a 38khz signal. there are libraries that will generate this signal, but they are generally intended for sending infra red remote codes for home entertainment systems such as tvs etc. These libraries will not give you a signal for proportional control of a servo.

One quick experiment to try it to use a 555 timer to generate the 38khz signal for the ir emitter and then use the servo library to drive an arduino pin connected to the reset pin of the 555.

This will generate the correct frequency for your detector, but pulsed in the correct way to provide proportional control of a servo.

The 555 and 556 timer chips are great little devices that can be used for all sorts of projects, so if nothing else you will increase your options for future projects by experimenting with the 555 and 556

EDIT: Alternatively you can search for code examples for generating a 38Khz signal directly from an Ardiuno PIN, there are lots. If you find one that does not use timer 1, you can use an AND gate to combine an Arduino generate servo signal with the Arduino generated 38Khz IR signal to get a proportional 38Khz Servo signal out of the AND gate. I will have a go at putting together an example this evening.

Duane B

1532  Using Arduino / General Electronics / Re: Dont Waste Your Time on: March 01, 2012, 11:22:52 pm

Mine are labelled 'altronix, made in japan'

They are the only ones available here and are generally pretty bad.

Duane B

1533  Using Arduino / General Electronics / Dont Waste Your Time on: March 01, 2012, 02:35:06 pm
   I have just wasted another hour trouble shooting a working circuit that I have moved from breadboard to strip board, yet again the problem was a very small join between the copper tracks.

   How hard can it be to make strip board !

   Morale of the story, it takes less than a minute to check continuity track to track, but more than 30 to find a short after building.

   Duane B
1534  Using Arduino / Project Guidance / Re: Slotcar speed controller with display and electronic memory project on: March 01, 2012, 02:26:36 pm
   I know the 'meat board' now, I have seen it used as a source of tough plastic before, in the UK we call them 'cutting boards'.

   You seem to be taking a big bite with your first attempt ! If the code you have cut and paste is the code you plan to use, there are a number of errors in it that I can see.

   I would suggest breaking the project down into smaller steps, for example, on my programmable RC Controllers, there are either a set of 5 potentiometers or a menu system with up/down/set/cancel buttons and an LCD Display. A first step would be reading these values, storing them in program memory and using them to adjust the car performance. This is basically your proof of concept, once this works, then worry about storing values for later recall etc.

As a very first step, pick one value, throttle curve would see an obvious one and work on reading this and using it as an output. Then add a menu system and one more control until you have them all.

Just out of interest, what are you using Servos for ?

Duane B.

1535  Using Arduino / Programming Questions / Re: Dynamic Array? on: March 01, 2012, 07:07:57 am
   Us bit flags instead, a single 8 bit byte gives you 8 on/off bit flags, a single 16 bit int gives you sixteen and a long gives you 32. Pick whichever fits your purpose, it works like this

#define SOUND_FLAG 1
#define COLOUR_FLAG 2
#define VIDEO_FLAG 4
#define STEREO_FLAG 8
// etc etc 16,32,64,128, notice that we double the value each time, this ensure each flag uses the next bit in our byte, int or long

byte bFlags;

to set a flag use

bFlags |= VIDEO_FLAG;

to clear a flag use

bFlags &= (!VIDEO_FLAG);

to test a flag use

if(bFlags & VIDEO_FLAG) // the video flag is set

This approach is 8 times more efficient that your current approach without even taking account of the extra code that would be used to manage your dynamic array.

Search for C bit wise operators for more information on this approach

Duane B
1536  Using Arduino / Sensors / Re: IRremote library on: February 29, 2012, 12:55:56 pm
   Without any information on what the error is, no noone can help you, however with a little information like the actual error cut and paste from the compiler, the people around here are generally very helpful.

Over to you...

Duane B
1537  Using Arduino / Audio / Re: Auduino v5 on uno only pot 4 works on: February 29, 2012, 12:52:42 pm
   I can't spare the time or hardware to test this tonight, but I have attached code updated with the volatile keyword.

This may not fix the issue, but it is a reasonable possibility that newer versions of the compiler would optimize the variables to fixed values such that changes to the values in loop would not be picked up in the interrupt routine. The volatile keyword should tell the compiler not to try to optimize the variables inside the interrupt routine even though it can't see anything that would alter their values.

If anyone can test this with a UNO and Arduino 1.0 I would be grateful, if it works I will have another look through and see which of the variables can be left and which should volatile.

// Auduino, the Lo-Fi granular synthesiser
// by Peter Knight,
// Help:
// More help:
// Analog in 0: Grain 1 pitch
// Analog in 1: Grain 2 decay
// Analog in 2: Grain 1 decay
// Analog in 3: Grain 2 pitch
// Analog in 4: Grain repetition frequency
// Digital 3: Audio out (Digital 11 on ATmega8)
// Changelog:
// 19 Nov 2008: Added support for ATmega8 boards
// 21 Mar 2009: Added support for ATmega328 boards
// 7 Apr 2009: Fixed interrupt vector for ATmega328 boards
// 8 Apr 2009: Added support for ATmega1280 boards (Arduino Mega)

#include <avr/io.h>
#include <avr/interrupt.h>

volatile uint16_t syncPhaseAcc;
volatile uint16_t syncPhaseInc;
volatile uint16_t grainPhaseAcc;
volatile uint16_t grainPhaseInc;
volatile uint16_t grainAmp;
volatile uint8_t grainDecay;
volatile uint16_t grain2PhaseAcc;
volatile uint16_t grain2PhaseInc;
volatile uint16_t grain2Amp;
volatile uint8_t grain2Decay;

// Map Analogue channels
#define SYNC_CONTROL         (4)
#define GRAIN_FREQ_CONTROL   (0)
#define GRAIN2_FREQ_CONTROL  (3)

// Changing these will also requires rewriting audioOn()

#if defined(__AVR_ATmega8__)
// On old ATmega8 boards.
//    Output is on pin 11
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       5
#define PWM_PIN       11
#define PWM_VALUE     OCR2
#elif defined(__AVR_ATmega1280__)
// On the Arduino Mega
//    Output is on pin 3
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       7
#define PWM_PIN       3
#define PWM_VALUE     OCR3C
// For modern ATmega168 and ATmega328 boards
//    Output is on pin 3
#define PWM_PIN       3
#define PWM_VALUE     OCR2B
#define LED_PIN       13
#define LED_PORT      PORTB
#define LED_BIT       5

// Smooth logarithmic mapping
uint16_t antilogTable[] = {
uint16_t mapPhaseInc(uint16_t input) {
  return (antilogTable[input & 0x3f]) >> (input >> 6);

// Stepped chromatic mapping
uint16_t midiTable[] = {
uint16_t mapMidi(uint16_t input) {
  return (midiTable[(1023-input) >> 3]);

// Stepped Pentatonic mapping
uint16_t pentatonicTable[54] = {

uint16_t mapPentatonic(uint16_t input) {
  uint8_t value = (1023-input) / (1024/53);
  return (pentatonicTable[value]);

void audioOn() {
#if defined(__AVR_ATmega8__)
  // ATmega8 has different registers
  TCCR2 = _BV(WGM20) | _BV(COM21) | _BV(CS20);
#elif defined(__AVR_ATmega1280__)
  TCCR3A = _BV(COM3C1) | _BV(WGM30);
  TCCR3B = _BV(CS30);
  TIMSK3 = _BV(TOIE3);
  // Set up PWM to 31.25kHz, phase accurate
  TCCR2A = _BV(COM2B1) | _BV(WGM20);
  TCCR2B = _BV(CS20);
  TIMSK2 = _BV(TOIE2);

void setup() {

void loop() {
  // The loop is pretty simple - it just updates the parameters for the oscillators.
  // Avoid using any functions that make extensive use of interrupts, or turn interrupts off.
  // They will cause clicks and poops in the audio.
  // Smooth frequency mapping
  //syncPhaseInc = mapPhaseInc(analogRead(SYNC_CONTROL)) / 4;
  // Stepped mapping to MIDI notes: C, Db, D, Eb, E, F...
  //syncPhaseInc = mapMidi(analogRead(SYNC_CONTROL));
  // Stepped pentatonic mapping: D, E, G, A, B
  syncPhaseInc = mapPentatonic(analogRead(SYNC_CONTROL));

  grainPhaseInc  = mapPhaseInc(analogRead(GRAIN_FREQ_CONTROL)) / 2;
  grainDecay     = analogRead(GRAIN_DECAY_CONTROL) / 8;
  grain2PhaseInc = mapPhaseInc(analogRead(GRAIN2_FREQ_CONTROL)) / 2;
  grain2Decay    = analogRead(GRAIN2_DECAY_CONTROL) / 4;

  uint8_t value;
  uint16_t output;

  syncPhaseAcc += syncPhaseInc;
  if (syncPhaseAcc < syncPhaseInc) {
    // Time to start the next grain
    grainPhaseAcc = 0;
    grainAmp = 0x7fff;
    grain2PhaseAcc = 0;
    grain2Amp = 0x7fff;
    LED_PORT ^= 1 << LED_BIT; // Faster than using digitalWrite
  // Increment the phase of the grain oscillators
  grainPhaseAcc += grainPhaseInc;
  grain2PhaseAcc += grain2PhaseInc;

  // Convert phase into a triangle wave
  value = (grainPhaseAcc >> 7) & 0xff;
  if (grainPhaseAcc & 0x8000) value = ~value;
  // Multiply by current grain amplitude to get sample
  output = value * (grainAmp >> 8);

  // Repeat for second grain
  value = (grain2PhaseAcc >> 7) & 0xff;
  if (grain2PhaseAcc & 0x8000) value = ~value;
  output += value * (grain2Amp >> 8);

  // Make the grain amplitudes decay by a factor every sample (exponential decay)
  grainAmp -= (grainAmp >> 8) * grainDecay;
  grain2Amp -= (grain2Amp >> 8) * grain2Decay;

  // Scale output to the available range, clipping if necessary
  output >>= 9;
  if (output > 255) output = 255;

  // Output to PWM (this is faster than using analogWrite) 
  PWM_VALUE = output;

Duane B
1538  Using Arduino / Audio / Re: Auduino v5 on uno only pot 4 works on: February 29, 2012, 02:47:04 am
   I have had a quick scan through the code and while I do not have an Arduino to test on at the moment, one thing you can try is adding the keyword volatile to the variable declarations -

i.e change

uint16_t syncPhaseAcc;


volatile uint16_t syncPhaseAcc;

and repeat this for all of the variables, it might not be needed for all but I dont have the time to check this at the moment.

Can you try it out and let me know how you get on

Duane B.
1539  Using Arduino / Audio / Re: Auduino v5 on uno only pot 4 works on: February 29, 2012, 01:18:18 am
   I also built an Auduino V5 on an UNO and only one pot had any effect. I built it very quickly just to try and so I was not surprised when it didn't work. I also hardcoded values in place of the analogReads and these did not have any effect - the same result as you observed.

   I will have another look at it now that I know it was not just down to my lack of attention while building.

   Duane B
1540  Using Arduino / General Electronics / Re: Turn Short Pulse Into Longer Pulse on: February 28, 2012, 12:27:20 pm
   Thanks for the replies, I have found a few sample circuits by searching for the term 'pulse stretcher'.

   I was planning to try them out this evening, but I picked up some 556 Timers earlier today and have been migrating my transmitter from cascaded 555s to a single 556 - its so much easier to work with on strip board :-)

   I will get back to the pulse stretcher tomorrow.

   In the meantime, thanks for all your help

Duane B
1541  Using Arduino / Project Guidance / Re: Using a camera to guide an RC car from a computer. on: February 28, 2012, 12:51:27 am
   Just to add my few cents worth -

   If you can stretch to lipo batteries and a charger for them, you will get all the power you need, they are also much lighter than older nimh or nicad batteries.

   For lower speeds, its common to fit lathe or crawler motors to cars, these provide low speeds, very smooth control, longer run times and sufficient torque to move around whatever equipment you load the car up with - my crawler can push my four year faster than I can walk in his go kart.

   As previously mentioned you should get a hobby grade radio, this will give you proportional control for smooth and accurate movement, my low end system has a range of over 100 meters, thats as far as I can still see and usefully control the car, more expensive systems will give much greater range, my eyes won't !

Duane B

1542  Using Arduino / General Electronics / Re: Turn Short Pulse Into Longer Pulse on: February 28, 2012, 12:32:59 am
   Thanks for the replies.

    Its for an IR Decoder, I am generating a 40Khz IR signal from a 555 Timer which activates the decoder, this 40Khz Signal is being switched at 100Hz by another 555 Timer which is the signal I am interested in at the IR Decoder end. In daylight there is sufficient light to cause momentary pulses on the IR Decoder, its very simple to filter these out in software, however I have an LED attached to the decode which lights whenever it reads a signal, its very simple an LED connected between Vcc and the decoder output, when the decoder output is pulled low, the LED Lights. This works very well for testing my hardware with or without software running, but the pulses caused by environmental light are generally too short to visibly light the LED. What I would really like is a low component count solution to extend the pulse length in hardware so that the pulse is visible on the LED. I was hoping for something with fewer components that a 555 monostable, but given the difference in the tigger pulse and visible pulse durations it might be my only options unless anyone can expand on the suggestion from goforsmoke -

"If the pulse is strong enough then let it charge a resistor-capacitor(-ground) to light the led or hold the pin HIGH. If it isn't then use a transistor to make it strong enough."

Duane B

    Duane B.

1543  Using Arduino / General Electronics / Turn Short Pulse Into Longer Pulse on: February 27, 2012, 10:17:13 am
   I have an application where I expect a certain amount of environmental noise on my input, I have my hardware set up so that an indicator LED lights in the presence of this noise however the duration of some noise is too short to visibly light the LED. I would like to use hardware to generate a longer visible pulse, I know that I can easily do this in software, but I like the current arrangement where the hardware is reporting its own state - its a sanity check on my software.

   Can anyone point me in the direction general direction of a hardware approach - I am thinking something along the lines of a transistor to switch a higher current that would charge a series capacitor. I know I can use a 555 Timer but would be interested to learn of and try out an alternative.


Duane B
1544  Using Arduino / Motors, Mechanics, and Power / Re: ESC arming problem on: February 25, 2012, 10:08:47 am
   For heli 0 is an appropriate arming value.

   As for the beep it could be anything at all, it might be a low voltage alarm, a signal alarm, anything.

   I don't have any experience with Heli ESCs, but if you post a picture someone might be able to tell what it is or if its a generic copy, what it was copied from.

   Other than that do you have radio equipment to program and test it with, does it beep with a radio or just with Arduino ?

Duane B
1545  Using Arduino / Programming Questions / Re: Button Function - Call throughout when button action needed on: February 25, 2012, 10:04:16 am
 We might be getting off the OPs topic at this point, but a reasonable improvement from your suggestions would be to make the delay a parameter of the function.

In addition it would also be possible to pass the mask to getKeys so that only the keys of interest are poled and the delay is only active if a LOW is detected on a key of interest.

The three functions obviously implement a blocking/poling approach to the user interface, it is the simplest approach and based on the original topic - 'Button Function - Call throughout when button action needed' would appear to be an appropriate response.

Duane B.

Pages: 1 ... 101 102 [103] 104 105 ... 114