A novel random access protocol for data collection from a set of energy harvesting (EH) capable wireless nodes is proposed. The scheme is a variant of the dynamic framed ALOHA (DFA) protocol, tailored to EH networks. The proposed scheme, referred to as energy group-DFA (EG-DFA), is based on the observation that, when DFA is operated with EH-capable nodes, the optimal number of slots in a frame (i.e., the frame size) must balance two conflicting performance requirements. First, increasing the data collection rate (throughput) is well known to require a frame size equal to the backlog, namely the number of transmitting nodes. Second, since each node can store and harvest a finite energy, the number of (re)transmissions attempts that each node can perform during the channel contention process is limited. Thus, decreasing the number of uncollected data packets due to energy shortages (referred to as delivery error rate, DER) calls for a larger frame so as to avoid energy-wasting collisions. Moreover, the optimal frame size depends on both the residual energy at the nodes and the harvesting rate. Leveraging these insights, EG-DFA creates groups of nodes according to their energy availability and runs optimized and separated instances of DFA for each group. Simulation results show the advantages of EG-DFA in terms of throughput for a given DER, especially in the low-DER regime.