Show Posts
Pages: 1 [2] 3 4 ... 38
16  Using Arduino / Project Guidance / Strange problem, sending IR control signals - not working on stand alone 328P on: December 30, 2013, 09:45:29 pm
Hi all. I'm working on something which is really bugging me. I am trying to send a IR code to switch a device off, and I'm using the code attached. I have it working on a bread-boarded using a Nano (328P), I then started on the project and built a perf board standalone 328 which seemed successful, the blink sketch runs fine.

Here is the problem, with a IR LED connected to the perf board 328 - it doesn't seem to switch off the device.

I started to trouble shoot - I am using the exact same code on both, same LED, same value resistor same pin numbering. I used my phone camera to verify IR is being emitted when I send the signal from the LED and it is on the bread-boarded nano, but I can't see anything coming from the LED on the perf board 328.

I then loaded the blink sketch and once again used my camera to check and the IR LED on the perf board was indeed lighting up.  I even put a 328 chip on another breadboard and set it up the same but I'm seeing exactly the same issue; LED appears working but nothing when I send the signal smiley-sad

I have run out of things to try, hope somebody can come up with some ideas?

Thanks

Edit.. forgot the code

Code:
// This program allows an Arduino to power on/off a Duraflame heater using infrared
//
// Usage: hook up an IR led with Annode on pin 13.  Then send serial data "POWER"
// to the arduino.  It should flash the LED code.
//
// By Rick Osgood with code borrowed from adafruit.com
//

#define IRledPin 13
#define NumIRsignals 96
      
// This is the code I determined works for my Duraflame heater
int IRsignal[] = {
// ON, OFF (in 10's of microseconds)
130, 34,
130, 36,
46, 118,
128, 36,
128, 36,
46, 118,
48, 118,
46, 118,
46, 118,
46, 118,
46, 118,
130, 684,
128, 36,
130, 34,
48, 118,
128, 36,
128, 36,
46, 118,
46, 118,
46, 118,
46, 120,
46, 118,
46, 118,
128, 686,
128, 36,
128, 36,
46, 118,
130, 34,
130, 36,
46, 116,
48, 118,
46, 118,
46, 118,
46, 118,
48, 116,
130, 684,
128, 36,
130, 34,
48, 118,
128, 36,
128, 36,
46, 118,
46, 118,
48, 116,
48, 118,
46, 118,
46, 118,
128, 0};

void setup(void) {
  digitalWrite(IRledPin, LOW);   //Make sure LED starts "off"
  Serial.begin(9600);            //Initialize Serial port
}

void loop() {
  char data[6];
  int index = 0;

  delay(1000);  //Serial input seems to need some kind of short delay or the data gets screwed up.

  while (Serial.available() > 0) {            //Loop if there data on the serial line
    if (index < 5) {                          //Make sure we don't overflow
      data[index] = Serial.read();            //Load a character into the string
      index++;                                //Increment the index to get the next character
    }
  }
  
  data[5]='\0';  //Null terminate the string
  
  if (strcmp(data, "POWER") == 0){                //If the Arduino receives the POWER signal...
    Serial.println("SENDING SIGNAL!");
    for (int i = 0; i < NumIRsignals; i+=2) {         //Loop through all of the IR timings
      pulseIR(IRsignal[i]*10);              //Flash IR LED at 38khz for the right amount of time
      delayMicroseconds(IRsignal[i+1]*10);  //Then turn it off for the right amount of time
    }
  }                                         //Otherwise do nothing!
}

// This function allows us to PWM the IR LED at about 38khz for the sensor
// Borrowed from Adafruit!
void pulseIR(long microsecs) {
  // we'll count down from the number of microseconds we are told to wait
 
  cli();  // this turns off any background interrupts
 
  while (microsecs > 0) {
    // 38 kHz is about 13 microseconds high and 13 microseconds low
   digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
   delayMicroseconds(10);         // hang out for 10 microseconds, you can also change this to 9 if its not working
   digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
   delayMicroseconds(10);         // hang out for 10 microseconds, you can also change this to 9 if its not working
 
   // so 26 microseconds altogether
   microsecs -= 26;
  }
 
  sei();  // this turns them back on
}
]
17  Using Arduino / Project Guidance / Re: Nicks low power code, modifying for two push buttons on: December 24, 2013, 09:48:08 pm
many thanks Nick, works like a charm now smiley

