Skip to main content

Posts

Showing posts from September, 2020

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    ' Does the same to line 1, which you can't really make out     Shape7.FillColor = vbRed                 ' Cha

Visual Basic, Arduino and Points

 Step 3 in this process was to get the Servo to rotate more slowly than before. This is the modified Arduino Code // the next block of code sets up a loop in the Program to rotate the Servo 1 step at a time. //  This way, we get a 'smooth' movement, rather than a sudden one if (Inpchar=='A') {                          // checks Input character A for Anticlockwise     delay(300);                                 // a wee pause (for dramatic effect!! )     for (int i = 0; i <= 135; i++) {     //  a variable i goes 1, 2, 3, 4 . . up to 135           servoPos = i;                              //  send the new value to the Servo controller           delay(30);                                   // a very wee pause (30 milliseconds) //        30 milliseconds * 135 steps means 4,050 milliseconds, so just over 4 seconds            myServo.write(servoPos);         // move the Servo to the new value of i (1, 2, 3, etc)     }        //  This is used in Arduino code to finis

Visual Basic, Arduino and a Servo

The overall plan is to end up with a Model Railway Layout which is being controlled from a Laptop computer by clicking (or pressing) buttons on some form of mimic panel displayed on the Laptop.   The LEDs are working, so now on to getting a Servo to behave.   Many thanks first of all to Paul McWhorter on Youtube for his series of video instructions https://www.youtube.com/playlist?list=PLGs0VKk2DiYw-L-RibttcvK-WBZm8WLEP Tutorials no. 30 and 31 are the ones about Servos, how to connect them and control them.   The Visual Basic Code and Form In VB, make up a form with 4 Buttons.   For this simple version, we only need 2 of them.  We will ignore the "pretty coloured" ones just now!! CW for Clockwise              ACW for Anti Clockwise This is all the code needed for these buttons. Private Sub Basic_AC_Click()      ' This is the code which is executed when the ACW button is used        MSComm1.Output = "a"           End Sub Private Sub Basic_CW_Cli

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

East of Scotland Demo layout

At today's West of Scotland Area Group meeting, we were treated to a presentation and demonstration by Chris Cosgrove from the East of Scotland Area Group. Their layout is a basic oval with two additional loop sidings. A further siding leads to a turntable off which is a track to an engine shed. To add interest, a working level crossing with flashing lights will be added. The layout is controlled using an EzyBus controller, one input board and two output boards all connected by I2C.  The level crossing is triggered by two laser TOTI's (one each side). To create the necessary delays, Chris designed a circuit using the PIC 12F675, the outputs of which are fed to the EzyBus Input Board. Switches are also connected to the Input Board for point selection, Engine shed door operation and turntable position selection. The Output boards are used for Servo Control of the points, the automation of the Engine Shed doors and for the level crossing gates. Additional digital outputs control t

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

Cumbria Area Group Meeting

 Some 15 members joined us for the second Zoom meeting of the Cumbria Area Group on  11/09/20 John Farrell (North Wales Area Group ) gave us his interesting presentation on the CBUS beginners kit 101 which he was test building prior to its Kitlocker release.  We were joined by Howard Watkins, well know MERG personality and creator of the build documentation for this kit.  The kit purposely contains boards from the original CBUS range including CANACC8  which requires some slight modification (additional parts are provided) , a CANACE8C  which is a 5 Volt module powered from the CANACC8, an Experimenters kit and a 12 Volt DC supply with mains lead. With the boards connected you are then able to create events without the need of a computer. A DIL switch on both main boards is used instead. John had purchased separately a CANGIZMO  board which is a very useful testing and debug tool. A most useful discussion ensued. It was suggested that we develop something to assist our members on getti

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 make the project of greater potential interest to other modellers the following

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.