Skip to main content

Posts

Showing posts with the label Programming

Push button Ezypoints

 A few months ago I produced a batch of Ezypoint kits for our local members to overcome a shortage in the Kitlocker.  At that time the kit was produced on stripboard which some members find problematic. An additional PCB board normally available from MERG was not available either.  Alan Turner ( the PCB designer) had only a few boards available but graciously provided me with the gerber files to allow me to order PCBs directly from China . Having sourced all necessary components, the kits were duly made up. I find this simple kit is really useful for automation projects. A toggle switch provides either a HIGH or LOW on the PIC input pin to determine which of the two servo positions is selected. For a particular application, I wanted to use a push button to toggle the position on alternate presses of the button. This involved a rewrite of some of the code in the PIC. I initially developed the program using an Arduino as a means of testing the logic. When this was successfu...

Mimic Points in Visual Basic

For this project, I wanted to create a moving graphic to mimic a set of points moving from one position to the other.  This Blog shows all that is needed. The first Picture shows the 6 lines needed.                                 This Picture shows the Line Properties.    The tracks are shown with 5 lines, though only the middle ones in red are involved.  The other line shown below the others is the one that actually "moves".  It is shown below the other lines for clarity only.  At the start of the Program running, it is positioned over the lower red line. In VB, each Line has properties and these are shown above.  To get a line to appear to move, all that needs to be done is to gradually change the X2 and Y2 co-ordinates of the line. This is the code for the program. The first 6 lines create a pause Function in the program, by using the Computers internal C...

Shuttle Plus or Super Shuttle?

 A really interesting project was discussed at tonight's JALSIG Zoom meeting. The Basic shuttle kit PMP4 was designed in February 2013 and remains one of the most popular Pocket Money Kits. It uses a 555 circuit as a basic timer  and changes the state of a relay to reverse the polarity of the track. Davy Dick has revisited this circuit but this time used a 14 Pin PIC (16F676) to replicate the circuit and  add a few enhancements to take advantage of the additional pins available. It is hoped that this will eventually appear as a Pocket Money Kit with PCB sometime in the New Year. Potential features include adjustable cycle times, controlling semaphore or lights using a delay or detectors set by an option jumper and incorporation of PMP4a  for shuttles with branches.   Two additional pins might be used to control crossing gates or trigger sound effects or anything else your imagination fancies. Using around 12 components and some simple coding techniques, thi...

Arduino controlled shuttle

 Thirteen members joined us on today's Cumbria Zoom meeting where Tony Hoath demonstrated and explained his Arduino based shuttle layout which he uses for bedding in new OO scale locos. The basic Pocket Money  shuttle Kit suffers from the sudden stop when the track break is detected and the sudden start when the relay is reversed. The affect can be minimised if slow speed is selected. Tony uses a simple Light Dependent Resistor to detect the presence of a loco and then gradually decelerates and finally stops on reaching a second sensor. The circuit is shown below. As the relay is only switched when no power is being supplied to the track, a much smaller relay can be used to change direction. As the locomotive returns it ramps up to a set speed so the rather unrealistic stop / start is avoided. Tony's sketch is available below. //00 test track //1 loco to run back and forth //2 LDR,s to determine train postion. //2 push buttons. Green starts and stops operation. The sto...

Use Visual Basic to enhance the Display

 The reason that I like VB as a Programming Environment is the ease with which you can make it look nicer or Enhance the Display if you want to sound fancier about it. If we take the Red LED - Green LED Program, we can another couple of features which show the beginnings of what might appear in a mimic panel.  So the first thing we would do is to add a couple of Shapes (another type of VB Object). We put a shape beside the Red Control buttons then set the properties to :- Shape = circle Fillcolor = Red Bordercolor = red Name = Red_Circle Do the same for the second, green, shape. Then we edit the VB code Private Sub Red_Off_Click()   MSComm1.Output = "r"                   '   Sends r Switch off Red   Red_Circle.FillColor = vbWhite       '   Changes the fillcolor to white End Sub Private Sub Red_On_Click()   MSComm1.Output = "R"        '   Sends ...

Introduction to linking Visual Basic to an Arduino

 Visual Basic is an "Object Oriented" language and is a programming environment which I'm comfortable in, so I'm going to look at the steps involved in setting up a Program on a Laptop to control a simple model train layout. Using an Arduino Uno, connect via a USB Cable, the first thing is to establish communication from Laptop to the Arduino. This needs the Comms Component to be added.  This link shows how to do that.     http://www.thaiio.com/prog-cgi/0002_serial.htm This picture shows the main (functional) sections of code, along with the Program display (Bottom left) when it's running. The Visual Basic bit (top left) In VB, you add "Objects" to a form and then attach some code to each Object. Some of the Objects you get in VB are Command Buttons, Labels, Text Boxes, List Boxes.  There are many others. This example has "Command Buttons" named "Red On", "Green Off" and all that happens is when, for example you click on the...

PIC Projects

 Two interesting PIC projects were shown at JALSIG's last meeting which is now available to view on MERG TV. Brian Norris demonstrated a program which simulates eleven lit traffic cones working in a chaser sequence as you would see on a motorway or roadworks. Developed using a 16F18323 chip, Brian explains how he moved from a very basic program to a more sophisticated one using the pintools function. This was followed by a presentation by Ian Hart showing a CANMIO board with modified code that checked the inputs and outputs in a specific sequence.     This apparently is a really useful tool to fault find boards coming from other members to ensure outputs and inputs are soldered properly without shorts or bridges. The session was recorded and is available on the JALSIG area of MERG TV You would have to join the Group through the area groups page.

PIC Programming Add-on

 I have been using my PIC Programming Kit for a number of years.  In the main, I have downloaded the relevant Hex files from the MERG website and written them to whatever PIC was required, either for my own projects or for those of other members. PICs can be significantly smaller than Arduino Nanos for example and as I sometimes model in N gauge, space matters. Following a previous post on carriage lighting, I considered using Davy Dick's PMP 19 as a starting point. Even a 12F675 PIC takes up a fair amount of room, but then I came across an SMD version of the same device. It's much smaller and surprisingly cheaper than the original, but how the hell can you program them? I found this device on AliExpress which simply plugs into the programmer using the standard pitched pins on the base. The SMD device sits on the top and a set of spring loaded pins then secures each pin above and below to ensure good contact. Works an absolute treat.  Now all I need to do is design an SMD...

Visual Basic Code in a Mimic Panel

Visual Basic is what is known as on Object Oriented Language, so you add Objects (Lines, Boxes, Shapes) to a form and then create some matching code which is executed when you Click (usually) on that object.  The modified Form for the Points Program now looks like. The objects on this form are Lines 1 and 2, Shapes 6 and 7 and a couple of Command Buttons called Clockwise and Anti Clockwise.  When we Click on Clockwise, then some code is executed. This lot !! Private Sub Clockwise_Click()     MSComm1.Output = "C"                  ' Sends a "C" to the Arduino code which makes the Servo turn     Clockwise.Enabled = False                   ' Disables the "Clockwise" button so we can't press it by mistake     Line2.BorderColor = &HC0C0FF    ' Changes Line 2 to a beige kind of colour     Line1.BorderColor = &HC0C0FF  ...