Page 1 of 2

Initial experiments with Bluetooth and Arduino

Posted: Mon Jul 01, 2019 7:01 pm
by ge_rik
Whilst away on my hols (in sunny France - and yes it was hot!!), I got to grips with the (very) basics of Arduino. Now I'm back I've been experimenting.


Still early days yet, but I've written up wot I dun on my blog for those who might be interested
https://riksrailway.blogspot.com/2019/0 ... phone.html

Total outlay on the control bits = £17.81. I could have done it more cheaply if I'd bought the bits directly from China - but I didn't want to wait.

Hope it's of interest.

Rik

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 6:07 am
by philipy
Hi Rik,
Glad you had a good holiday. Yes it is hot in France, we still have a few more days here before we have to return and we are only a few kilometres from where the French temperature record was set last weekend at just over 45 deg C.

Anyway, thanks for your Arduino blog, very interesting, and when I've had time to go through the detail, possibly of interest. However, a couple of quick questions first -
1) is it necessary to have a fully working smart phone for the Bluetooth side of things to function, i.e with a valid SIM card installed? The reason I ask is that I don't possess such a beastie, but cheap 2nd hand units are available and might be worth the investment as long as I don't also have to fork out for a SIM account ( what did you say about being a cheapskate??).
2) You mention the limited Bluetooth range issue, and I wonder if it might be possible to programme the Arduino to maintain whatever its current instructions are on loss of signal, and continue with them until signal is regained, similar to the Deltang operation?

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 7:24 am
by ge_rik
Hi Philip
I can't see any reason why a network free phone wouldn't work. I also use it with my tablet which is like a phone without the phone. Regarding the range. I tested it in my garden and easily got 17m with foliage in the way. That's the max I get to see from phone to loco, so it could well be more. The coding by default keeps the last value received until it detects a change from the phone so in effect has built in coast control.

Rik

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 7:49 am
by ge_rik
It's early days so I haven't had much time for a full evaluation but what I've found so far is:

