Dwa pociągi jeżdżą jednocześnie, każdy na swoim regulatorze. Arduino Mega samo przełącza odcinki toru na regulator pociągu, który do nich wjeżdża, i samo obsługuje trzy pętle nawrotne. Prowadzisz pociąg jak dotąd: regulatorem ustawiasz prędkość i kierunek, przyciskami przestawiasz zwrotnice.
Two trains run at the same time, each on its own controller. The Arduino Mega switches each track block to the controller of the train that enters it, and handles the three reversing loops by itself. You drive as before: the controller sets speed and direction, the buttons set the turnouts.
Stan projektu. Gotowe i sprawdzone: cztery płytki (połączenia i reguły w KiCad) oraz program (symulator jeżdżących pociągów). Czeka: plan torów. Z niego wynikają granice odcinków i tabela w pliku Layout.h (krok 8). Do tego czasu Mega tylko pokazuje czujniki, a wszystkie przekaźniki są wyłączone. Cały tor jeździ wtedy na regulatorze 1, a pętle na ograniczonym prądzie.
Project status. Done and checked: the four boards (connections and rules in KiCad) and the program (simulator with moving trains). Waiting: the track plan. It sets the block boundaries and the table in Layout.h (step 8). Until then the Mega only shows the detectors and all relays stay off. The whole track then runs on controller 1, and the loops on limited current.
Nie buduj wersji v0.3 (stara instrukcja: INSTALL-v0.3.html). Jej ogranicznik prądu był tylko w jednej szynie. Przy wjeździe do pętli ze złą biegunowością druga szyna robiła pełne zwarcie.
Do not build v0.3 (old guide: INSTALL-v0.3.html). Its current limiter was in one rail only. On a wrong-polarity loop entry, the other rail made a dead short.
Pełna lista z hasłami do wyszukania na Allegro jest w pliku SHOPPING.md. Najważniejsze:
The full list with Allegro search terms is in SHOPPING.md. The main items:
| CzęśćPart | IleHow many | UwagiNotes |
|---|---|---|
| Dioda 1N5408 (lub 1N5401…1N5407)Diode 1N5408 (or 1N5401…1N5407) | 70 | 60 potrzebnych60 needed |
| Transoptor PC817COptocoupler PC817C | 20 | 18 potrzebnych, 2 na czujnik18 needed, 2 per detector |
| Rezystor 100 Ω 0,25 WResistor 100 Ω 0.25 W | 20 | 18 potrzebnych18 needed |
| Rezystor 47 Ω 5 WResistor 47 Ω 5 W | 8 | 6 potrzebnych, 2 na pętlę6 needed, 2 per loop |
| ULN2003A (DIP-16) | 4 | 3 potrzebne. ULN2004A / ULN2004APG też pasuje, jeśli cewka HLS8L ma co najmniej 40 Ω3 needed. ULN2004A / ULN2004APG also fits if the HLS8L coil measures at least 40 Ω |
| Bezpiecznik resetowalny 0,5 A (MF-R050)Resettable fuse 0.5 A (MF-R050) | 3 | 2 potrzebne. Wersja przewlekana, nóżki co 5 mm. Zamienniki: RXEF050, RXE050, FRX050-60F2 needed. Through-hole, leads 5 mm apart. Equivalents: RXEF050, RXE050, FRX050-60F |
| Przetwornica step-down LM2596LM2596 step-down converter | 1 | 12 V → 5,0 V dla przekaźników HLS8L12 V → 5.0 V for the HLS8L relays |
| Złącza śrubowe ARK 5 mm, 2 / 3 piny5 mm screw terminals, 2 / 3 pins | 40 / 10 | 35 / 9 potrzebnych35 / 9 needed |
| Laminat jednostronny 100 × 160Single-sided board 100 × 160 | 6–7 | Płytki z kroku 1The boards in step 1 |
| Listwa goldpin, przewody połączeniowe, dystanse M3Pin headers, jumper wires, M3 spacers | — | Mega ↔ płytkiMega ↔ boards |
| Przewód do toru, 2 koloryTrack feeder wire, 2 colours | 2 × 10 m | Jeden kolor do szyny 1, drugi do szyny 2One colour for rail 1, the other for rail 2 |
Wszystkie płytki są jednostronne, z miedzią tylko od spodu, do zrobienia metodą termotransferu. Pliki są w folderze kicad/v0.4/, w podfolderze każdej płytki.
All boards are single-sided, with copper on the bottom only, made by toner transfer. The files are in kicad/v0.4/, in each board's own folder.
| PłytkaBoard | WymiarySize | Ile sztukHow many | Co robiWhat it does |
|---|---|---|---|
| DET4 | 148 × 66 mm | 1½ | 4 czujniki prądu odcinków. Drugą płytkę przetnij na pół: połówka obsługuje B5 i B6.4 block current detectors. Cut the second board in half: one half serves B5 and B6. |
| LOOP | 74 × 100 mm | 3 | Jedna na pętlę: czujnik i ogranicznik w szynie 1, ogranicznik w szynie 2.One per loop: detector and limiter in rail 1, limiter in rail 2. |
| RELAY3 | 66 × 92 mm | 3 | Jedna na pętlę: 3 przekaźniki HLS8L (wybór regulatora, 2 × obejście ogranicznika).One per loop: 3 HLS8L relays (controller choice, 2 × limiter bypass). |
| CTRL | 130 × 50 mm | 1 | Wejścia obu regulatorów z bezpiecznikami i szyny zbiorcze HOT1, HOT2, COMMON.Both controller inputs with fuses, and the HOT1, HOT2, COMMON buses. |
LOOP i RELAY3 mieszczą się obok siebie na jednym laminacie 100 × 160.
A LOOP and a RELAY3 fit side by side on one 100 × 160 board.
…-BCu-toner-1to1.pdf na drukarce laserowej w skali 100 % (bez „dopasuj do strony”).Print …-BCu-toner-1to1.pdf on a laser printer at 100 % scale (no "fit to page").| WiertłoDrill | Do czegoFor |
|---|---|
| 0,8 mm | PC817, rezystory 100 Ω, ULN2003APC817, 100 Ω resistors, ULN2003A |
| 1,0 mm | listwy goldpin, cewki przekaźników, bezpiecznikipin headers, relay coil pins, fuses |
| 1,2 mm | rezystory 47 Ω 5 W47 Ω 5 W resistors |
| 1,3 mm | złącza śrubowe, styki przekaźnikówscrew terminals, relay contacts |
| 1,6 mm | diody 1N54081N5408 diodes |
| 3,2 mm | otwory montażowe M3M3 mounting holes |
Przed trawieniem RELAY3 sprawdź przekaźnik HLS8L. Na końcu przekaźnika, z dala od cewki, są dwie nóżki styków. Przy wyłączonym przekaźniku zmierz multimetrem, która z nich łączy się z COM: to jest NC. Płytka zakłada, że NC jest po tej samej stronie co zacisk NC (u góry na rysunku RELAY3 poniżej). Jeśli Twój przekaźnik ma odwrotnie, obejście działałoby na odwrót. Wtedy płytkę trzeba poprawić przed trawieniem.
Before etching RELAY3, check an HLS8L relay. At the far end from the coil, the relay has two contact legs. With the relay off, find with a multimeter which of them connects to COM: that one is NC. The board expects NC on the same side as the NC terminal (at the top in the RELAY3 drawing below). If your relay has it the other way round, the bypass would work backwards. The board then needs a fix before etching.
Rysunki pokazują płytki od strony elementów, na podstawie prawdziwych plików KiCad. Dokładny rysunek montażowy każdej płytki jest w pliku …-assembly.pdf.
The drawings show the boards from the component side, made from the real KiCad files. The exact assembly drawing of each board is in …-assembly.pdf.
ReversingLoops.ino z folderu projektu.Install the Arduino IDE. Open ReversingLoops.ino from the project folder.Layout.h is not filled in yet: relays stay off, showing detectors only. To normalne, dopóki nie ma planu torów.The monitor shows: Layout.h is not filled in yet: relays stay off, showing detectors only. That is expected until the track plan exists.IN, TRK1 → jedna szyna, drugi przewód regulatora → druga szyna. Jedź: monitor pokazuje B1 A albo B1 B. Zmień kierunek: druga litera. Pokrętło na zero: B1 -.DET4 detector. Connect the A G B pins of cell BLOCK 1 to the Mega: A → A0, G → GND, B → A1. Take a piece of track with a loco. One controller wire → IN, TRK1 → one rail, the other controller wire → the other rail. Drive: the monitor shows B1 A or B1 B. Change direction: the other letter. Knob to zero: B1 -.LINE1 i TRK1, kołki A G B do A12, GND, A13 (S2). Lokomotywa jedzie wolno, bo prąd płynie przez ogranicznik 47 Ω. Tak ma być.LOOP. The same, through LINE1 and TRK1, A G B pins to A12, GND, A13 (S2). The loco runs slowly because the current goes through the 47 Ω limiter. That is expected.A, pociąg jedzie w stronę końca 1.The easiest way to find the ends is by driving (step 8): run a loco through the block. When the monitor shows A, the train is moving toward end 1.Layout.h.Write on the plan: the ends of every block, and which ends each gap joins. This is needed for Layout.h.Kolejność śrub NO / COM / NC na module 16 przekaźników może być inna niż na rysunkach. Zawsze czytaj napis wydrukowany obok śrub.
The NO / COM / NC screw order on the 16-relay module may differ from the drawings. Always read the label printed next to the screws.
IN 1 (a, b). Regulator 2 → IN 2.Controller 1 output → CTRL IN 1 (a, b). Controller 2 → IN 2.OUT 1: a → CH1 NC i CH2 NO. b → CH1 NO i CH2 NC.CTRL OUT 1: a → CH1 NC and CH2 NO. b → CH1 NO and CH2 NC.HOT1. CH2 COM → CTRL COMMON.CH1 COM → CTRL HOT1. CH2 COM → CTRL COMMON.OUT 2 → CH3 + CH4, CH3 COM → HOT2, CH4 COM → COMMON.Controller 2 the same way: OUT 2 → CH3 + CH4, CH3 COM → HOT2, CH4 COM → COMMON.HOT1 → NC przekaźników CH11–CH16. CTRL HOT2 → NO tych przekaźników. Krótkie mostki od śruby do śruby są w porządku.CTRL HOT1 → NC of relays CH11–CH16. CTRL HOT2 → NO of those relays. Short links from screw to screw are fine.IN komórki DET4. TRK1 tej komórki → szyna 1 odcinka.Relay COM → the DET4 cell's IN. That cell's TRK1 → the block's rail 1.COMMON → szyna 2 linii głównej, w 2–3 miejscach.CTRL COMMON → main-line rail 2, at 2–3 places.| OdcinekBlock | PrzekaźnikRelay | CzujnikDetector | Mega: czujnik A · BMega: detector A · B | Mega: przekaźnikMega: relay |
|---|---|---|---|---|
| B1 | CH11 | DET4 · BLOCK 1 | A0 · A1 | D27 |
| B2 | CH12 | DET4 · BLOCK 2 | A2 · A3 | D28 |
| B3 | CH13 | DET4 · BLOCK 3 | A4 · A5 | D29 |
| B4 | CH14 | DET4 · BLOCK 4 | A6 · A7 | D30 |
| B5 | CH15 | pół DET4 · BLOCK 1half DET4 · BLOCK 1 | A8 · A9 | D31 |
| B6 | CH16 | pół DET4 · BLOCK 2half DET4 · BLOCK 2 | A10 · A11 | D32 |
Każda pętla ma swoją płytkę LOOP, swoją płytkę RELAY3 i parę odwracającą na module.
Each loop has its own LOOP board, its own RELAY3 board and a reverser pair on the module.
| SkądFrom | DokądTo |
|---|---|
CTRL HOT1 / HOT2 | RELAY3 K1 NC / NO |
| RELAY3 K1 COM | para pętli: A NC i B NOloop pair: A NC and B NO |
CTRL COMMON | para pętli: A NO i B NCloop pair: A NO and B NC |
| para pętli: A COM / B COMloop pair: A COM / B COM | LOOP LINE1 / LINE2 |
LOOP BYP1-C / BYP1-NO | RELAY3 K2 COM / NO |
LOOP BYP2-C / BYP2-NO | RELAY3 K3 COM / NO |
LOOP TRK1 / TRK2 | szyna 1 / szyna 2 pętliloop rail 1 / rail 2 |
| PętlaLoop | Para (A + B)Pair (A + B) | Mega: paraMega: pair | Mega: RELAY3 kołek 1Mega: RELAY3 pin 1 | Mega: RELAY3 kołek 2 + 3Mega: RELAY3 pin 2 + 3 | Mega: czujnik A · BMega: detector A · B |
|---|---|---|---|---|---|
| S2 zewnętrznaouter | CH5 + CH6 | D24 | D33 | D36 | A12 · A13 |
| S3 wewnętrznainner | CH7 + CH8 | D25 | D34 | D37 | A14 · A15 |
| S4 pętla 3loop 3 | CH9 + CH10 | D26 | D35 | D38 | D39 · D40 |
| Piny MegiMega pins | DokądTo | Do czegoWhat for |
|---|---|---|
| D22 | moduł IN1 + IN2module IN1 + IN2 | odwracanie regulatora 1controller 1 reverser |
| D23 | moduł IN3 + IN4module IN3 + IN4 | odwracanie regulatora 2controller 2 reverser |
| D24 · D25 · D26 | moduł IN5+6 · IN7+8 · IN9+10module IN5+6 · IN7+8 · IN9+10 | odwracanie pętli S2 · S3 · S4loop S2 · S3 · S4 reversers |
| D27 … D32 | moduł IN11 … IN16module IN11 … IN16 | wybór regulatora B1 … B6controller choice B1 … B6 |
| D33 · D34 · D35 | RELAY3 kołek 1 (S2 · S3 · S4)RELAY3 pin 1 (S2 · S3 · S4) | wybór regulatora pętliloop controller choice |
| D36 · D37 · D38 | RELAY3 kołek 2 + 3 (S2 · S3 · S4)RELAY3 pin 2 + 3 (S2 · S3 · S4) | obejście ogranicznikówlimiter bypass |
| A0 … A11 | DET4: A · B odcinków B1 … B6DET4: A · B of blocks B1 … B6 | czujniki prąducurrent detectors |
| A12 … A15 | LOOP S2, S3: A · BLOOP S2, S3: A · B | |
| D39 · D40 | LOOP S4: A · BLOOP S4: A · B | |
| GND | GND modułu, każdy kołek G, RELAY3 Gmodule GND, every G pin, RELAY3 G | wspólna masashared ground |
Layout.h.The pin numbers are set in Layout.h.Wszystkie przekaźniki są wyłączone: każdy odcinek dostaje regulator 1, pętle są na ograniczonym prądzie. Mega pokazuje tylko czujniki.
All relays are off: every block gets controller 1, the loops are on limited current. The Mega only shows the detectors.
A. Tam jest koniec 1.Block ends. Drive a loco slowly through every block and every gap. For each block, write down which way the train moves while the monitor shows A. That way is end 1.Layout.hB · The track table: Layout.hTen krok robi się na komputerze, gdy plan torów jest gotowy. W pliku Layout.h każda przerwa to jedna linia: odcinek, jego koniec, drugi odcinek, jego koniec. Przykład:
This step is done on the computer once the track plan is ready. In Layout.h every gap is one line: block, its end, the other block, its end. Example:
#define LAYOUT_FILLED_IN 1
static const EdgeDef EDGES[] = {
{BLK_B1, 1, BLK_B2, 0}, // B1 → B2
{BLK_B2, 1, BLK_S2, 0}, // B2 → loop S2, first leg
{BLK_B2, 1, BLK_S2, 1}, // B2 → loop S2, second leg (balloon loop)
};
static const uint8_t NEDGES = 3;
LAYOUT_FILLED_IN na 1 i wgraj program jeszcze raz. Jeśli tabela ma błąd, monitor pokaże Layout.h error in EDGES line … i przekaźniki zostaną wyłączone.Set LAYOUT_FILLED_IN to 1 and upload the program again. If the table has a mistake, the monitor shows Layout.h error in EDGES line … and the relays stay off.own B1 1. Pociąg 2, np. na B4: own B4 2.Put train 1 on a block, e.g. B1, and type own B1 1 in the monitor. Train 2, e.g. on B4: own B4 2.loop-flip i loop-enter.Drive into each loop. At the gap there may be a short jerk, and the monitor shows loop-flip and loop-enter.contested. Mega nie zatrzyma pociągu.Do not drive into the other train's block. When both trains head for the same free block, the Mega switches nothing and prints a contested warning. The Mega cannot stop a train.own).Train moved by hand: tell the Mega where it is with own.| KomendaCommand | Co robiWhat it does |
|---|---|
state | tabela odcinków: właściciel, regulator, stan pętli, prądblock table: owner, controller, loop state, current |
own B3 2 | pociąg regulatora 2 stoi na B3the train of controller 2 stands in B3 |
own B3 - | B3 jest pustyB3 is empty |
forget | kasuje zapisany stan: wszystkie odcinki wolne, regulator 1clears the saved state: every block free, controller 1 |
| KomunikatMessage | ZnaczenieMeaning |
|---|---|
acquire | pociąg wjechał na wolny odcinek; odcinek należy teraz do jego regulatoraa train entered a free block; the block now belongs to its controller |
release | pociąg opuścił odcinek; odcinek jest wolnya train left a block; the block is free |
assign | wolny odcinek przed pociągiem przełączony na jego regulatora free block ahead of a train switched to its controller |
preset | biegunowość pętli ustawiona przed wjazdem pociąguloop polarity set before the train arrives |
loop-flip | krótkie zwarcie przy przerwie; pętla odwróconaa short at the gap; the loop was reversed |
loop-enter | cały pociąg w pętli: pełna moc, regulator i pętla odwrócone razemthe whole train is in the loop: full power, controller and loop reversed together |
loop-reverse | pociąg zmienił kierunek w pętlithe train changed direction inside the loop |
loop-fault | zwarcie przy przerwie nie ustąpiło; sprawdź okablowanie pętlithe short at the gap did not clear; check the loop wiring |
contested | oba pociągi jadą na ten sam odcinekboth trains head into the same block |
unexpected | prąd na odcinku, przy którym nie ma znanego pociągu; użyj owncurrent in a block with no known train next to it; use own |
| ObjawSymptom | Możliwa przyczynaPossible cause | Co zrobićWhat to do |
|---|---|---|
| Regulator 2 nic nie napędzaController 2 drives nothing | Tabela toru niewypełniona: przekaźniki są wyłączone, wszystko jest na regulatorze 1Track table not filled in: the relays are off, everything is on controller 1 | Krok 8 BStep 8 B |
| Pociąg w pętli jedzie bardzo wolnoA train crawls inside a loop | Obejście nie działa: brak 5 V na RELAY3 albo brak mostka 2–3The bypass does not work: no 5 V on RELAY3, or no 2–3 bridge | Sprawdź przetwornicę i RELAY3 (krok 3)Check the converter and RELAY3 (step 3) |
| Pociąg staje za przerwąA train stops past a gap | Następny odcinek jest na drugim regulatorze albo ma luźny przewódThe next block is on the other controller, or has a loose wire | Wpisz state. Sprawdź przewody tego odcinkaType state. Check that block's wires |
| Szarpnięcie lub wyłączenie regulatora przy przerwie między odcinkamiJerk or controller cut-out at a gap between blocks | Pociąg wjechał na odcinek drugiego regulatoraThe train entered a block of the other controller | Nie wjeżdżaj na odcinek drugiego pociągu. Sprawdź state i ownDo not drive into the other train's block. Check state and own |
loop-fault w monitorzeloop-fault in the monitor | Zamienione LINE1 / LINE2, zła para na module albo brak przerwyLINE1 / LINE2 swapped, wrong pair on the module, or a missing gap | Sprawdź okablowanie pętli (krok 5c) i przerwyCheck the loop wiring (step 5c) and the gaps |
| Przekaźniki szybko stukają w kółkoRelays chatter | Brudne koła lub szyny, słaby stykDirty wheels or rails, poor contact | Wyczyść tor i koła. Jeśli nie pomoże, zapisz, gdzie i kiedy to się dziejeClean the track and wheels. If that does not help, note where and when it happens |
| Nic nie jedzie na jednym regulatorze, bezpiecznik na CTRL jest ciepłyNothing runs on one controller, its fuse on CTRL is warm | Prawdziwe zwarcie: wykolejenie albo metal na torzeA real short: derailment or metal on the track | Usuń przyczynę i odczekaj minutę. Bezpiecznik resetowalny wraca samRemove the cause and wait a minute. The resettable fuse recovers by itself |
Layout.h error in EDGES line …Layout.h error in EDGES line … | Błąd w tabeli toru, np. przerwa między odcinkami łączy dwa końce 1A mistake in the track table, e.g. a gap between blocks joins two ends 1 | Popraw tę linię (liczoną od 0) i wgraj programFix that line (counted from 0) and upload the program |