Amazing how small the current is, and how it wakes so quickly

Now to try and add some code to expand my project smiley
18  Using Arduino / Project Guidance / Re: Nicks low power code, modifying for two push buttons on: December 23, 2013, 09:14:37 pm
Thanks, I never seem to stop the simple oversights!

It seems to be working now, but I'm getting strange behavior - the LED on D13 - D2 triggered is flashing at the expected rate, but the LED on D12 - D3 triggered is flashing at around twice the expected rate?
19  Using Arduino / Project Guidance / Re: Nicks low power code, modifying for two push buttons on: December 23, 2013, 07:56:52 pm
Thanks Nick! I can kind of follow that but I can't get the code working,  D12 is always flashing? Not sure what I am doing wrong?

Thanks

Code:
#include <avr/sleep.h>

const byte LEDA = 13;
const byte LEDB = 12;
 
volatile byte wakeUpPin;

void combinedWake ()
{
  // cancel sleep as a precaution
  sleep_disable();
  // must do this as the pin will probably stay low for a while
  detachInterrupt (0);
}  // end of combinedWake

void wake_A ()
{
wakeUpPin = 2;
combinedWake ();
}  // end of wake_A

void wake_B ()
{
wakeUpPin = 3;
combinedWake ();
}  // end of wake_B

void setup ()
  {
  digitalWrite (2, HIGH);  // enable pull-up
  }  // end of setup

void loop ()
{
  if (wakeUpPin == 2)
  {
  pinMode (LEDA, OUTPUT);
  digitalWrite (LEDA, HIGH);
  delay (50);
  digitalWrite (LEDA, LOW);
  delay (50);
  pinMode (LEDA, INPUT);
  }
 
else if (wakeUpPin == 3)
{
  pinMode (LEDB, OUTPUT);
  digitalWrite (LEDB, HIGH);
  delay (50);
  digitalWrite (LEDB, LOW);
  delay (50);
  pinMode (LEDB, INPUT);
}
 

  // disable ADC
  ADCSRA = 0; 
 
  set_sleep_mode (SLEEP_MODE_PWR_DOWN); 
  sleep_enable();

  // Do not interrupt before we go to sleep, or the
  // ISR will detach interrupts and we won't wake.
  noInterrupts ();
 
// will be called when pin D2 goes low 
  attachInterrupt (0, wake_A, LOW);
// will be called when pin D3 goes low 
  attachInterrupt (1, wake_B, LOW);
 
 
 
 
  // turn off brown-out enable in software
  // BODS must be set to one and BODSE must be set to zero within four clock cycles
  MCUCR = bit (BODS) | bit (BODSE);
  // The BODS bit is automatically cleared after three clock cycles
  MCUCR = bit (BODS);
 
  // We are guaranteed that the sleep_cpu call will be done
  // as the processor executes the next instruction after
  // interrupts are turned on.
  interrupts ();  // one cycle
  sleep_cpu ();   // one cycle


  } // end of loop
20  Using Arduino / Project Guidance / Re: Nicks low power code, modifying for two push buttons on: December 23, 2013, 03:35:03 pm
Hi Nick, many thanks for the great resources!

What is the variable that it sets?

21  Using Arduino / Project Guidance / Re: Nicks low power code, modifying for two push buttons on: December 23, 2013, 01:09:05 pm
Hmmm I'm not sure how one one would use diodes? Is it not possible to decide which interupt has been triggered and run a routine based on that?

Thanks smiley
22  Using Arduino / Project Guidance / Nicks low power code, modifying for two push buttons on: December 23, 2013, 07:14:27 am
Hi all, I would like to modify Nick Gammons' power saving code to have two buttons (on interrupt pins). In the current code it seems that if the processor wakes up it runs the whole loop function, but I would like it to run a prefined function on one button input and another on the second button input?

