I just got the Arduino a few days ago and must say that I am quite taken with it. I have quite a lot to learn, but I thought that I'd share my latest creation with you all. I commented it pretty well and tried to be clear when things got a little messy. If you use it, let me know how this works for you!
I wish that I could actually just paste the program here, but it looks as if I will exceed the maximum number of characters by a fair amount. Below is the code for the program, but without the comments. If you want the complete code with all its comments please get it here: http://dustinj.us/files/arduino/Arduino_IR_Transmit.txt
It's a hold over from the days when on the x86 platform it was quicker to and something with the inverse than it was to set it to zero. It was also quicker to xor something with itself.
If you dont mind, I post “my” code, I derived from yours. It triggers the shutter of a Nikon D80 and should also work with D70(s) and probably all the other Nikons, that can be remotecontrolled with the standard Nikon remote.
#define IR_LED_PIN 6 // Pin for the IR-LED
#define STATUS_LED_PIN 13 // Pin for the Status-LED
int c = 0; // Counter to repeat loop
void setup() { // Setup, initialize Ports etc
initialize_ir(IR_LED_PIN, STATUS_LED_PIN);
}
void loop() { // sending the IR-Code itself, repeat 2 times with 62ms delay
digitalWrite(STATUS_LED_PIN, HIGH);
for (cg=0; cg<=1; cg++)
{
delay(62);
ir_raw_write_high(1 << 6, 2000);
ir_raw_write_low(1 << 6, 10000); // lowtime: 27830us, but the delayMicroseconds function is known to be precise only up to 16000 us, thats why I splittet that.
ir_raw_write_low(1 << 6, 10000);
ir_raw_write_low(1 << 6, 7830);
ir_raw_write_high(1 << 6, 390);
ir_raw_write_low(1 << 6, 1580);
ir_raw_write_high(1 << 6, 410);
ir_raw_write_low(1 << 6, 3580);
ir_raw_write_high(1 << 6, 400);
ir_raw_write_low(1 << 6, 10);
}
digitalWrite(STATUS_LED_PIN, LOW);
delay(2000);
}
void initialize_ir(byte ir_pin, byte status_pin) {
pinMode(status_pin, OUTPUT);
pinMode(ir_pin, OUTPUT);
digitalWrite(status_pin, LOW);
digitalWrite(ir_pin, LOW);
prepare_timer();
}
void prepare_timer() {
TCCR1A = 0x00;
TCCR1B = (1 << CS11) | (1 << CS10);
TIMSK1 = 0x00;
}
void ir_raw_write_low(byte pin, unsigned int time) {
PORTD = PORTD & ~pin; // sets pin LOW
delayMicroseconds(time);
}
void ir_raw_write_high(byte pin, unsigned int time) {
for(int i=0; i <= time/26; i++) {
PORTD = PORTD | pin;
delayMicroseconds(13);
PORTD = PORTD & ~pin;
delayMicroseconds(13);
}
}
As you can see above, I used your code for releasing my camerashutter via IR with the Arduino. I just used ir_raw_write_high/low and it works like a charme. But I’d like to understand what your functions are actually doing.
You commented on it, but I still dont understand. Do you have a reference, where I can read, what TCCR1A and TIMSK1 are and how they work? I couldnt find anything.
Do you have a reference, where I can read, what TCCR1A and TIMSK1 are and how they work?
I actually had a hard time finding documentation on the timers too. I resorted to digging through the datasheet, which wasn't as bad as it sounds. I also found a pretty helpful overview of timers at the avrfreaks website.
Documentation for the PORTD stuff can be found Here.
Documentation for the bit manipulation part of the code can be found Here or in the extended language reference
Thx guys. I now got some time, worked through the links and understood it. Great stuff. The Scanner I wanted to realize with this is working. Some Hardware is missing. If I got that working, I'll post it here and maybe somewhere else, too.