A new arduino for servos?

Shdwdrgn Mar 21, 2018

  1. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    I ran across this board today while looking at arduinos on ebay, but I have also seen it listed on Amazon. The board is called a "Nano Strong" and is produced by DIY More. This is a square board with all of the I/O pins arranges around the parameter and includes a micro-USB port for direct flashing.

    What really caught my eye here is that all of the I/O pins are arranged with complementary power and ground pins, looking exactly like the pinout of a typical servo motor. Onboard power is processed through an AMS1117 5V chip which means it would be limited to around 1.0A of power. I know the little 9g servos I work with draw around 220mA each while running, which would quickly overpower this little regulator. However I don't see any problem with feeding a regulated high-current 5V supply through the USB port or perhaps cutting a trace or two to allow for a direct power supply feed to the servos.

    I've been playing with Geoff Bunza's DCC accessory code lately and it looks to me like if the current draw problem could be solved then there are 22 I/O pins available on this board (one of which would need to be the DCC input channel), leaving the potential for driving up to 21 servos without any addition hardware.

    I'm going to go ahead and order one to play with, but I'm wondering if anyone else has gotten their hands on this board and tried to run a servo with it? If it works, this could be a nice compact solution.
     
  2. KE4NYV

    KE4NYV TrainBoard Member

    219
    281
    17
    I bought several of these to match up with some Raspberry Pi Zero W's. RocRail is supposed to support it via TCP/IP. I'm considering running my layout primarily via JMRI, but running all of my turnout control through RocRail. With this servo interface, I can reduce the price per turnout by using low cost servos and some simple brackets on all yards and industries. I'll save my tortoise motors for all main line turnouts. It's just an idea for now, but the initial cost is pretty low. $3 for the servo board, $25 for a RPi Zero W and servos at around a $1 each.

    https://www.ebay.com/itm/12-bit-For...552519?hash=item569dea1a47:g:tqkAAOSw539ZbeDx
     
  3. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    I'm using that same board at the moment along with a modification of Geoff's AccDec_10Servos_7LED_6Ftn sketch. The original idea was to provide 16 I/O ports from the arduino plus 16-32 servo ports, however I think there's a conflict with providing enough CV's for 32 servos (I had to move the first device to start at CV15, but it looks like there are some required CVs between 15-29 including CV29). I'm going to build a new version of the code today that starts the I/O CVs back at 30 again, which still leaves me the possibility of 13 I/Os and 32 servos. Once I can get it working to write the CVs again I'll post the code. Other than the CV issue the code is working nicely with some SG90 servos, with the CVs controlling the range of speed of each.

    I'm curious what part the RPi zero's are meant to play in your setup? I'm using a single Rpi3 on mine to provide DHCP and DNS for an isolated network, with DCCppESP32 as my base station, but otherwise I'm just using an arduino by itself as an accessory decoder and plan to use ESP32's onboard the locos as DCC decoders. It sounds like you're planning to use the Zero as part of your accessory decoders, which seems like an awfully expensive way to go?
     
  4. KE4NYV

    KE4NYV TrainBoard Member

    219
    281
    17
    So, right now I'm throwing around all kinds of ideas. Honestly, a $25 RPi Zero W and a $5 board to control 16 servos is pretty good per turnout. I also like that it's wireless for the control and I can place it anywhere under the layout. This is all theory, of course. I'm thinking I'll create a separate subnet for either control of the entire layout. I like being able to remote desktop into the Pi 3 I have running everything now to make changes. I want to retain that ability. Especially when I'm sitting in my living room, watching TV and I just want to make some tweaks without having to go upstairs into the train room ;)

    Another side of this is learning to decode DCC in a microprocessor. I recently designed/built a board to extract DCC to a simple 0-5V TTL signal that can be fed into a PIC or similar processor. We should put our heads together and work on somthing:

    [​IMG]

    [​IMG]
     
  5. ECLR

    ECLR New Member

    2
    0
    7
    HI, I have not been active on this forum for a long time, but thought I would catch up.
    I use Rocrail and have made some universal wifi interfaces for use on my garden layout.
    Each module, (which costs about $10, from EBay or the like) provides 8 universal IO, usable as inputs, outputs, servo drives or PWM modulated outputs.

    The modules use standard ESP8266 esp-12 modules, best bought as "NodeMCU" boards that include the necessary USB interfaces. I also bought NODEMCU Motor drive boards as these have a useful high power drive, but also provide a row of RC servo type three pin connections that give easy connection to hall sensors, servos etc.

    To provide 5V to the servos, an external 5V regulator is added to the Vcc line (powered from the V motoor) and small modification is needed to cut the provided 3v3 to the line of pins and connect it to the 5V line.

    Other than this, the modules are completely as purchased.
    The second photo shows the board with a servo, hall sensor to sense the trains, and a led.

    The code (and instructions on how to program the module) is available here: https://github.com/dagnall53/ESPMQTTRocnetSound

    There is also a version of the code for "mobile" decoders, ie locos, that provides PWM motor control and two track sounds based on sampled sounds.

    Hope you like this
    Dagnall





    NodeMCU Mods (1).jpg

    IMG_1918.JPG
     
    Last edited: Apr 2, 2018
  6. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Sounds like everybody has projects going!

    @KE4NYV - nice little board there. What chip are you using to decode the signals? I have seen a sketch for reading DCC on an ATtiny85 chip which I would have loved to use for my servo decoder, but since that chip doesn't have a hardware I2C interface there could be timing issues between handling both DCC and I2C. Ah well, I'll probably still give it a try some time.

    @ECLR - have you seen the PCA9685 board? It uses two lines for I2C to control 16 12-bit PWM outputs such as for running servos, and it can be daisy-chained for up to a total of 992 servos. That is what I am currently using on an arduino and it leaves all the other pins free for LEDs and such. I've never used a NodeMCU but I have used the bare ESP8266-12 boards. If you run into any problems with signal strength try switching up to an ESP32, they seem to have a stronger radio in them (not to mention all the other numerous goodies!).
     
    KE4NYV likes this.
  7. KE4NYV

    KE4NYV TrainBoard Member

    219
    281
    17
    I started off with a PIC18F252 as my intended platform, but right now I am messing with some code I found for the Arduino. I'm not exactly a big fan of Arduino for projects that I could potentially turn into products. I like knowing the code I am "selling" in a product was written by me or at least internal to my company. More of an ethics thing for me. The snippets I found are in C, so I am hoping to port some of the crucial routines over to PIC C and then build on that. The other night I added an LCD and had it displaying the DCC bus packet status, current loco number, accessory number, ect. Was working well and then I started getting a problem with the Arduino locking up when it would try to return to the packet parsing routine. I didn't change anything in there, but something broke. Still playing around with that. I like the idea of a simple status display panel that can be added to any DCC layout to tell you current DCC information ie. current locos in action, accessory toggles, ect.
     
  8. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Both of you might be interested in the DCCppESP32 base station project. I am currently running that using a clone board that is marked as Wemos Lolin32, but it includes a 128x64 OLED display on it. I get them from ebay for about $10.50 and the project is written to display info for this size of screen. The output isn't ideal but it does show key things like the number of connected throttles, active locos, and current draw on the mainline and programming tracks. It also provides a wifi connection which allows me to telnet in and manually enter commands, plus provides a web page throttle and status that I can connect to from my phone. The web page is pretty bare-minimum at the moment but someone is working up building an update (which I home includes formatting for mobile devices). What I am hoping to see, or build myself later, is an ESP-based mobile decoder that can read DCC over wifi and send output to an S88 bus.

    So of course building from this code might not be anything you can sell, but it's still an interesting project and might give you some ideas.
     
    Atani likes this.
  9. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Hey the new boards came in today! Unwrapped one and plugged it into USB and a fast-blink sketch appears to have started right up. So a few things of note right awake...

    - This board uses the atmel328p, although I can't tell if it is 5v or 3.3v. I'm thinking the 3.3v is more likely since the board contains a 3.3v output connector, except that it is also listed as having a 16Mhz clock.
    - The board also takes a power input of 7-16VDC, so with a little filtering and a slight drop in voltage I might be able to run it directly from track power. (On reflection I need a dedicated 5V supply anyway to provide current for the servos, so scratch that.)
    - Having up to 8 servos plugged in a row is going to be an issue... the servo plugs have a wide top and start spreading out in an arc with more than a few in a row.
    - Unlike the pictures show, the ground headers actually go to the *outside* of the board, which is good because it is less likely that an accidental short will fry an I/O pin on the MPU. (There is a clear ground plane around the outer edge of the board which also connects the corner mounting holes.)
    - The board is 1 and 9/16" square (40mm), which is a pretty nice size if I can get servos running on even half the pins.

    So I think the first thing to do is build an inline cable with an optoisolater and make sure I can read DCC signals, then solder on one set of headers and see if I can run a single servo.

    There is a nice heavy trace on the back of the board running the 5V power to the headers so eventually I need to attempt to connect a power source directly to that. If it is routing the way I think I see it, I can purposefully make a notch in the trace before it feeds to the headers, acting as a fuse point so if the servos pull too much current I just pop a small section of trace instead of destroying the whole board., but I need to figure out how many servos I can run simultaneously and under load. Unless someone happens to know a calculation for home much current a specific trace width can carry at 5VDC?
     
  10. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Quick update... initial hardware build is done but it's getting late. I built up the who optoisolator circuit right on the chip itself and then wrapped it in heatshrink tubing. Still have to find another piece of tubing that fits the connector and yellow wire. I thought it would make it easier if I designed it to fit straight on the existing header rows on the board. I should be ready to load in a sketch and hook it to the tracks though.

    [​IMG]

    Hmm camera lens are funny things. The opto bundle looks a lot bigger here than it really is but I was rather close when I took the pic.
     
  11. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    And it's up and running! I ran into a problem right after my last message in that I was unable to actually write my sketch to the board. I thought selecting an arduino pro mini would be appropriate since it listed the atmega328p chip, but nope, not quite close enough. Turns out you can just select the standard arduino nano and THAT setup is compatible with programming this board.

    I thought I had all this DCC stuff down now, but mistakes will still happen. I set a new address for this board, adding in a couple turnout definitions for the new address range, and tried to operate one of the servos... nothing. A lot of back-and-forth comparing the atmega328 pinout with a nano pinout, and referencing what I could see of traces on the new board. I finally figured out why the DCC pin is so particular when folks are using one of the atmega328 boards -- there's only two external interrupts available! Yeesh ok so my only choices for the DCC signal are pins 2 or 3. Got that set up in the code but still didn't receive any commands. Finally loaded up Rudy's sniffer and discovered my error -- on the table I had typed up to convert full addresses to the DCC++ two-byte convention I had repeated some number, so instead of using 25-3 for address 100 I had instead entered 15-3. Put Geoff's accessory decoder back on the board and corrected my turnout entry, and woo-hoo we're up and running! I have a couple servos plugged into the board now and it will move both of them through their range, so the board and the USB port provide plenty of power to drive a single servo at one time, at least.

    I had a thought about getting enough current around the board to all the servos though. If the header spacing requires me to leave at least one gap between servo plugs on all three banks, what if I used the empty spot as a power *input*? Basically add a 5V feed to the red/black header pins in the middle of each row. That would greatly reduce the path that the 5V current needs to follow along circuit board traces so I shouldn't have to worry about blowing any of those traces, nor modifying the board itself in any way. Although I do need to check if I actually can power the board directly through those red headers...

    I did find one other limitation. A6 and A7 are exposed through the headers, but apparently those pins are analog-only, so there's a good chance I may not be able to run the servos from those two positions. Even so, when counting up the pins I still have available after counting the extra power pins and the DCC input, I still believe I can run 18 servos from this board, and that's nothing to sneeze at!
     
  12. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Pins 0 and 1 are also not easily available, since they are dedicated to the serial port. Supposedly they will work fine as I/O if you don't initialize Serial, but I think that's kind of handy to have. Ah well, down to 16 pins available, right? NOPE! It turns out I can't count. There's actually 17 pins still available. I'm using D3-D13, and A0-A5, and plan to supply power on the header at D0 or D1, AREF, and A6 or A7. However I believe I'll limit it to 16 servos per board simply because I'm used to counting in multiples of 16 due to extensive computer work so it makes it very easy for me to remember the addressing.

    I put in an order last night for a bunch of surface-mount components. I want to try building a smaller version of the inline DCC signal reader. I've noticed in a lot of discussions on this board regarding DCC++ that most people seem to be interested in plug&play solutions and it seems like a small module like this would go a long ways towards allowing people to just jump right into a DCC++ type of setup. So we'll see how that goes...
     

Share This Page