NikonLens 0.0.1
Library for controlling Nikon F-mount lenses.
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
lain::tNikonLens Class Reference

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.
 

Detailed Description

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.

Member Function Documentation

◆ begin()

void lain::tNikonLens::begin ( u8  handshakePin_In,
u8  handshakePin_Out 
)

Initialize SPI for lens communication.

See class description for connection information.

Parameters
[in]handshakePin_InInput pin for reading the H/S line.
[in]handshakePin_OutOutput pin for pulling the H/S line low.

◆ sendCommand()

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.

Parameters
[in]cmdThe command byte to send.
[in]byteCountFromLensNumber of bytes to receive, or zero if not receiving.
[out]bytesFromLensDestination for received bytes, or null if not receiving.
[in]byteCountToLensNumber of bytes to send, or zero if not sending.
[in]bytesToLensSource of bytes sent to lens, or null if not sending.
Returns
A result code indicating success, or the failure cause.

The documentation for this class was generated from the following files: