Bluetooth and Arduino

Rhinochugger

Rhinochugger

Retired Oik
27 Oct 2009
28,723
3,458
North West Norfolk
Arduino - can someone advise me on a decent vintage before I get to the wine warehouse tomorrow morning? :nerd::nerd:
 
D

Deleted member 4232

Guest
Moved
 
Last edited by a moderator:
D

Deleted member 4232

Guest
Moved
 
Last edited by a moderator:
M

Michael

Registered
26 Jan 2010
135
16
A very nice solution for indoor model railways that can also be used outdoors. Also, a great way to introduce people to Arduino programming and could easily be used with the ESP8266 and all other similar Arduino IDE compatible processors.

As for the LocoFi wi-fi solution, the phone app is the weakest link (personal experience, a phone to control an outdoor train is useless), but it does make it easy to get started as you only have to play with the receiver.

However, as the protocol is known (from the Arduino sketch) it would be relatively easy to make a transmitter using an Arduino Nano, bluetooth module (HC-05 as master), a few buttons and potentiometer(s) or an ESP32 that has integrated bluetooth as well as wi-fi.

Please note there is a potential problem with the circuit diagram on the ArduinoRailwayControl website. Arduinos have 5 volt outputs and the HC-06 is a 3v3 device. The 3v3 output from the HC-05 will drive the Arduino but the 5 volt output from the Arduino to the HC-06 should be reduced to 3v3 by the use of two resistors (1K and 2k are suggested if you do an internet search). Whilst it obviously works it is bad engineering practice and it is possible you will blow the HC-06.


Michael
 
D

Deleted member 4232

Guest
Moved
 
Last edited by a moderator:
musket the dog

musket the dog

Professional engineer, amateur modeler
31 Oct 2009
680
93
Leicester
nlrr.webs.com
A very interesting piece of kit, I had been pondering over Raspberry Pis and wondering if there was any railway control potential (mainly for points and signalling) but maybe a step back to the Arduino is actually more suitable for a greater number of applications.

I am currently about to invest in acquiring the gear to convert my stock to radio control and had my heart set on the Deltang system. This throws an interesting spanner in the works.

Obviously the initial outlay is less, soldering and basic programming aren't beyond my range of skills. From Rik's experiments range and use outdoors don't seem to be as big an issue as they might have once been with Bluetooth devices (I can happily wonder all over my garden while my phone syncs with my cheapo bluetooth speaker).

I suppose the downsides would be the larger packaging space needed? I imagine finding space for 3 boards and a voltage regulator might be difficult in smaller locos or ones less boxy by design.

Additionally what happens if you introduce two systems? Can the app switch between the two individually, or would it be a case of resyncing and using a single loco at a time?
 
D

Deleted member 4232

Guest
Moved
 
Last edited by a moderator:
  • Like
Reactions: 1 user
D

Deleted member 4232

Guest
Moved
 
Last edited by a moderator:
M

Michael

Registered
26 Jan 2010
135
16
I am currently about to invest in acquiring the gear to convert my stock to radio control and had my heart set on the Deltang system. This throws an interesting spanner in the works.

If you need to make your decision now, I would say go with Deltang until this bluetooth system is proven. I've been using Arduinos in locos outdoors since 2013 so I have a lot of experience. Picture from 2013 of Accucraft Lyn controlled by an Arduino Nano and nrf24l01 wifi board with an Arduino Uno in the 'smart' brick, as I called it :)
P1010769.JPG
Now whilst I have no experience of bluetooth, I know that connectivity is the main issue in the garden and that whilst it might work so many metres on a bench, when you stick it in a loco, especially a metal one, it's a different matter.

The Arduino/nrf24l01 combination worked but the range was bad, 5 - 10 meters at best.

In 2018 I switched to the ESP8266 which has an integral wi-fi chip and a Tenda router and it is now working happily in my 7 locos and 2 wagons, around a track that is 70 foot long.

I would therefore say that you need to prove that this bluetooth solution works reliably in a metal loco around a large garden before investing too much time or money in it.

I have an HC-06 and many Arduino Nanos so would be more than happy to help test it if you wanted. Unfortunately, my phone is a Samsung S4 mini which is Android 4 and the app requires Android 5 and above. My wife won't be too happy if I keep using her newer phone in the garden!

Michael
 
ge_rik

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
9,907
1,077
Cheshire
www.riksrailway.blogspot.com
Corrected diagram,....Bluetooth Power moved from D3....to 5V pin...., resistor voltage divider for correct 3.3V logic level.
Nano will accept up to 12V on it's VIN pin....voltage regulator surplus to requirements.



View attachment 254153

Or, as the Input Voltage is less than 12V, can move jumper on L298 for 5V to supply power to the Nano on the 5V pin.


View attachment 254154
Thanks for your work on this. I must admit to being a belt and braces sort of guy and so, although the li ion pack is nominally rated at 11.1v, when it is fully charged it can exceed 12v, hence the voltage regulator. I wondered if I could use the 5v terminal on the L298 but being new to all this, I wasn't sure.

Rik
 
