getting closer (more code moved from Arduino to Pi)