This schema is used to control 16 device through serial port but it gives random results in reality however I have try it in simulation program and it work very well
Nothing obvious is wrong with the schematic (no datasheets were consulted), my guess is the problem is code related or you're using a bad power supply.