Cercanías train tickets can be bought from machines at the train station and if available, ticket windows where Renfe staff can help you out. It's easier to use the machines, but you can always go to a ticket window if you speak a bit of Spanish and need extra help.