Initial experiments with Bluetooth and Arduino

A place for discussing battery-electric locomotives, whether they're diesel, steam or even electric outline
User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Tue Jul 02, 2019 6:30 pm

-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.
Last edited by ge_rik on Tue Jul 02, 2019 7:22 pm, edited 1 time in total.
------------------------
Peckforton Light Railway - Blog Facebook Youtube

metalmuncher
Cleaner
Cleaner
Posts: 95
Joined: Sat Oct 20, 2012 4:15 pm

Re: Initial experiments with Bluetooth and Arduino

Post by metalmuncher » 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...
Attachments
IMG_20190702_181222.jpg
IMG_20190702_181222.jpg (80.52 KiB) Viewed 4889 times

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Tue Jul 02, 2019 7:29 pm

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....
Last edited by ge_rik on Tue Jul 02, 2019 8:49 pm, edited 1 time in total.
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
philipy
Moderator
Moderator
Posts: 5033
Joined: Sun Jan 30, 2011 3:00 pm
Location: South Northants

Re: Initial experiments with Bluetooth and Arduino

Post by philipy » Tue Jul 02, 2019 7:48 pm

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.
Philip

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Tue Jul 02, 2019 7:51 pm

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
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
philipy
Moderator
Moderator
Posts: 5033
Joined: Sun Jan 30, 2011 3:00 pm
Location: South Northants

Re: Initial experiments with Bluetooth and Arduino

Post by philipy » Thu Jul 04, 2019 10:09 am

Rik, not sure if you are interested ( it's not Arduino or Bluetooth!) but I've just found a long and detailed thread, with code, for using NRF240L01+ with Picaxe, on the Picaxe forum.
https://picaxeforum.co.uk/threads/using ... les.19036/
Philip

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Fri Jul 05, 2019 8:26 pm

philipy wrote: Thu Jul 04, 2019 10:09 am Rik, not sure if you are interested ( it's not Arduino or Bluetooth!) but I've just found a long and detailed thread, with code, for using NRF240L01+ with Picaxe, on the Picaxe forum.
https://picaxeforum.co.uk/threads/using ... les.19036/
I might well be interested later on. For the moment I'm still exploring Bluetooth, but when I've got as far as I want to with it, I'll start exploring more traditional RC including the nrf240 and maybe even using the Bluetooth module in a tx with knobs and switches.

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
philipy
Moderator
Moderator
Posts: 5033
Joined: Sun Jan 30, 2011 3:00 pm
Location: South Northants

Re: Initial experiments with Bluetooth and Arduino

Post by philipy » Sat Jul 06, 2019 2:26 pm

ge_rik wrote: Fri Jul 05, 2019 8:26 pm when I've got as far as I want to with it, I'll start exploring more traditional RC including the nrf240 and maybe even using the Bluetooth module in a tx with knobs and switches.
Subsequent to my post I found a site of a guy who has got arduino, and the Tx-Rx 2.4gh modules, with speed knobs and steering joysticks , working for R/C cars, Should be easy to swap switches for joysticks and use them for bells and whistles instead of steering. Let me know if you want the links.
Philip

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Mon Jul 08, 2019 10:34 am

Further dabblings. I'm now using another app called RoboRemo, which enables me to design my own controller. I've also changed the coding so I get a much wider range of speed steps - but these seem to depend on the PWM setting I use. Steve Massikker uses 122.5Hz, which makes the loco growl especially at low speeds. The Arduino default value is 490Hz, which makes it whine. I've now discovered how to vary the PWM setting and so here's how the loco behaves on 12kHz and 8kHz.



I'm playing around with the SD Player which Tom mentioned and Greg has been playing around with. I'll post where I'm up to when I get it to behave itself..... :?

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
philipy
Moderator
Moderator
Posts: 5033
Joined: Sun Jan 30, 2011 3:00 pm
Location: South Northants

Re: Initial experiments with Bluetooth and Arduino

Post by philipy » Mon Jul 08, 2019 1:16 pm

Certainly looks nice, smooth control Rik.
Not sure about the noise, tbh. I suspect that my sound set up may be distorting things, I didn't really get a whine, but I did hear what sounded not unlike a London Underground train, at one point!
Philip

User avatar
GTB
Driver
Driver
Posts: 1550
Joined: Sat Mar 05, 2011 2:46 pm
Location: Australia

Re: Initial experiments with Bluetooth and Arduino

Post by GTB » Mon Jul 08, 2019 2:27 pm

ge_rik wrote: Mon Jul 08, 2019 10:34 am I've now discovered how to vary the PWM setting and so here's how the loco behaves on 12kHz and 8kHz.
Most human hearing goes up to about 20kz, although sensitivity at the higher frequencies drops off as you get older. From memory 'silent drive' DCC decoders run above 15kHz.

I can hear the buzz from the PWM at both 8 and 12kHz in your video (that or it's gear noise). I read somewhere that an Arduino board can get into the supersonic PWM frequency range, but you'd need to check the H-bridge driving the motor can handle those frequencies as well.

Regards,
Graeme

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Tue Jul 09, 2019 8:55 am

GTB wrote: Mon Jul 08, 2019 2:27 pm
ge_rik wrote: Mon Jul 08, 2019 10:34 am I've now discovered how to vary the PWM setting and so here's how the loco behaves on 12kHz and 8kHz.
Most human hearing goes up to about 20kz, although sensitivity at the higher frequencies drops off as you get older. From memory 'silent drive' DCC decoders run above 15kHz.

I can hear the buzz from the PWM at both 8 and 12kHz in your video (that or it's gear noise). I read somewhere that an Arduino board can get into the supersonic PWM frequency range, but you'd need to check the H-bridge driving the motor can handle those frequencies as well.

Regards,
Graeme
Hi Graeme
Yes, still get buzz at low speeds on both settings. I might try increasing the frequency to see if it disappears. One thing I have found is that increasing the frequency seems to diminish the range of speed settings to which the motor responds. I get a range of 0 - 255 from the slider on the app and at lower frequencies (eg 490Hz) I can use the full range - though the motor doesn't start until about 40. When I set the frequency to 8kHz, the usable range of steps drops to 70 - 130. At 12kHz, the range drops further from 80 to 120. Not entirely sure why.

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
tom_tom_go
Driver
Driver
Posts: 4824
Joined: Wed Feb 23, 2011 3:08 am
Location: Kent, UK
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by tom_tom_go » Tue Jul 09, 2019 9:07 am

Would using capacitors on the motor help reduce noise?

User avatar
GTB
Driver
Driver
Posts: 1550
Joined: Sat Mar 05, 2011 2:46 pm
Location: Australia

Re: Initial experiments with Bluetooth and Arduino

Post by GTB » Tue Jul 09, 2019 10:40 am

ge_rik wrote: Tue Jul 09, 2019 8:55 am One thing I have found is that increasing the frequency seems to diminish the range of speed settings to which the motor responds.
The higher the pwm frequency, the more like DC it becomes, so the motor starting voltage increases. That may be what you are seeing.

When DCC went to 'silent' decoders, they had to add some form of kickstart to improve slow running. Or they changed to back emf control, which is effectively a cruise control.

Regards,
Graeme

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Tue Jul 09, 2019 1:49 pm

Latest developments. I've now incorporated sound from a small SD Player module. The tracks are played either in response to key presses on the app (ie the horn and the engine start / stop) and the speed setting determines which of three tracks play (idle, slow speed, fast speed). Not yet perfect. The sound files need a bit of tinkering, but the principle seems to work OK.

Had to revert to the default PWM setting of 490Hz as the PWM library in the Arduino compiler developed a fault.

Getting there ... albeit slowly!



Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
FWLR
Driver
Driver
Posts: 4262
Joined: Sat Aug 05, 2017 9:45 am
Location: Preston, Lancashire, UK

Re: Initial experiments with Bluetooth and Arduino

Post by FWLR » Thu Jul 11, 2019 9:09 am

Well I think it's great Rik. :thumbright: :thumbright: The engine idle and running is far better than some. The horn maybe needs tweaking a bit and the start timing may just need altering, but a man of your skills will no doubt overcome such things.

This is the same comment I have put on your Youtube channel. It's not because I can't be bothered to write anything. It's, I can't think of anything else to say about how fabulous it sounds, oh I just have.... :lol: :lol:

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Sat Jul 13, 2019 12:32 pm

I think I've improved the sound files - though maybe you should be the judge.

.
I've blogged what I've done here just in case anyone ever wants to have a try themselves:
https://riksrailway.blogspot.com/2019/0 ... art-4.html
.
I think I've more or less finished my experimentations with Bluetooth and phone apps. It might be because I am not an avid user of a mobile phone, but I do find using a phone to be a nuisance compared with a handheld transmitter. Not only is it hard to see the screen but I find it all too easy to press one of the buttons on the side of the phone and switch the darn thing off - usually at a critical moment. I'm sure it would be possible to pair more than one loco with the app and switch from controlling one to the other, but my Deltang Tx22 does that quite easily, so I can't see it is much of an advantage. I suppose the real advantage is that it's possible to equip a loco with Bluetooth control and sound for just under £20 (plus the cost of the batteries - another £5) - even cheaper if you get your gear directly from China.

Anyway - my dabblings (ie circuitry and programming codes) are there for anyone to play around with if you're more tech-savvy than me.

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

User avatar
FWLR
Driver
Driver
Posts: 4262
Joined: Sat Aug 05, 2017 9:45 am
Location: Preston, Lancashire, UK

Re: Initial experiments with Bluetooth and Arduino

Post by FWLR » Sat Jul 13, 2019 1:10 pm

Thats superb Rik. A vast improvement on your last version. The start up and moving off is fantastic and the horn even sounds better as well. Thanks for giving us an in-site into Bluetooth control. If somebody with your talents think it's better with traditional remote control, who am I to disagree.... :roll: :roll:

But if you what to move the loco or even the electronics with the SD Card, I will gladly take it off your hands........ :lol: :lol: :lol: :lol:

User avatar
tom_tom_go
Driver
Driver
Posts: 4824
Joined: Wed Feb 23, 2011 3:08 am
Location: Kent, UK
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by tom_tom_go » Sat Jul 13, 2019 6:11 pm

I believe you should be right chuffed with what you have achieved Rik given you were born in a generation where computers and coding were not mainstream.

Bluetooth (or Wi-Fi, I don't see the benefit or using Bluetooth over Wi-Fi) for controlling indoor layout operation with an app would appeal to me, however, outside in the outdoors l prefer to keep loco running as low tech as possible.

User avatar
ge_rik
Administrator
Administrator
Posts: 6497
Joined: Sun Oct 25, 2009 10:20 pm
Location: Cheshire
Contact:

Re: Initial experiments with Bluetooth and Arduino

Post by ge_rik » Sat Jul 13, 2019 6:38 pm

FWLR wrote: Sat Jul 13, 2019 1:10 pm But if you what to move the loco or even the electronics with the SD Card, I will gladly take it off your hands........ :lol: :lol: :lol: :lol:
Thanks Rod. Although it looks very toylike, it's actually quite useful as a test-bed loco. The three components of the body just clip together, so it's dead easy to take apart to tinker and then put together again.

I'm planning on experimenting with more traditional RC with the Arduino next - so I can make a Tx with a knob, push buttons and a reversing switch - back to more familiar territory.

Rik
------------------------
Peckforton Light Railway - Blog Facebook Youtube

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests