NikonLens 0.0.1
Library for controlling Nikon F-mount lenses.
|
Control Nikon F-mount lenses from an Arduino. More...
#include <NikonLens.h>
Public Types | |
enum | tResultCode { Success , Timeout } |
Possible result codes for commands. | |
Public Member Functions | |
void | begin (u8 handshakePin_In, u8 handshakePin_Out) |
Initialize SPI for lens communication. | |
void | end () |
Tear down, relinquish resources. | |
tResultCode | sendCommand (u8 cmd, u8 byteCountFromLens=0, u8 *bytesFromLens=nullptr, u8 byteCountToLens=0, u8 const *bytesToLens=nullptr) |
Send lens command and read/write data. | |
Control Nikon F-mount lenses from an Arduino.
Nikon lenses use a modified version of SPI. See also:
Connections are as follows (with Arduino Uno pin numbers):
NOTE: The Nikon D5100 starts communication with the lens at 96kHz, then increases speed to 156kHz if the lens supports it. Because the Arduino runs at 16MHz and the maximum divider ratio for SPI is 128, the slowest we can run the bus is 125kHz.
If using this code with older lenses causes problems, it should be modified to use the AVR's System Clock Prescaler to drop the CPU frequency so you can achieve a slower SPI bus speed.
I haven't tested this, it may interfere with other Arduino features.
void lain::tNikonLens::begin | ( | u8 | handshakePin_In, |
u8 | handshakePin_Out | ||
) |
Initialize SPI for lens communication.
See class description for connection information.
[in] | handshakePin_In | Input pin for reading the H/S line. |
[in] | handshakePin_Out | Output pin for pulling the H/S line low. |
tNikonLens::tResultCode lain::tNikonLens::sendCommand | ( | u8 | cmd, |
u8 | byteCountFromLens = 0 , |
||
u8 * | bytesFromLens = nullptr , |
||
u8 | byteCountToLens = 0 , |
||
u8 const * | bytesToLens = nullptr |
||
) |
Send lens command and read/write data.
Sends command cmd to the lens.
If data is to be received, byteCountFromLens must be set to the number of bytes expected.
If data is to be sent, byteCountToLens must be set to the number of bytes to send.
Received data is placed in bytesFromLens, so it must be sized accordingly.
Likewise, data sent to the lens is sourced from bytesToLens.
[in] | cmd | The command byte to send. |
[in] | byteCountFromLens | Number of bytes to receive, or zero if not receiving. |
[out] | bytesFromLens | Destination for received bytes, or null if not receiving. |
[in] | byteCountToLens | Number of bytes to send, or zero if not sending. |
[in] | bytesToLens | Source of bytes sent to lens, or null if not sending. |