Motivated by the increasing interest in networked multi-agent systems and the wide number of applications in distributed control of smart grids, we address the problem of synchronization of microgrids. Two topologies are considered: the physical topology that relates the interconnection of distributed generators and loads, and the communication topology, which describes the information flow of the power system measurements. We propose a control strategy based on the information flow and we show that there exists a strong relationship between both topologies in order to achieve synchronization. As a matter of fact, we show that our results can be extended when isolated group of nodes are taken into account, and they can be connected or disconnected to the main grid. Finally, the effects of time-varying sampling are analyzed using some average passivity conditions, and sampling-time independence is demonstrated with the proposed controller.