ge_rik

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
9,907
1,077
Cheshire
www.riksrailway.blogspot.com
If you need to make your decision now, I would say go with Deltang until this bluetooth system is proven. I've been using Arduinos in locos outdoors since 2013 so I have a lot of experience. Picture from 2013 of Accucraft Lyn controlled by an Arduino Nano and nrf24l01 wifi board with an Arduino Uno in the 'smart' brick, as I called it :)
View attachment 254158
Now whilst I have no experience of bluetooth, I know that connectivity is the main issue in the garden and that whilst it might work so many metres on a bench, when you stick it in a loco, especially a metal one, it's a different matter.

The Arduino/nrf24l01 combination worked but the range was bad, 5 - 10 meters at best.

In 2018 I switched to the ESP8266 which has an integral wi-fi chip and a Tenda router and it is now working happily in my 7 locos and 2 wagons, around a track that is 70 foot long.

I would therefore say that you need to prove that this bluetooth solution works reliably in a metal loco around a large garden before investing too much time or money in it.

I have an HC-06 and many Arduino Nanos so would be more than happy to help test it if you wanted. Unfortunately, my phone is a Samsung S4 mini which is Android 4 and the app requires Android 5 and above. My wife won't be too happy if I keep using her newer phone in the garden!

Michael
Interesting stuff, Michael. I've been tinkering with the PWM frequencies on the Arduino to try and cut down motor buzz. What setting do you use?

Rik
 
D

Deleted member 4232

Guest
Moved
 
Last edited by a moderator:
D

Deleted member 4232

Guest
Moved
 
Last edited by a moderator:
  • Like
Reactions: 1 user
PhilP

PhilP

G Scale, 7/8th's, Electronics
5 Jun 2013
26,911
2,780
Tamworth, Staffs.
My wife won't be too happy if I keep using her newer phone in the garden!

"But Darling, it IS a mobile phone.."

<Edit - Friday>
Strange.. I am having a situation where I 'post', but then the article is not there, and text is still in the new post box..
I posted this yesterday, but see it is not in the thread, and the above text still in the new post edit box.

An odd missed post, down to me, but this is now one of a handful of times it has happened over the last couple of weeks?
 
M

Michael

Registered
26 Jan 2010
135
16
Interesting stuff, Michael. I've been tinkering with the PWM frequencies on the Arduino to try and cut down motor buzz. What setting do you use?

It depends if you want a hum or a whistle.:) I adjust the value for each loco as it depends on the motor. Normally I use around 5000 to 8000 Hz but interesting to see that the bluetooth example used 122.5Hz. Does anyone know what frequency Deltang uses?

As per John's post, the options are rather restrictive on an Arduino. It's a bit easier with an ESP8266: analogWriteFreq(8000);
 
PhilP

PhilP

G Scale, 7/8th's, Electronics
5 Jun 2013
26,911
2,780
Tamworth, Staffs.
Does anyone know what frequency Deltang uses?

Default is 'auto' = fastest, which is 12KHz or 16KHz, dependent on model..

It can be altered in programming.. 15Hz makes a motor in a boat sound 'pop-pop-pop'.
 
ge_rik

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
9,907
1,077
Cheshire
www.riksrailway.blogspot.com
Set PWM frequency for D9 & D10
Timer 1 divisor to 256 for PWM frequency of 122.55 Hz
TCCR1B = TCCR1B & B11111000 | B00000100;



Rik, try changing the line above in the program to one of the values below.....

TCCR1B = TCCR1B & B11111000 | B00000001; // 31KHz
TCCR1B = TCCR1B & B11111000 | B00000010; // 3.9KHz
TCCR1B = TCCR1B & B11111000 | B00000011; // 490Hz (default)
TCCR1B = TCCR1B & B11111000 | B00000101; // 30.6Hz
Trouble with that is it only gives a limited range of values it shoots up from 490Hz to 30kHz with nothing in between. I want to play around with 12kHz or 16kHz.

Looks like there's a library which can be included which gives much finer control over the PWM frequencies.


I'm presently giving that a go.

Rik
 
ge_rik

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
9,907
1,077
Cheshire
www.riksrailway.blogspot.com
It depends if you want a hum or a whistle.:) I adjust the value for each loco as it depends on the motor. Normally I use around 5000 to 8000 Hz but interesting to see that the bluetooth example used 122.5Hz. Does anyone know what frequency Deltang uses?

As per John's post, the options are rather restrictive on an Arduino. It's a bit easier with an ESP8266: analogWriteFreq(8000);
I wish they'd include something as straightforward as that in the Arduino coding by default. Even with the PWM library it's a bit convoluted.

Rik
 
Greg Elmassian

Greg Elmassian

Registered
8 Mar 2014
4,417
659
San Diego
www.elmassian.com
Most people quickly went over 12 KHz because of the audible buzzing, thus the introduction of "ultrasonic" PWM.... some motors do run better at a much lower PWM, but it is usually older current hungry ones.

Greg
 
ge_rik

ge_rik

British narrow gauge (esp. Southwold and W&LLR)
24 Oct 2009
9,907
1,077
Cheshire
www.riksrailway.blogspot.com
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