Incredible opportunities for an experienced modeler appear when using feedback in the URB system. Connecting sensors of any type to the system, mp3-players that create the sound ambient of your railway, a real-time clock module and other things turn your layout into a living world. Using sensor triggering events, third-party commands from external devices and using algorithms created by you, you can set autonomous smart behavior to any object on your layout. This page presents features and concepts for advanced modelers using the URB system. You can use these ideas yourself or become a member of the URB Club.
Any sensor, button or toggle in the Arduino software environment is a Boolean device. This means that you can use the experience of creating algorithms of the URB Project that you already have to manipulate signals from these devices.
However, any programmer who creates software for industrial microcontrollers will immediately start talking about the fact that there is a many books of computer science about processing signals from sensors, and this problem is very complex. Of course this is true, but in our case it is only necessary to define three concepts about signals from sensors.
This is the funniest fault that a lot of people come across every time trying to use conventional sensor modules for Arduino. The essence of this fault is easily shown by the example of an IR sensor. Depending on the installation method of this digital module on the railway tracks and the version of the module, the trigger signal can be either HIGH or LOW at the OUT pin.
To avoid these discrepancies in the URB Project, I recommend using an intermediate Boolean variable:
bool flag_sensor_XX = false; ... pinMode(5, INPUT); ... if (digitalRead(5) == LOW) flag_sensor_XX = true; else flag_sensor_XX = false; ...
That is, the state of the variable will always uniquely determine the sensor state and you can't go wrong. If the sensor trigger signal is HIGH, just simply change the LOW to HIGH in the status reading line of sensor.
I assume that you will only use buttons and digital sensors. The main code for processing signals from these devices is digitalRead(PIN)
. If you follow the code on the official Arduino website, there may be some misunderstanding. Sensor readings return parameters: HIGH and LOW. The variable val
is of type int. Ignore this and use the Boolean type.
There are also special parameters of the pinMode
function for buttons and toggles:
The URB unit is used in this video. URB unit is a shield of my development for Arduino NANO, which provides a more convenient connection of external devices. Its use is optional.
Bluetooth connection between an Android device (phone or tablet) and COMM can transfer data in both directions. Organizing the transfer of telemetry from railway devices to the app, we can implement the feedback mode.
The motor switching via app gives a lot of unobvious opportunities and gives rise to the small problem. For example, the position of the turnout can be uniquely associated with traffic light signals and, as a result, get a ready signal system. Also, you get the initial routes for trains immediately after the URB system is turned on. All this was taken into account in the development of this project by changing the sketches of a particular Local unit, you can program any logic of the behavior of the signals. Also in the application there is a button DEFAULT, which sets turnouts to the position assigned user, the same happens when the layout is initialized when the power is turned on. A problem roses if the switches are controlled by several players at the same time.
Without using feedback the position of the switches in the apps will very soon not correspond to the actual position of the turnouts on your railroad.
This situation changes when the feedback mode is activated. The command unit URB always notifies the application about changing the positions of turnouts. Thus, even if two Android phones are used, the position of all turnouts will be online displayed on each of them.
To send data to Android device from COMM about pos of the turnout A, you will use simple code Bluetooth.print("ja1z")
. And etc.
A unique feature of the URB system is the correct position of the direction buttons in the application. Thanks to the feedback, the buttons automatically switch after train passing via the loop. You can see the algorithm of this subsystem on video above. The Protocol 3 uses the Bluetooth.print("1rlz");
for Driver 1 and Bluetooth.print("2rlz");
for Driver 2.
The Wireless Railway Unit is compatible with all sketches, algorithms and Protocol of the URB project. The only difference is the use of wireless data transmission instead of wired buses. You can mix WRU with URB units or other microcontrollers (MEGA, ESP and etc.) in any way. Available only for members of URB Club.
Entry-level boards (NANO and UNO) have a very good feature – to find errors in the code, faults in the circuit you does not need an additional tool. You can do without even a tester, but it is more convenient with it. The price of these boards is very small, and I will repeat my recommendation, you should have at least three Arduino.
Regardless of the manufacturer, these boards are very reliable. I read messages from users in which they admitted to incorrectly connecting the polarity, supplying a supply voltage of more than 9 volts to a 5-volt power pin, and even the Chinese Arduino remained operational. But sometimes these extreme experiments lead to damage to the Arduino pins, the inability to download sketches and other problems.
Accordingly, to determine the problem, you need a second similar Arduino board. The principle is simple, you just change one Arduino board to another and run your experiments again.
If you suspect Arduino's malfunctioning. Perhaps you have damaged a pin or several pins or the sketch is not working properly. So, each Arduino pin has several levels of protection, and the first thing to do is disconnect all the wires and connect the USB cable. If you have a URB unit, then it’s still easier – remove the Arudino NANO from the connector and move it near from the computer on which Arduino IDE is installed.
Try uploading the BLINK sketch into the problematic Arduino. If this is not possible, then throw this Arduino into the trash.
If, after loading the sketch, the built-in LED flashes, this means that the main Arduino circuits are operational and the problem can only be with a specific pin. You can sequentially check pins of Arduino by connecting an external LED and sequentially be change the pin number in the BLINK sketch. Or use tester instead the LED. Checking pins in INPUT mode is performed similarly. Uploading code:
void setup() { pinMode (NUMBER_OF_PIN, INPUT_PULLUP); Serial.begin(9600); } void loop() { Serial.println(digitalRead (NUMBER_OF_PIN)); }
And after that, look at the Terminal how data changes when shorting this pin to GND.
If in the Arduino IDE Terminal the data from this pin will not consistently show 0 or 1, then mark this pin as faulty. If your Arduino is working with the exception of the pins do you have defined, then simply do not use these GPIOs in sketches for this instance of the board.
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. The hardware of the URB project consists of modules that can operate autonomously. Therefore, troubleshooting is a simple checking of the modules by one. You can always connect the URB unit to the computer and add test commands to sketch from the Protocol 3 for check it.
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.
The general principle is this: you are comparing a problematic Arduino with a known-good Arduino. The same principals for other details.
Connecting a computer directly to unit is a very important feature. You can debug your sketches on time on the layout, or test the circuits separately by functional blocks.
Big layout is a lot of wires, the complexity of connecting devices and their compatibility among themselves, and most importantly the inability to add or change something in the finished layout without dramatic changes in the wiring. These shortcomings are absent in the URB concept.
All wiring between the blocks is made up of four wires. For example, if you need to put a few new junctions or sensors or streetlights on the layout, you just cut the four-wire bus in the nearest place and insert another URB. It remains only to upload the sketch, and your newly installed pieces are immediately integrated into the layout. At any time you can reprogram already installed URBs directly on a layout, you just need to leave the opportunity to reach it with a mini-USB cable. This way you can change the control or setting of any layout's devices, and replace it if necessary.
Another plus is the ability to experiment with each the URB unit independently of others, and it's still an easy way to look for possible malfunctions in electrical parts on layout. It is also possible to assemble URBs with peripheral modules separately on the table. You'll tune the prototype and then will transfer it to the layout. This allows you to realize your ideas much faster.
My apps 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.
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 3 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. In my applications, the connection between the Android phone and Arduino via bluetooth is a virtual analogue of a serial connection.
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 1 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.