Renewable energy resources have an increasing share of the electrical power, and the concept of distributed generation and storage units is about to completely change the basic architecture and control algorithms of the electric power grids. In this tutorial paper, first a survey on data-driven control algorithms is presented. Then, an overview of different control problems related to the integration of the distributed energy resources into the electrical grid is given. Finally, a time-domain data-driven solution based on the neural networks and a frequency-domain solution using convex optimization techniques are presented for some challenging control problems in microgrids. The solutions are validated by simulation and hardware-in-the-loop (HIL) experiments.