Skip to main content

Posts

Showing posts with the label Arduino

What is Arduino

 With groups in our area having smaller attendees at Zoom meetings, we decided to try a multi group session so that our speakers would benefit from a fuller audience. On Sunday 14th January The Scottish Border Group, Cumbria Group and North Wales Group joined together for our first joint session. This worked very well, with our speaker, David Roberts giving an excellent talk on Arduino hardware delivered to around 24 members. For those who missed it, it is available on the MERG website on Channel 36 of MERG TV Some Arduino software tutorials are available on the MERG website and there is an Arduino Special Interest Group for those interested. If you want a well structured, beginners course for absolute beginners, I would suggest Paul McWhorter as a starting point.

Automatic Station Lights

 Following on from the station lights blog I published awhile ago I have now have the lights coming on automatic when a train comes into any of the four tracks using a Arduino Nano As I have some spare Ezybus boards I used one of these to do all my connections to the Nano, it also has a 12 Volt input to power the Nano As my layout is DCC I am using a MERG PMP7 for train detecting, which uses a opto-isolator, to control the LED on the control panel. One side has a voltage on, in my case 5 Volts with a dropper resistor which brings it down to about 3.5 Volts, the other side is connected to ground 0 Volts. One of the Nano pins reads this voltage, if it is 3.5 volts it does nothing but if it at 0 volts it switches on another pin on the Nano. I have used 4 PMP7's for the 4 tracks and used 4 pins on the Nano ( one for each track ) if any of the pins goes to 0 Volts it will switch on the output pin, this in turn switches on a replay to power the LED's ( I have not used the output pin ...

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...

CBUS to Control DC Layouts

 At this mornings Virtual Area Group Meeting, Rob Thomas described how he uses  CBUS to control his OO9 layout.  He discussed the Pros and Cons of the various available systems including MERG's Automatic Train Controller, commercial offerings and Mike Bolton's Basin Speed Controller. Having opted for the Basin Speed Controller version as the basis of his project, he then looked at how he might add additional control using CBUS. Various versions were developed starting with a seven speed and stop initial project with subsequent modifications to overcome some of the problems associated with the different behaviours of individual train motors. Speed and Inertia were eventually  controlled using files created from a Python script and stored on an Arduino. He uses RFID to identify the locos so that the correct profile can be loaded to the controller. This is certainly not a beginners subject but the video is available on the Merg website for those interested.

Cafe Sign for 00 Gauge

 This is the cafe sign that Andrew Robb has set up for me, and I have installed it in a Metcalfe kit PO254 It runs off a Arduino Nano board with a 132*32 OLED The set up is the same as the Station sign but with a new program in the Nano The display board is mounted into a slightly modified 3D printed sign holder Sorry the Video is not very sharp. Many thanks to Andrew for doing this for me.

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  ...

Document First - then Code

 Davy Dick's talk to the JAL Special Interest Group last night was a not to be missed event for anyone wishing to program in any language. The critical analysis process was succinctly expressed as " If you can't describe it - you can't code it" Comments in a program are essential for the understanding of others and for yourself if looking at it after a prolonged delay. Davy suggests that we shouldn't write code and then comment on it, but the opposite. Write comments describing your requirements and then write the code for each part. Davy used a few examples to outline his method of designing using Psuedo Code. A road roller, a canal boat with intermediate animations, a traffic light simulator, a lighthouse and Ezypoints were demonstrated and discussed showing different programming methods. I would recommend that you watch this presentation which is now available on the JALSIG area of the MERG website. You might have to Join the JAL Special Interest Group to...

Visual Basic & Arduino

The project I'm working on just now involves writing a Program in Visual Basic 6.0 (a Programming Environment I'm comfortable in) linked to an Arduino Uno. So far, I've got as far as controlling a set of traffic lights (3 LEDs on a bit of Breadboard) but I'm happy with that progress so far.  There's a long way to go on this, a steep learning curve, but courtesy of Covid 19, I have a lot more time to devote to this kind of project than I would usually have at this time of year. So far, I have one way communication, next challenge is to get information going the other way.  Web forums are very useful things. For those of you who want to see the "nuts & bolts", here is the Arduino Code int redled= 12; int amberled=10; int greenled=8; char Inpchar; void setup()  { pinMode(redled,OUTPUT); pinMode(amberled,OUTPUT); pinMode(greenled,OUTPUT); Serial.begin(9600); }  void loop() { if (Serial.available())  { Inpchar = Serial.read();}  // Reads single character fr...

Interested in Programming Technique?

The JAL Special Interest Group has a meeting on Monday 14th September at 19:30     These are sessions that are open to all members, both in the UK and internationally. It normally discusses programming PIC chips using the JAL programming language.  Davy Dick from the West of Scotland Area Group will be the guest speaker and will be discussing how he goes about starting a program from scratch, using his automated canal barge and the traffic lights Pocket Money Project as examples.  As this session covers programming technique, it is also useful for Arduino and other platform  programmers.  If you have not yet signed up to JALSIG then you will have to   update your profile

