Pages

Saturday, July 13, 2019

Controlling a loco with a Bluetooth phone app and Arduino - Part 2

Introduction

Having tried a simple approach to controlling a loco with a Bluetooth app and Arduino, I felt the need ArduinoRailwayControl.com could be modified. What I needed was more precise control at slower speeds for shunting at the sacrifice of losing more precision when running faster. This involved changing the code uploaded to the Arduino Nano board.
to develop the system further to improve the way the loco responded at slow speeds. As my knowledge and skills do not extend as far as writing my own apps, I decided to explore ways in which the nine step output from the ArduinoRailwayControl free app could be tweaked to provide more precise slow running.

Modifying the code

Fortuitously, Steve Massikker suggests that users might need to tinker with his code to tailor it to the needs of different locos and set-ups. The instructions for translating the signals received from the Bluetooth app have been made conveniently available in an array at the start of theArdiono program (sketch).

byte speedArray [] = {60, 80, 100, 120, 140, 170, 200, 230, 255};
 As can be seen, the speed steps increase by a factor of 20 initially, rising to 30 and finally 35. I felt the starting value of 60 was a little too high for my loco and so, after some experimentation, reduced this to 45. I then, changed the size of the steps to something a more exponential than linear.
byte speedArray [] = {45, 46, 48, 52, 60 , 76, 108, 172, 255};
Whilst this was an acceptable mathematical progression of steps, as you can see, in reality, the increments are quite abrupt at the upper ends of the scale.

So, some sort of compromise was needed.
byte speedArray [] = {45, 50, 60, 75, 95, 120, 150, 185, 225};
This provided a smoother speed progression at the lower end of the spectrum. Interestingly, the more abrupt speed changes are less noticeable at the upper end.


As can be seen, the speed steps now provide more control at lower speeds and are barely noticeable.


My next investigations will be to explore a way in which the output from a Bluetooth app can provide even more precise control. See Bluetooth loco control with a phone app - Part 3



No comments:

Post a Comment