working code including serial comm