Making improvements to Arduino code to reduce pi memory issues