Nikon camera libary added to the playground.

Hi, There has been a lot of talk about controlling Nikon cameras. Using the existing information on the net I wrote a header file to do this. Hope this will be is useful to others. http://www.vonroth.com/Arduino/NikonIrControl/

I have a question for other library developers. This code was so simple I just made it a .h file. It seems to me that making it a proper C++ object is overkill and would use additional Arduino resources. Was this the correct decision?

Thanks,

Gustav

This was only pointed out to me today, sorry for the very slow response.

I have a couple of points.

  1. The convention for header files is they should only contain information about code or data, and never generate code within itself. If a header file, which generates code or allocates space for data, gets included into several places (e.g. several .c or .cpp files), it will likely generate link errors because the same functions or data are defined multiple times.

(Macros are okay because they are expanded in the program which is including the header.)

It is better to put the code in a normal .c/.cpp/.pde file, and use the header to say what the function looks like.

So the header would only contain: void cameraSnap(int pin);

The remainder of the file would be in a normal .pde/.c/.cpp file (I can't quickly say which, but I'd tend to do a .pde).

  1. Did you know that the hardware timers in the Arduino (ATmega) can generate square waves without continual software intervention?

There are three timers, and anyone will do the job needed.

By using a timer, the 38KHz modulation will be very accurate (sub-10th-microsecond), and the program can get on and do other things because it is not running in a loop to control the IR LED modulation. The program will need to control the larger scale timing (though that could hang off the same timer in an interrupt service routine if you really wanted to).

There is a downside though. You'd need to understand the ATmega manual chapter on the timer, and the set-up code looks a bit ugly, but it is rock solid.

HTH GB-)

PS - I am away for a few days, so if I don't respond quickly, I apologise in advance. I will try to get back to you later this week. If you want me to, I can help you write timer code.

Point 1. I agree. I was just being lazy I should repackage it some time.

As for point 2. I have written 38KHz modulation for Arduino using timer and actually have the code done for other projects. I just figure this way the timer are available for other things.

If you offering help on low level stuff I am working on a libary for a circular que for 2 projects. A polar hear monitor and a bike computer that reads wheel rotation. It essentually the same code for both projects. The code works great when I write it as a standard sketch using the Arduino Interrupt function. But when I write it as a library and don’t use the Arduino interupt function it is interupting on the riseing and fallign edge of the pulse. If you think you can help I will post the code here.

Thanks,

Gustav