dcc-sm

I have just started to play with a wonderful new tool, a four channel logic analyzer from https://www.saleae.com/

This is a fantastic unit for the price, I can’t tell you how wonderful it is for doing small scale digital h/w design and firmware. I can literally time my interrupt routines, I’m sporting 5us on a dcc decoder INT routine. Sweet. I also found a really bad firmware bottleneck, I love this thing!

lab-500

Here it is all hooked up to my development system. Atmel Studio 7 drives everything. This is my favorite kind of software development. Right on the metal.

dccdcc-input

Well, if you can’t beat em join em eh? Ha.

Since I’m putting together a new N scale layout, or at least I’m planning it out right now, I decided I should probably give DCC a go since it’s so popular. So I ordered an inexpensive DCC starter set, the MRC prodigy Express2. I am glad I did. Just on a test loop my little DCC switcher locomotive runs WAY better than it did on DC. And since I like the feel of the MRC Prodigy Express DCC controller (more or less), I figured, why not come up with a way to use that to control, via Xbee, for my G scale stuff too?

So after much scouring and searching via Google, I came up with an input and output circuit for my control widget board.

In the above picture you can see the DCC waveforms and the really simple input side of the circuit. I’ve also got my basic C framework built out and this looks like it will be a fun project if I can ever get the time to work on it!

Anyhow, the basic idea here is read the DCC out of the Prodigy output, transmit that via Xbee and decode it on the other end. Or pass it through, or both. That way you can use any DCC handheld you want to control battery powered locomotives or even live steam ones (via intercepts of DCC commands to servos and relays, etc)

So this should be neat if I can get it to work. Something new to learn anyhow, DCC as a message stream 🙂

newboards

I have a lot less time to work on my projects than I used to so here is another sort of work in progress post.

I have the new widget boards and will be assembling several soon. I am missing a part, an SMD 140 ohm resistor for the power LED. It’s ordered.

Along with that order is all the parts I will need to intercept the DCC stream with my control widget and then either process it internally (moving servos, motor controllers, outputs, etc) or send it out to other Xbee wireless nodes. Something fun to do anyhow.

I should have a MRC Prodigy Express DCC controller soon. I will put it to use with my N scale trains but the main focus will be intercepting the DCC signals and sending them out via wireless XBee as mentioned above.

Also, if you notice, there is the Raspberry Pi 2 there beside Mr Foreman, I’ve got that up and running, very nice board. Really sweet.

Hmm. Also making progress on the CNC styrene cutting, I have large parts of the depot finished, I’ll post some pics soon.

I wired up my yellow critter with a control widget, a Turnigy 20A ESC and a 4.8v 2300mah nimh battery pack. Works quite well. I did have to add a relay to reverse the motor but that’s already supported by the software, it’s what I use in my RS3.

A pic from the video, out on the track at Gilbert Virginia.

Just can see the Xbee in the cab. The battery is in the engine compartment along with the Turnigy ESC. The relay to toggle the motor direction is also in the cab but you can’t see it from here.

The development platform for my Dash 9 whenever I get around to it. A close shot of the control board with the Xbee. This is the same control board in the Critter. There is just enough room (I think) in the critter to put in micro servos for the couplers but I have not gotten there yet…

And here is the critter with the handheld controller.

Here are some pictures of my computer/manual switch throw. I was looking for a device that I could use to throw a switch both with a manual lever and also have a servo drive it for computer control. This is what I came up with. After a bit of testing, it seems like it will do just what I want. It uses a cheap waterproof servo, three magnets and a styrene throw. There are two magnets on the servo wheel and one on the throw. There is no connection between the servo wheel and the actuator other than the magnetic ‘clutch’. The ‘spring’ wire is a paper clip bent to fit. With the servo off or centered, you can throw the switch manually and it ‘clicks’ to one of the two magnets on the wheel. Under computer control, the servo can rotate to ‘pick up’ the magnet on the arm to throw the switch. Works quite well on the bench so I’ll be installing it soon to test out in Gilbert.

bt

I’ve started some development for a new throttle controller, this one is based on an Android tablet for the user interface. My approach is a bit different than what is out there for tablets and smartphones though. I don’t like ‘sliders’ on a touch screen for controlling vehicles, so the idea here is to interface a small analog joystick (the parallax unit) and a potentiometer to do the actual control. The tablet will be used to pull up user interface screens for the locomotives and also have screens for controlling other things.

Basically, I’ve connected a generic bluetooth interface (about $10) to my Xbee Widget controller. The Widget can be configured to have up to 8 analog inputs, I’m using 3 of them here. I have the bluetooth interface on the spare serial port. On the other serial port is the Xbee which actually sends the commands to the locomotive.

