We present precision measurements with MHz uncertainty of the energy gap between asymptotic and well bound levels in the electronic ground state X $^1Sigma_{mathrm{g}}^+$ of the $^{39}$K$_2$ molecule. The molecules are prepared in a highly collimated particle beam and are interrogated in a $Lambda$-type excitation scheme of optical transitions to long range levels close to the asymptote of the ground state, using the electronically excited state A $^1Sigma^+_{rm u}$ as intermediate one. The transition frequencies are measured either by comparison with I$_2$ lines or by absolute measurements using a fs-frequency comb. The determined level energies were used together with Feshbach resonances from cold collisions of $^{39}$K and $^{40}$K reported from other authors to fit new ground state potentials. Precise scattering lengths are determined and tests of the validity of the Born-Oppenheimer approximation for the description of cold collisions at this level of precision are performed.