Pros
  • Cheap
    Flexible (I'm presently investigating a DIY app and already added directional lighting and coded auto station stop)
    Acceptable range
    Plenty of resources
Cons
  • Hard to see the screen in sunlight
    Not tactile - ie you can't feel the controls in your hand
    Easy to press the wrong button and lose the app - but that might be because I'm not an experienced smart phone user
    Not as compact and convenient as Deltang
    Some tech knowledge required but the learning curve is quite shallow
I'm going to keep playing, cos I like the challenge but I'm not sure it will become my default control system

Rik

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 10:04 am
by ge_rik
Latest development.
Steve Massikker from arduinorailwaycontrol.com has been in touch and wants me to collaborate in producing an app and coding specifically to meet the needs of large scale train operation. Watch this space, as they say.

Rik

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 10:12 am
by tom_tom_go
Oh Rik what have you started, I play trains to escape technology!

As long as this type of tech doesn't render DCC and traditional Tx/Rx obsolete then it's good thing for those who want to operate using a touch screen and an app.

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 12:22 pm
by philipy
ge_rik wrote: Tue Jul 02, 2019 10:04 am Latest development.
Steve Massikker from arduinorailwaycontrol.com has been in touch and wants me to collaborate in producing an app and coding specifically to meet the needs of large scale train operation. Watch this space, as they say.

Rik
I've just come back from wading through his site and I noticed that you seemed to have joined up!

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 12:45 pm
by ge_rik
philipy wrote: Tue Jul 02, 2019 12:22 pm
ge_rik wrote: Tue Jul 02, 2019 10:04 am Latest development.
Steve Massikker from arduinorailwaycontrol.com has been in touch and wants me to collaborate in producing an app and coding specifically to meet the needs of large scale train operation. Watch this space, as they say.

Rik
I've just come back from wading through his site and I noticed that you seemed to have joined up!
Have I? Must have a quick wade myself..... :shock:

Rik

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 3:47 pm
by -steves-
Rik

I love this idea and think it looks very funky. It's certainly cheap and for that is quite appealing.

One of the down sides is only 10 steps for control. Do you know if this can be changed later on to a much greater number, like 100?

Secondly, will this only work with a 12v ish supply? What about loco's running 18v or indeed 3v?

Cheers
Steve

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 4:11 pm
by idlemarvel
philipy wrote: Tue Jul 02, 2019 6:07 am ...However, a couple of quick questions first -
1) is it necessary to have a fully working smart phone for the Bluetooth side of things to function, i.e with a valid SIM card installed? The reason I ask is that I don't possess such a beastie, but cheap 2nd hand units are available and might be worth the investment as long as I don't also have to fork out for a SIM account ( what did you say about being a cheapskate??).
...
You don't need a SIM card at all to use the bluetooth feature of a phone, same applied to wifi. I use an old SIM-less iPhone 4 as my wireless train controller.

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 4:18 pm
by BorisSpencer
-steves- wrote: Tue Jul 02, 2019 3:47 pm One of the down sides is only 10 steps for control. Do you know if this can be changed later on to a much greater number, like 100?
You're stuck with the codes the android app is transmitting.
But looking at the example code, it wouldn't take much of a change to use one of the on-off switches as a 'gear selector' to add more granularity to the speed control. Effectively giving a high and low range.

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 4:41 pm
by philipy
idlemarvel wrote: Tue Jul 02, 2019 4:11 pm
philipy wrote: Tue Jul 02, 2019 6:07 am ...However, a couple of quick questions first -
1) is it necessary to have a fully working smart phone for the Bluetooth side of things to function, i.e with a valid SIM card installed? The reason I ask is that I don't possess such a beastie, but cheap 2nd hand units are available and might be worth the investment as long as I don't also have to fork out for a SIM account ( what did you say about being a cheapskate??).
...
You don't need a SIM card at all to use the bluetooth feature of a phone, same applied to wifi. I use an old SIM-less iPhone 4 as my wireless train controller.
Thanks Dave.

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 5:09 pm
by BorisSpencer
BorisSpencer wrote: Tue Jul 02, 2019 4:18 pm
-steves- wrote: Tue Jul 02, 2019 3:47 pm One of the down sides is only 10 steps for control. Do you know if this can be changed later on to a much greater number, like 100?
You're stuck with the codes the android app is transmitting.
But looking at the example code, it wouldn't take much of a change to use one of the on-off switches as a 'gear selector' to add more granularity to the speed control. Effectively giving a high and low range.
Apologies for quoting my own post, it also wouldn't take much to smooth the transition between the 10 increments at the Arduino end, i.e. multiple steps between speeds. The 10 increments are probably because we are looking at software orininaly scoped to control basic track-powered 00 locos.

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 5:30 pm
by tom_tom_go
I believe Apple phones need a Sim card initially to boot up when new but after that you can take the Sim out and use it on Wi-Fi.

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 6:11 pm
by ge_rik
Steve has already produced an app with 18 speed steps. What appeals to me is you can have two different speed profiles for each loco. The motor driver has two outputs so it's possible to switch from one to the other. Hence I could have 18 steps with a low top speed for shunting and then another profile with a higher top speed. See -



Rik

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 6:30 pm
by ge_rik
-steves- wrote: Tue Jul 02, 2019 3:47 pm Rik
I love this idea and think it looks very funky. It's certainly cheap and for that is quite appealing.
One of the down sides is only 10 steps for control. Do you know if this can be changed later on to a much greater number, like 100?
Secondly, will this only work with a 12v ish supply? What about loco's running 18v or indeed 3v?
Cheers
Steve
Theoretically it should be possible to get up to 255 speed steps. As mentioned above, Steve has already produced an app with 18 steps. It's surprising how the steps aren't noticeable except at lower speed settings. I'm going to experiment with more profiles as the default top speed is too high for my railway.

