We address the problem of electronic and nuclear spin resonance of an individual atom on a surface driven by a scanning tunneling microscope. Several mechanisms have been proposed so far, some of them based on the modulation of exchange and crystal field associated with a piezoelectric displacement of the adatom driven by the radio frequency (RF) tip electric field. Here we consider another mechanism, where the piezoelectric displacement modulates the g-factor anisotropy, leading both to electronic and nuclear spin flip transitions. We discuss thoroughly the cases of hydrogenated Ti (S=1/2) and Fe (S=2) on MgO, relevant for recent experiments. We model the system using two approaches. First, an analytical model that includes crystal field, spin orbit coupling, and hyperfine interactions. Second, we carry out density-functional-based calculations. We find that the modulation of the anisotropy of the g tensor due to the piezoelectric displacement of the atom is an additional mechanism for scanning tunneling microscopy (STM)-based single spin resonance that would be effective in S=1/2 adatoms with large spin orbit coupling. In the case of hydrogenated Ti on MgO, we predict a modulation spin resonance frequency driven by the DC electric field of the tip.