Thanks

Code:
#include <avr/sleep.h>

const byte LED = 9;
 
void wake ()
{
  // cancel sleep as a precaution
  sleep_disable();
  // must do this as the pin will probably stay low for a while
  detachInterrupt (0);
}  // end of wake

void setup ()
  {
  digitalWrite (2, HIGH);  // enable pull-up
  }  // end of setup

void loop ()
{
 
  pinMode (LED, OUTPUT);
  digitalWrite (LED, HIGH);
  delay (50);
  digitalWrite (LED, LOW);
  delay (50);
  pinMode (LED, INPUT);
 
  // disable ADC
  ADCSRA = 0; 
 
  set_sleep_mode (SLEEP_MODE_PWR_DOWN); 
  sleep_enable();

  // Do not interrupt before we go to sleep, or the
  // ISR will detach interrupts and we won't wake.
  noInterrupts ();
 
  // will be called when pin D2 goes low 
  attachInterrupt (0, wake, LOW);
 
  // turn off brown-out enable in software
  // BODS must be set to one and BODSE must be set to zero within four clock cycles
  MCUCR = bit (BODS) | bit (BODSE);
  // The BODS bit is automatically cleared after three clock cycles
  MCUCR = bit (BODS);
 
  // We are guaranteed that the sleep_cpu call will be done
  // as the processor executes the next instruction after
  // interrupts are turned on.
  interrupts ();  // one cycle
  sleep_cpu ();   // one cycle

  } // end of loop
23  Using Arduino / Project Guidance / Re: IR remote controller project with low power? on: December 18, 2013, 06:40:04 am
I need to think a bit more about it I guess, it would be nice to only have to press one button but maybe could use come dual pole switches - one pole to wake up via interrupt and the other pole to be read as a digital input?

Thanks
24  Using Arduino / Project Guidance / Re: IR remote controller project with low power? on: December 06, 2013, 09:53:46 pm
the only trouble with that though is I would need to press two buttons, one hardware interupt then another button connected to a standard digital IO pin?

Thanks
25  Using Arduino / Project Guidance / Re: IR remote controller project with low power? on: December 04, 2013, 07:36:43 am
any ideas?
26  Using Arduino / LEDs and Multiplexing / Re: WS2801, Fast SPI or Adafruit library? on: December 02, 2013, 05:16:35 pm
True  smiley-razz

Just wondering if there is any advantage in one over the other? I guess the fast spi library might be faster and able to drive more pixels?

Thanks
27  Using Arduino / LEDs and Multiplexing / WS2801, Fast SPI or Adafruit library? on: December 02, 2013, 12:34:38 pm
Hi all, I have a string of WS2801 LEDs that I would now like to use. I have tested them with the Adafruit library before and they worked well, but a few days ago I came across the Fast SPI library which appears to be compatible with WS2801 drivers.

I'm now wondering if I would be better off wiring the string to the SPI pins of the Arduino pro mini that I planned to use or just stick to the Adafruit method?
28  Using Arduino / Microcontrollers / Re: low power consumption 328p on: December 02, 2013, 06:15:47 am
Thanks guys. That is true if it is sleeping I guess 16MHz will be fine.

Probably a silly question but running at 8MHz, will the whole sketch run half speed - IE. delay(100) would become delay(200)?

Thanks
29  Using Arduino / Microcontrollers / low power consumption 328p on: November 30, 2013, 09:44:07 pm
Hi all. I would like to run an 328P at low power, will it be OK running from 3x AA batteries? At what voltage is it likely to stop running?

If I used the internal 8MHz clock, would that improve consumption much? I want to make a IR remote control, will running at 8Mhz screw the sketch up - timings etc?

Thanks
30  Using Arduino / Project Guidance / Re: IR remote controller project with low power? on: November 29, 2013, 07:15:53 am
Thanks guys, I will have a read of the link later.

If I was to use interrupts, how could I read multiple inputs?
Pages: 1 [2] 3 4 ... 38