Optogenetic approaches allow the manipulation of neuronal activity patterns in space and time by light, particularly in small animals such as zebrafish. However, most techniques cannot control neuronal activity independently at different locations. Here we describe equipment and provide a protocol for single-photon patterned optical stimulation of neurons using a digital micromirror device (DMD). This method can create arbitrary spatiotemporal light patterns with spatial and temporal resolutions in the micrometer and submillisecond range, respectively. Different options to integrate a DMD into a multiphoton microscope are presented and compared. We also describe an ex vivo preparation of the adult zebrafish head that greatly facilitates optogenetic and other experiments. After assembly, the initial alignment takes about one day and the zebrafish preparation takes <30 min. The method has previously been used to activate channelrhodopsin-2 and manipulate oscillatory synchrony among spatially distributed neurons in the zebrafish olfactory bulb. It can be adapted easily to a wide range of other species, optogenetic probes and scientific applications.