Soon updating all sketches with code for a motor-driver L298 to 122Hz
I will set the frequency to 122 Hz for Arduino pins 9 and 10. This means that timer 1 with divider 256 will be used.
It is obvious to me that if most DCC decoders use a frequency of 100 Hz and this is the most recommended PWM frequency by manufacturers of miniature DC motors, then it is necessary to use exactly 122 Hz.
This is not a problem for the project itself, as it is possible to use any settings and any frequencies. That is, you can use 490 Hz and do not change anything in the sketch.
It is also possible not to change the design of the existing URB units at 122 Hz. Just in this case it can't to simultaneously use the servos and the motor-driver on the same unit. No more problems for transferring to 122 Hz.
Fully automatic Reverse Loop is complete
Arduino Train DNT correctly shows the direction of the train after passing the loop. This is another unique feature of the URB project. Full description is available for URB Club members.
Fully automatic Reverse Loop
I got the best implementation of the management of the railway loop. Robust and fully automatic operation, independent of the position of theturnout. Power switching does not affect the move of the train. And another very important surprise. Soon.
Protocol 2.1 — Precision Thrust Engine Control
Accuracy at fingertips – original programing code for the Thrust Slider in the Arduino Train apps now expanded. Protocol 2.1 now supports 18-speed control mode. All applications, except Demo, now support this version of Protocol. See changes on Orange Book.
Test 18 loco speeds
Test new features 18 speeds moving of a loco for update application DUO passed successfully. The train moves beautifully at low speed.
Easy solution for 5V power to the URB unit
For power supply circuits URB need 5V. The easiest way to do this is look at the photo. Chargers for mobile phones give 5V and current up to 1 A, this is quite enough. You only need to change the cable USB-microUSB to USB-miniUSB.
Please use it only for experiments or if you use a single command station to control trains. In other cases, you need a power supply with currents from 2A.
I think about new feature. Like Inertia.
Photos of railway layouts managed by the URB project
Pictures from my old sites
URB Electronic Model Railway Parts
Running and troubleshooting
To examples on this site are hard to go wrong, but shit happens :) If you have collected wires and a circuit, have included, but it does not work – we will look for the reason. At the same time you will understand how to act in such situations.
...nothing was working!
This is a quote from a real user message. The problem is that it is impossible to guess what went wrong. Therefore, the first thing to do: Don't Panic – you can't do something fatal with voltage of 5V. The biggest mistake: creating a short circuit or overload pins of the chip will only lead to the fact that you need a new Arduino.
If you turned ON the power (or plug USB cable) and the LEDs on the Arduino did not light up, or blinked and went out, then you incorrectly connected wires. Or you have a broken Arduino or problems with the power source.
Disconnect all wires except power wires and turn on the circuit again. If the problem persists, replace the Arduino, check the power supply with a tester and, most importantly, carefully look at the correctness of your wired connections.
The verification algorithm is simple, you need to divide your scheme into parts. And consistently add to it your items. So you localize first, and then fix the problem. Therefore, first of all, testing begins with the power supply.
"I can't connect via Bluetooth"
You can use any Bluetooth modules in your project. These modules are often very similar to the HC-06(05) I recommend. Unfortunately, many people like the beautiful name of BLE and Bluetooth 4, but this standard is designed for minimum power consumption, so a level converter is needed. In addition, the assignment of pins on other modules may be completely different. Consult the documentation for your modules if you want to use them.
My applications are connected over an Android Bluetooth. The rule of verification is as follows: if you could pair the Bluetooth module with the phone, then connection is works.
Test BT connection
To finally test the connection, upload a simple sketch to your COMM unit. Open the Serial Terminal Arduino IDE. If you are not mistaken with the wires, you will see Protocol 2 commands transmitted to your COMM unit from the application.
The most common mistake is the wrong connection of data wires RX TX between the Bluetooth module and the Arduino. I highly recommend using the URB unit, it solves most of the problems of this kind. When using the unit's URB together with the BT modules, do not forget to install the Level Converter!Test BT sketch
Train don't move
Produced are a lot of different variants for Motor-drivers modules. There are even a few dozen modules based on the chip L298, and they differ not only in location but also in the number of pins. Most importantly, there are two standard ways to connect Arduino to dual channel drivers: by six and by four wires. My sketches provide a six-wire connection. If you have another module, change the code according to your module.
The most common two problem situations:
- when you forgot to connect your circuit with a COMMON WIRE
- when the Driver A is controlled from the application, and the locomotive is on rails connected to outs B, or voltage measurements are taken on the Motor-driver outputs B
Please check your wires circuit connections carefully.
First check out the Arduino pins with unplugged the Motor-Driver. When you moving the thrust slider in the application on the corresponding to the ENA and ENB of Motor-Driver pins the voltage should be change from very close to zero to the Arduino's supply voltage. When you pushing buttons for changing the direction of motion should be changed the state of the corresponding pins IN1 IN2 and IN3 IN4 from a high level to a low level and vice versa.
If all the previous steps are completed, but the locomotive still does not move, then with digital multimeter checking the condition Motor-Driver and the locomotive.
Where to buy Arduino details for the project
Buyers guide — How to cheap buy details of Arduino
I did not want to write this guide for a long time, because I thought in Internet the information was enough to indicate that this is a very cheap project. I am the same buyer of these goods as you are. That is, I do not produce, sell or advertise the producers of these details. And I do not have any benefit from such activities.
But I was wrong, it turned out that this is very important. I will give my method of buying these goods and the approximate prices.
The first advice
Is to take several identical parts at once, it is not only cheaper, but also relieves you of the need to re-order. Be greedy! For example, for my project you need a few Arduino NANO, when buying five pieces on the trade portals such as aliexpress.com or alibaba.com one piece will cost only $3.2 (2.7€). On Ebay 5 pieces of Arduino NANO will cost 3.3€ for one, but the delivery will be much faster.
The second advice
Be very careful when choosing a product on these trading portals – the product description is often very brief and uninformative. For example, you can buy cheaper the same Arduino Nano Atmega168P, but with another CPU (need 328P) which will very restrict you in writing sketches and applying in the project. Also apply this recomandations to modules of Bluetooth and Motor-drivers, compare the picture on my site and on the sites of sellers, they should be identical (in part because of this I bring pictures instead of diagrams).
The third advice
Buy from local vendors consumables (wires, connectors, etc.). Shops such as Radioshack are almost everywhere. If you look a little you will find that very often next to you there are private sellers of details of Arduino, it is slightly more expensive than on sites, but at times faster. Plus there will be communication, often people trade Arduino not for profit, but for the sake of a hobby (just like me).
All items for one URB unit bought in this way are for me a less than $4 or approximately 3€.
Comparison URB project with manufactured solutions
Now let's just count. I will compare the price of electronics, without wires and power supply blocks, for Example of a Symmetrical layout presented on it site. I'm not so sure about real prices, but approximately in out June 2018 so:
I took the simplest set of parts for installation the electronics for "Symmetrical track plan" from the site of Horby. And it's not even a wireless console. The price difference with the same functionality eightfolded, this despite the fact that the expansion options for my project is much greater. The attempt to calculate the price of the necessary components from the Pro series from the company ROCO led to a difference of 25 times!
And for me it was a bit surprising that I did not find on these sites a classic set for DC control.
|Detail||Quantity||Price $||Price €|
|URB unit||2||4.00 x 2||3.40 x 2|
|Arduino NANO||2||3.50 x 2||3.00 x 2|
|Arduino Train Junior App||1||9.99||9.99|
|Servo SG-90||4||1.40 x 4||1.20 x 4|
|Relay 2ch||2||1.20 x 2||1.10 x 2|
All well-known manufacturers have ceased production DС control systems.
|Detail||Quantity||Price $||Price €|
|Hornby DCC Select Controller||1||139.99||121.99|
|Digital Locomotive Decoder||2||25.99 x 2||22.50 x 2|
|Hornby Accessory Decoder||1||52.00||48.99|
|Surface Mounted Point Motor||4||12.99 x 4||9.99 x 4|