Train sequence / timetable using Arduino

                              Following discussions in a MERG Zoom meeting about potential projects for the Cumbria virtual area group I have started this blog to share my ideas for building a train sequence / timetable system based on an Arduino UNO. The trigger for this project was Andy Robb's article in the MERG journal (June 2020 edition). In it Andy describes using an UNO with a OLED display to produce an electronic station display board.  Having tried out Andy's version I started thinking about expanding the idea and have come up the following list of possibilities: 1. Replace my card index train sequence with an electronic version. 2. Have the train sequence synchronised with the on platform displays. 3. Display an analogue clock on the station display and have it display the train times. 4. Store the position reached in the sequence so that it starts where it left off on power up.  To mak...

Arduino Kit

 At today's Scottish Border Area Group Zoom meeting we had about seven attendees. As it was a coffee and chat meeting various subjects were discussed, including carriage lighting. Keith showed us an alternative method involving conventional led strips, four button cell batteries and the lights being switched on and off using a reed switch in the presence of a magnet. Details of the circuit will be made available later. For those interested in learning how to program and use Arduino's on your layout, Derek showed us a really useful kit that includes an Arduino Uno, breadboard, jumpers and USB and power cables. In addition there are a number of experimental parts that include a servo motor and driver, leds, switches and various sensors and display types/ All parts of the kit are contained in a convenient plastic case. This kit is available on Ebay for around £20 and is an ideal starter kit.

MERG Advert Display

 At last Sundays West of Scotland Area Group Meeting, I showed a MERG advert running on a 128 x 64 OLED display. One of their group contacted me to ask if that could work on the 128 x 32 station display which he had just ordered from me. The original image is 290 x 115 pixels so this needs to be reduced with the aspect ratio maintained. The original is also a colour image which we will also need to convert to run on a monochrome display. Paint is a very basic program installed on most Windows machines but is perfect for what we need to do. Open the original image in Paint and select Resize The OLED display width is 128 pixels By selecting the pixel radio button and typing 128 in the horizontal field and ensuring the maintain aspect ratio box is ticked, the picture is reduced to 128 x 50 , perfect for a 128 x 64 display. For 128 x 32 we must instead select 32 in the vertical field which will produce a final image size of 81 x 32 pixels. All that remains to do, is to save it as a m...

Arduino Cookbook 3rd Edition

The third edition is now available. I was tempted to buy an earlier version but a lot has happened to the available Arduino devices since the second edition was published in 2012. This is not really a beginners book for Arduino or for programming in C, but its eighteen chapters and seven appendices makes it an excellent sourcebook for writing code that works. With the introduction of chips like ESP32 and beyond, the chapters on Wireless, Bluetooth, WiFi and Ethernet are particularly welcome. The layout using Discussions, Problems and Solutions makes the book very readable and with over 200 coding examples the forty pound price tag is quite reasonable. I think if your serious about learning and using Arduinos on your layout projects, then the  Arduino Cookbook 3rd Edition should be on your bookshelf  

Arduino Special Interest Group

This new SIG is being run by John Fletcher and already has more than fifty members. Details can be found on the MERG Website. There has been an enormous amount of work done on the website bringing together coding samples, members projects and discussions on the forum. Yesterday evening's Virtual Area Group meeting featured a presentation from Ron Pluck showing his method of developing a railway project from circuit diagram to working device. Although some technical problems were encountered, the session has been recorded. The link is now available and I understand that both the completed sketch and a Word document explaining its development is now available in the Arduino SIG area of the website. I would recommend that you download these documents to have them available as you watch. Andy R

Demystifying Components - Arduino

If you missed Sven's excellent presentation on Monday, or would like to revisit it, it is now available on MERG TV. SVEN's PRESENTATION Sven demonstrates how you can take your first steps in programming an Arduino. You may have heard about the Arduino microcontroller. It is a small and cheap programmable device that is popular in model railways. It is used for controlling lights and motors on a layout. This is an overview of what Arduino is and how to get started with your own Arduino project and demonstrate how to connect an Arduino to a PC and make it control some  LED 's and servos. No knowledge of Arduinos or programming is needed. Great Introduction and well worth a watch Andy R

WOSAG Meeting 2nd August

Another well attended Zoom Meeting for the West of Scotland and its increasing number of followers from other regions. Davy carried on from the previous sessions on servos showing a members implementation of a traverser utilising a lead-screw and simple kitchen drawer runners. It is a very flexible and compact method to store trains in a confined space where there is no room for a more typical point operated fiddle yard. Neil McNulty and myself did a presentation on Station Displays using the Arduino  For those who missed it here is a couple of links to some you tube videos Station display   https://youtu.be/ IeHQJ2KWlJg Oled Projects     https://youtu.be/BVtIPwhyprs Andy R