The talks took place over three days of assemblies with pupils give first hand accounts of the dangers and near misses which have taken place over the years.
Experienced Cardiff based train drivers, Jon Davies and Greg Wilcox have been delivering the talks for several years on behalf of Arriva Trains Wales and the wider rail industry, and say they are now more important than ever.
“Engaging young people in rail safety is particularly important for the pupils at St Martin's because of the planned electrification of the Valleys network,” said Mr Davies.
The school is just a few minutes walk from Caerphilly station and the line linking Rhymney to Cardiff.
British Transport police officers joined the talk to give a detailled account of the problems that can arise both to yourself and to the local community and emergency services if you trespass on the railway or don't treat it with enough respect.
Community Support Officer Andrew Williamson said: “Every single day across Wales we are called to the tracks because a train driver has had to sound their horn or apply their emergency brake in a desperate bid to avoid youths on the line, who then run off, seemingly unaware of the danger they have put themselves in.
“Trespass may not sound like a serious offence but, in the unforgiving environment of the railway, it can be fatal.
“Our main concern is keeping people safe. We are more interested in preventing instances of trespass and saving lives than enforcement, which is why events such as this are so important in helping to open young people’s eyes to the very real dangers posed by the railway.
“Trespass is not a game: these are real tracks, with real trains and real-life consequences. My message is simple - stay safe and stay off the tracks.”
Teacher Claire Mason said: "The assembly was thought provoking and really helped to highlight potential risks on the railway.
"Pupils enjoyed the interactive content and the anecdotes were hard hitting. Following the assembly, pupils were able to discuss the issues of level crossings, illegal access to train lines with their tutors. One of the most important lessons was linked to the future electrification of the valleys lines and the dangers associated with high voltage electricity cables."
The talk follows a previous one given at Willows High School in Cardiff.