Jump to content
 

Arduino wifi control


thegavs
 Share

Recommended Posts

For reasons of what must be best described as insanity I decided not to use the conventional control systems for the gauge3 items I am working on.  With hindsight I might have actually got stuff finished if I did not go down this route.  I wanted to use my phone or tablet to control locos signals and other bits.

 

I thought I would start a new thread to update all am happy to share any code as well.

 

The system so far is as follows.

 

A Raspberry Pi3 running openhab2 a open source home automation server.  This runs a webserver that phones,  tablets and PC can connect to.  it also has a rules engine that could be used to automate things as well.  

 

post-13823-0-15970500-1496683388_thumb.png

 

This is the PC version

 

post-13823-0-15851700-1496683437_thumb.png

 

This is the phone version.

 

The Raspberry can also integrate with voice control such as Amazons echo, as well as controlling lighting.

 

 

In theory it should be possible to write an addon to include DCC or radio control.

Link to post
Share on other sites

BLDC motor control.   Am working on using brushless DC motors.  In Gauge3 there is room for these motors.  They are cheap powerful and do not in theory do not need a gearbox.  About a year ago I hacked togther a proof of concept and was able to drive 12 wagons with 2 motors slowly.  However at that stage did not have the wifi control working.

 

A year on am getting closer.

 

post-13823-0-80501300-1496684053_thumb.jpg

 

To the right is a Nodemcu running arduino code that acts as a wifi controler linking into the openhab2 server on the raspberry Pi3.  This then communicates with the Arduino UNO that just does the motor control.   Putting the motor control on the nodemcu causes pauses when accessing the wifi, it maybe the later esp32 chips are fast enough to get over this.  Between the 2 is a triple half bridge that amplifies the UNO output to 12v from the battery pack.  One advantage of this system is many motors can be connected to the amplifier and will always turn in sync.

 

Next step is to remove the UNO and replace with a Attiny85

Link to post
Share on other sites

Next step is to remove the UNO and replace with a Attiny85

You might like to consider the Attiny1634 - most of the power of an Atmega 328 in a smaller package. On the other hand there must be plenty of room in a Gauge3 loco for an Atmega 328 and then the exact same code from the Uno could be used.

 

This sounds like an interesting project. How many locos do you need to control?

 

Am I correct to assume that the NodeMCU acts as a client calling on the server in the RPI?

 

I considered using ESP8266 modules for 00 Gauge BPR/C but concluded that it would be difficult to guarantee reliable control for several trains (like a dozen or so) using WiFi if each one was to receive, say, 10 messages per second and use the absence of messages as a fail-safe. I'm guessing there won't be a need for control of a large number of Gauge 3 locos.

 

...R

Link to post
Share on other sites

Will take a look at the Attiny1634 as am strugglng with the attiny85 already.  Space is not really an issue in gauge3 but need to find something a bit smaller than the UNO, I might just use another nodemcu and disable the wifi on it.  The nodemcu uses MQTT protocol to communicate with the Rpi which broadcasts instructions.  Effectively it broadcasts just the speed and direction and the nodemcu keeps repeating that until it hears otherwise.  It would be possible to program in fail safes but as of yet have not done that.

 

The plan is to use it with a handfull of locos but in theory it should be able to handle a lot more.

 

G

Link to post
Share on other sites

As you've got plenty of space, why not use an Arduino Nano or Pro Mini? I'm more or less following what Robin is doing with RC in OO, but as I'll be working in O gauge, I've bought some Pro Minis to (hopefully) make things easier.

Link to post
Share on other sites

 Effectively it broadcasts just the speed and direction and the nodemcu keeps repeating that until it hears otherwise

I am trying to learn here. I don't associate "broadcast" with WiFi. In my mind a web server sits there silently until it receives a request. I am assuming your nodemcu makes that request at periodic intervals?

 

Or have I got it all wrong?

 

...R

Link to post
Share on other sites

[edit: it helps to look beyond the comfort zone for bargains. Here's a link for 10 Pro-Mini's for about a tenner]

I bought three through AliExpress, for a bit more than that, as I wanted 3.3 volt ones that seem to be more expensive. I didn't feel any discomfort, and will do it again when I'm sure of what I need!

Link to post
Share on other sites

there's another program running underneath it (the actual DCC command station) that broadcasts DCC packets via WiFi.

I wonder if you have a link where I could read more about that?

 

...R

Link to post
Share on other sites

I wonder if you have a link where I could read more about that?

 

...R

 I am using MQTT protocol to comunucate between the Rpi and the nodemcu.

 

https://en.wikipedia.org/wiki/MQTT

 

http://www.hivemq.com/mqtt/

 

Basically its a very light weight protocol ontop of TCP.   

 

The server publishes information and the client subscribes to that connection.

Link to post
Share on other sites

  • 2 weeks later...

Quick update.   I took the system and a demo signal to the Great Central Railway model exhibition to test it on a gauge3 lay Wharton Road which is 92 feet long.  With the wifi hub at one end and the phone and signal at the other it worked fine.   So well I went for a walk as far as I could go.  250 feet and it was still working fine!

 

No problems with range then.

Link to post
Share on other sites

Your latest Post has prompted me to do the reading I had planned in Reply #11 :)

 

Is your MQTT broker is running on your RPi? Or are you using some commercial web based service?

 

And am I correct to think that at the exhibition your smartphone was connecting to the WiFi hub?

 

I'm really trying to get a feel for the pathways that the messages need to take.

 

Thanks.

 

...R

Link to post
Share on other sites

Thanks. I am trying to figure if there would be any advantage for me if I were to switch from using an Attiny1634 plus nRF24L01+ transceiver to using an ESP8266-12 as the MCU + wireless in my 00 Gauge locos.

 

Previously (before I knew about MQTT) it seemed unlikely that the WiFi system would perform as well when there are several locos to control but the MQTT system seems to be capable of 1000s of messages per second. Of course I don't know if the WiFi hub would be a bottleneck.

 

...R

Link to post
Share on other sites

Only one way to find out!

Yeah. But it would be nice to have some prior expectation that the trial would be worth the trouble.

 

I have come across lots of info about the throughput in bits-per-second but I have not been able to find any benchmarks where someone tested the turn-around time for a useful message of (say) 10 bytes. It is very easy to do that sort of test with a serial connection or an nRF24 but not so easy with WiFi. I would need to buy some ESP8266s, connect them to a breadboard, learn how to program them, learn how to install and setup the broker etc etc.

 

My overnight mental arithmetic leads me to think the throughput for WiFi will be much the same as for the nRF24. If I thought it would be (say) 5 or 10 times better the exploration would be definitely worthwhile.

 

...R

Link to post
Share on other sites

More reading and some testing with Python leads me to think it may be straightforward to use UDP multicasts to get the same effect with WiFi as I have been achieving with the nRF24s - but with less hardware and software. My tests suggest that the throughput would be about the same as with the nRF24. I may take the plunge and buy a few ESP8266-12 modules for tests.

 

...R

  • Like 3
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...