I’m using PyGame to build Android apps with because I love Python!

Right now, the only thing on the screen that actually works is the speedometer. This is a screen shot of a Positive Train Control screen I dug up on the internet. I’m not sure what most of the other things on there are so this is just for playing around for now. But hey, it looks neat!

So anyhow, since I looked high and low and found ONE reference on how to scan the BT devices with Python, I decided to post up some python source to help out anyone looking to do this. As with most Python things, it’s really quite easy once you get the particulars ironed out.

To use this, just pass in the name of your bt device after you instantiate it. This is the same name you see when you pair your device with your tablet. In my case, it’s ‘HC-06’.



bluetooth = Bluetooth()
bluetooth.prepare("HC-06")
bluetooth.write("--testmessage--")


Here is the method. Note that the UUID in the device create is the same for all BT devices (as far as I know).

Jnius is a nice package that lets you call Java from Python so this could be used for other things besides Bluetooth I guess, but that’s another project. I really detest Java so anything I can do to write Android apps in python is great.




#
# Bluetooth interface class for PyGame- Python Android Games and Graphics development
# you will need the jnius python library to use this
#

import pygame
import sqlite3
import math

try:
   import android
   from jnius import autoclass
except:
   android = None

class Bluetooth:
    def __init__(self):
        self.BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter') 
        self.BluetoothDevice = autoclass('android.bluetooth.BluetoothDevice')
        self.BluetoothSocket = autoclass('android.bluetooth.BluetoothSocket')
        self.UUID = autoclass('java.util.UUID')
        self.deviceValid = False

    def prepare(self, name):
        paired_devices = self.BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray()
        for device in paired_devices:
            if device.getName() == name:
               self.socket = device.createRfcommSocketToServiceRecord(self.UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
               self.recv_stream = self.socket.getInputStream()
               self.send_stream = self.socket.getOutputStream()
               self.socket.connect()
               self.deviceValid = True

    def write(self, sendString):
        if self.deviceValid:
           self.send_stream.write([ord(b) if ord(b) <= 127 else ord(b)-256 for b in sendString])

    def read(self):
        datastring = ""
        if self.deviceValid:
           c = self.recv_stream.available() 
           if c > 0:
              for i in range(c):
                  datastring = datastring + chr(self.recv_stream.read())
        return datastring
        
    def close(self):
        if self.deviceValid:
           self.socket.close()



Finally got my control system tested out in the woods. Very happy with the range. The Xbee will do 300ft and I can’t even see the RS3 if I go that far away. This is my controlwidgets.com design. All the wireless communications are handled by the Xbee. I can send any sort of data to or from anything with this system in real time. Those are 16 byte data packets that are controlling the throttle and coupler servos.

The RS3 has the throttle, front and rear couplers and single channel sound all hooked up and working. All of it is powered by a 5000mah hour LiPoly battery driving a Pololu 18v7 motor controller. The control widget drives the servos directly. There is also an RFID reader under the fuel tank which works quite well too.

1ChannelSound

I realized I didn’t have this posted up- this is the single channel mp3 sound card from mdfly.com combined with a simple audio amp. The amp is quite loud and can be built with parts from Radio Shack. This is what I’m using on my RS3 in the pictures below. I’m using the Attiny 1634 s/w UART to drive this from the client widget. It works quite well, you just send a single byte to the card to set the volume or play one of the sounds. However, you get what you pay for, $10 only gets you one sound at a time.

P1040103

P1040101

P1040102

Here are a couple of shots of my control system going into my Aristocraft RS3. The power is all in the back end, I have a 5000mah 14.8v lipo pack driving this beast with a Pololu 18v7 motor controller powering the trucks. A very potent drive train. Anyhow, these pics show the brains- the Atmel 1634 board, the Xbee Series 1 and the MDFly mp3 sound card. Not seen is the RFID reader on the fuel tank- I’ll post that up later. Phew, some work and lots of engineering spits and fails but it’s now pretty clean and works well. I did downsize the controls a bit, I’m only driving the motor, the two coupler servos and the sound card. I left the lights on a manual switch and there is a current sensor in there but I’m not looking at it right now. As mentioned, the RFID is also connected and works so I do have the basics of a computer controlled system. The main control boards are also reasonably accessable by taking off just the short hood of the locomotive so tweaking the firmware, sounds and the pololu motor controller won’t require the entire locomotive to be taken apart (which is a BITCH to say the least!)