# Even smaller WiFi for a train



## Shdwdrgn (Dec 23, 2014)

I was looking around today and came across an ESP8266-12. If you've been following my other projects, you know I'm currently using an -01 model with an arduino to create a web interface for controlling an HO steam loco. One thing about this conglomerate of hardware, it takes up some space, and I haven't had the time to try and shrink down the wiring to make everything fit inside the coal tender.

So I was surprised to find a model of the ESP8266 which has a number of I/O pins available on it to use. These chips have a full computer onboard and a decent amount of program space, but the -01 only has a couple pins available for I/O and wouldn't have worked by itself for my needs. However the -12 model has several pins available, including full 10-bit ADC converters (such as for sensing track voltage), and PWM outputs (used for controlling the loco motor speed).

I ordered a couple of these to play with, crossing my fingers that this one chip can replace my existing hardware. I'll need to figure out how to provide both 5v and 3.3v supplies to everything, but if this works it will take up about 1/3 of the space of the current boards, leaving only this one board handling all the computing needs, a voltage regulator and diodes to pull power from the track, and a 14-pin chip to control the motor speed.

Yeah, I get excited about playing with new electronics.


----------



## Shdwdrgn (Dec 23, 2014)

I received the modules this week and have been doing a bit more research. So far it looks very promising. The entire module is 16x25mm, and I think around 3-4mm thick. The pinout shows at least 8 I/O pins free for use, possibly more, and there is also an ADC input. Here's what I'm thinking of reserving for general functionality...

Digital output:
- headlight
- reverse-light
- cab light?
- smoke unit

PWM output:
- (2) loco motor
- sound output

ADC input:
- motor current (to detect how much load on the motor)

That still leaves ports available for other purposes, such as track location markers or obstacle detection. And since the wifi is built in, there's no need to use up extra ports for communications or write additional code to transfer wifi commands to the arduino.

Also I didn't mention the significant upgrade in specs when compared to the arduino pro-micro that I've been using... 80Mhz cpu instead of 8Mhz, 4MB flash storage instead of 28KB.

The one disadvantage here is the ESP8266 models do not come with a USB port for programming, however I discovered another possibility this week. Apparently there is code available to pull code over wifi. Basically the ESP8266 has a bootloader installed on it, and it checks the wifi connection for available code when it starts up. So you could have a server set up and make changes to the code on the server, then ALL of the locos would get the updates the next time they start up.

To break it down for those who didn't follow the jargon, you would have a 'server' on the layout (something small like a raspberry pi?). The computer on each loco needs to run a program so it knows what it should be doing, but this program is stored on the server. Each time a loco turns on, it checks for a new program and runs whatever you have given it. All of this is done over a wifi connection. You don't need any special sidings for programming, you just apply power and the loco handles everything automatically.

The pieces I am working with are small enough that I believe they could fit inside an N-scale boxcar, maybe even in an N-scale diesel loco. I'm currently working with HO steamers, but will soon also be putting the same equipment inside HOn3 steamers (thus the need to really reduce the size). I still haven't had a chance to power up the new computer chip, but once I do I will need to re-write all of my code, then I can work on reducing the physical size of components and see just how small I can really get it.

Yeah, I'm still excited about this...


----------

