Show Posts
Pages: 1 ... 101 102 [103] 104 105 ... 114
1531  Using Arduino / Sensors / Re: Suggestions on IR communication on: March 02, 2012, 05:32:49 am
   Ok, your project is as I previously understood it.

   The next question is, do you want control of the servo and the motor to be proportional ? if so its more functionality and more work than simple on/off left/right.

    Are you going for proportional control ?

    If so, my thinking is that you can generate a 38Khz IR signal from an Arduino timer or a 555 Timer and then pulse this signal on and off using the servo library.

    Are you planning to use two Arduinos ? or just one for transmitting or receiving ?

Duane B
1532  Using Arduino / Motors, Mechanics, and Power / Re: Help connecting nonstandard servo? on: March 02, 2012, 04:35:34 am
   If you can put up a picture of the connecter head on so that you are looking into the pin holes, this will help, the connectors are normally notched with either two corners cut or an extension tab on one side. If you have a picture I will have a look at one of my receivers and tell you which wire is which - the previous suggestions of opening the servo will also work, upto you.

Duane b
1533  Using Arduino / Project Guidance / Re: Help buying Arduino Board on: March 02, 2012, 04:31:04 am
   I would still suggest and 'UNO'. The one advantage I see of the smaller UNO board is that there are lots of low cost, well tried and supported methods of making your projects permanent.

So if you have the money I would suggest get a single UNO and with any money you have left over buy a few component packs for 'bread board arduinos' or 'standalone arduinos' you will learn a lot more this way and will be able to keep anything really cool that you make without using up your one and only UNO.

Duane B
1534  Using Arduino / Project Guidance / Re: A game with Arduino and IR on: March 02, 2012, 04:27:12 am
    You could experiment with using chained 555 or 556 Timers to generate pulses on the IR Emitter, each 'phaser' could have a different pulse width. Its not perfect, but its very cheap.

The basic idea is to have one timer generating a 38Khz carrier, then have another switch this one on and off using by connecting its output to the reset pin of the carrier timer. You would choose the frequency of the second timer, lets call it the control timer so that each phaser had a unique pulse period.

I am doing this in my Lap Timer project although at the moment I am only timing one car so have not looked too far into transmitting and capturing unique IDs through the pulse width. As the time I have to capture the pulse is so short I would probably go for a different encoding for this, but in your case I believe it would work.

I will try and put up a description of the IR Transmitter over the weekend, but you can find the basic idea all over the web, search for '555 IR' all I am doing is adding a second timer to pulse the first one.

EDIT: Here is a link to a relevant approach -

Duane B.

1535  Using Arduino / Sensors / Re: Suggestions on IR communication on: March 02, 2012, 04:16:44 am
Hi Marcus,
   Just to make sure I am not leading you in the wrong direction for your project, can you give a quick outline of what you want the end result to be, then we can make a better judgement on IR or any other alternatives.

Duane B
1536  Using Arduino / Sensors / Re: IRremote library on: March 02, 2012, 04:14:53 am
   Are you using Arduino 1.0 , if so I recently saw some threads about older libraries not compiling.

This is one example and includes the fix -

Duane B
1537  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

1538  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

1539  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
1540  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.

1541  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
1542  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
1543  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
1544  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.
1545  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
Pages: 1 ... 101 102 [103] 104 105 ... 114