Precise determination of the resonant frequency, phase, and quality factor in micromechanical and nanomechanical oscillators would permit, among other things, (i) the detection of trace amounts of adsorbed molecules through a shift in the resonant frequency, and (ii) pressure variations in the environment which affect the mechanical damping of the oscillator. The major difficulty in making these measurements in many cases is the ancillary equipment such as lasers or high magnetic fields that must be used. Being able to make precise measurements with a fully electrical actuation and detection method would greatly extend the usefulness of these oscillators. Detecting the oscillation through changes in the capacitance between the oscillator and a counter electrode is difficult because the static capacitance between them as well as the parasitic capacitance of the rest of the circuitry overwhelm the detection. We have found that the charge on a microcantilever or nanocantilever when driven by a nearby counter electrode contains higher harmonics of the driving signal with appreciable amplitude. This allows detection at frequencies well removed from the driving frequency, which increases the signal to background ratio by approximately three orders of magnitude. With this method, we show clear electrical detection of mechanical oscillations in ambient conditions for two systems: Si-based microcantilevers and multiwalled carbon nanotube based nanocantilevers.