A computer-implemented method (400, 500) for bidirectional data transfer based on barcodes, the method comprising: dividing, by a first device, a payload data to be sent by the first device into a plurality of data packages; generating, at the first device, a plurality of payload barcodes, each of the plurality of payload barcodes corresponding to one of the plurality of data packages, wherein each payload barcode comprises data of the corresponding data package; capturing images by a first camera of the first device, wherein a view of the first camera is configured to cover a second display of a second device, and any barcode contained in the images captured by the first camera is detected and decoded at the first device; displaying, at a first display of the first device, in sequence, the plurality of payload barcodes, one at a time, until all the plurality of payload barcodes have been displayed, including: stopping displaying a previous payload barcode of the sequence and displaying a subsequent payload barcode in the sequence, at the first display of the first device, in response to detecting, at the first device, in images of the second display captured by the first camera of the first device an acknowledgment "ACK" barcode corresponding to the previous payload barcode; and performing, at the first device operating in a sending role, deadlock resolution operations in response to detecting, while displaying a first of the plurality of payload barcodes, that the second device is also in a sending role, wherein a device operating in a sending role displays a payload barcode, and wherein performing, at the first device operating in the sending role, the deadlock resolution operations comprises switching, by the first device, into a receiving role after a random delay and at a same time continuously determining whether the second device has entered a receiving role, wherein a device operating in a receiving role captures an image of a payload barcode. dividing, by a first device, a payload data to be sent by the first device into a plurality of data packages; generating, at the first device, a plurality of payload barcodes, each of the plurality of payload barcodes corresponding to one of the plurality of data packages, wherein each payload barcode comprises data of the corresponding data package; capturing images by a first camera of the first device, wherein a view of the first camera is configured to cover a second display of a second device, and any barcode contained in the images captured by the first camera is detected and decoded at the first device; displaying, at a first display of the first device, in sequence, the plurality of payload barcodes, one at a time, until all the plurality of payload barcodes have been displayed, including: stopping displaying a previous payload barcode of the sequence and displaying a subsequent payload barcode in the sequence, at the first display of the first device, in response to detecting, at the first device, in images of the second display captured by the first camera of the first device an acknowledgment "ACK" barcode corresponding to the previous payload barcode; and performing, at the first device operating in a sending role, deadlock resolution operations in response to detecting, while displaying a first of the plurality of payload barcodes, that the second device is also in a sending role, wherein a device operating in a sending role displays a payload barcode, and wherein performing, at the first device operating in the sending role, the deadlock resolution operations comprises switching, by the first device, into a receiving role after a random delay and at a same time continuously determining whether the second device has entered a receiving role, wherein a device operating in a receiving role captures an image of a payload barcode.