The motor shield can handle 5v - 46v and 2A per channel (there are two) so, apart from the lower end, it should be ok for most of our needs. There are other motor shields with different characteristics, so there will probably be one suited to controlling lower voltages.

Rik

Edit: Just realised that the Arduino needs 5v for its logic circuits and so that's the minimum voltage you could have in your loco. Regarding the control of a loco with a 3v motor - you could just tailor the speed profile to keep the maximum speed realistic.

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 6:41 pm
by metalmuncher
With regards to the lack of tactility, it looks like it should be pretty straightforward (for anyone with the prerequisite knowledge) to make a transmitter like the common knob-and-reverse-switch type that works over the bluetooth link.

I have been playing with alternatives to the usual Deltang type setup for a while, in an attempt to keep the costs down. My latest messing about has brought me to cheapo chinese clone NRF24L01+ modules, with these you get a 2 way radio link for £2. I built a transmitter that is basically an Arduino with built in radio module, USB LiPo battery charger, OLED screen and buttons for menus, reverse switch and speed knob, photo attached. Would be relatively easy to use a bluetooth module instead of an NRF24.

On the other end, I wanted an integrated solution to radio control, motor driving and sound effects. I managed to get an AVR playing multiple sound files off an SD card at the same time, and another one sorting the radio and motor control, but when it came to integrating both functions into one little 8-bit chip... I was asking too much of either it, or my programming skills. Now looking into more powerful alternatives that also don't break the bank...

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 7:29 pm
by ge_rik
metalmuncher wrote: Tue Jul 02, 2019 6:41 pm With regards to the lack of tactility, it looks like it should be pretty straightforward (for anyone with the prerequisite knowledge) to make a transmitter like the common knob-and-reverse-switch type that works over the bluetooth link.

I have been playing with alternatives to the usual Deltang type setup for a while, in an attempt to keep the costs down. My latest messing about has brought me to cheapo chinese clone NRF24L01+ modules, with these you get a 2 way radio link for £2. I built a transmitter that is basically an Arduino with built in radio module, USB LiPo battery charger, OLED screen and buttons for menus, reverse switch and speed knob, photo attached. Would be relatively easy to use a bluetooth module instead of an NRF24.

On the other end, I wanted an integrated solution to radio control, motor driving and sound effects. I managed to get an AVR playing multiple sound files off an SD card at the same time, and another one sorting the radio and motor control, but when it came to integrating both functions into one little 8-bit chip... I was asking too much of either it, or my programming skills. Now looking into more powerful alternatives that also don't break the bank...
Really interesting stuff - you read my mind - I've got some NRF24L01+ modules on order and am just researching a Bluetooth equivalent. Gregh has been playing with 8-pin Picaxe chips for quite a few years and is experimenting with controlling sound files from an SD card as well as controlling the speed. You probably have a lot in common.

My programming skills are acquired purely on a need to know basis - trouble is I sometimes don't know what I don't know ..... :?

Rik

Edit: Just discovered that the HC-05 Bluetooth module is in 'slave' mode by default but can be reprogrammed into 'master' mode. Time for a play....

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 7:48 pm
by philipy
ge_rik wrote: Tue Jul 02, 2019 7:29 pm
trouble is I sometimes don't know what I don't know ..... :?
My trouble is that I know I just don't know enough!

Funnily enough, I was mentally playing around with this whole concept earlier this afternoon. I had seen that Steve had an 18 step version and my gut instinct said that there ought to be a way to build "a bluetooth transmitter with knobs", but my trouble is that I wouldn't actually know where to start. What Rich has just described sounds like a practical version of my gut instinct, even if he still wants to do more development.

Re: Initial experiments with Bluetooth and Arduino

Posted: Tue Jul 02, 2019 7:51 pm
by ge_rik
BTW - Just went strolling off down the street with my phone and put the loco on a length of track on the front lawn. I got a range of 46m (well 46 large strides). So should be adequate for most modest gardens.

Rik