Cov txheej txheem:

Tsheb ciav hlau Vaj - Arduino Wireless NMRA DCC: 4 Cov Kauj Ruam (nrog Duab)
Tsheb ciav hlau Vaj - Arduino Wireless NMRA DCC: 4 Cov Kauj Ruam (nrog Duab)

Video: Tsheb ciav hlau Vaj - Arduino Wireless NMRA DCC: 4 Cov Kauj Ruam (nrog Duab)

Video: Tsheb ciav hlau Vaj - Arduino Wireless NMRA DCC: 4 Cov Kauj Ruam (nrog Duab)
Video: tsheb ciav hlau(ລົດໄຟລາວ- ຈີນ) caij tau lawm nawb 2024, Hlis ntuj nqeg
Anonim
Image
Image
Tsim Cov Txheej Txheem
Tsim Cov Txheej Txheem

Ntxiv rau cov lus qhia yav dhau los nrog DCC ntawm txoj kev tsheb nqaj hlau tuag, Kuv tau tsim lub tswv yim ntxiv nrog tes tuav DCC Command Station nrog cov keyboard thiab cov zaub LCD. Qhov Chaw Nres Nkoj muaj txhua qhov coding xav tau rau NMRA DCC cov lus qhia, txawm li cas los xij tsis txhob txuas mus rau txoj kab, cov ntaub ntawv raug xa los ntawm xov tooj cua module RF24L01+ mus rau tus neeg txais xov tooj cua hauv lub tsheb lossis hauv qab qhov chaw - txhua qhov chaw tso cai.

Tau kawg, koj qhov chaw nyob yuav tsum muaj lub tshuab txiav txim siab lub peev xwm haum rau lub cav cav.

Kauj Ruam 1: Tsim Cov Txheej Txheem

Tsim Cov Txheej Txheem
Tsim Cov Txheej Txheem

Arduino Pro Mini yog lub hauv paus ntawm kev tsim qauv. Siv Fritzing los txhim kho Circuit thiab tsim PCBs.

Kuv muaj peev xwm siv tib lub PCB rau ob qho tib si xa thiab txais yog li txuag qee tus nqi.

Tus xa ntawv muaj kev sib txuas rau cov keyboard thiab LCD thaum tus txais tsis xav tau cov no thiab siv H-choj txhawm rau muab DCC cov zis rau thaj chaw.

Kev txhim kho ntxiv suav nrog kev sib txuas rau H-choj loj dua yog tias xav tau rau thaj chaw muaj zog dua.

PCF8574 tuaj yeem raug tshem tawm yog tias koj siv lub vijtsam LCD uas los nrog lub hnab ev tso cai rau SCA / SCL sib txuas ntawm Arduino los pub zaub uas siv tsuas yog 2 lub xov hlau. Parts list: Total = approx £ 60 for DCC Command Station + 1 receiverAdministrative receivers cost =.00 10.00 kwv yees txhua. + roj teeb

Arduino Pro Mini. x 2 = 00 4.00

4x3 membrane keypad = 00 3.00

20 x 4 LCD zaub = £ 7.00

PCF5874 = 80 1.80

NRF24L01+. xov tooj cua modules x 2 = 80 5.80

Kev tsim PCB rau 10 tawm (lossis Vero board tuaj yeem siv tau) = £ 24 lossis 80 4.80 rau 2off

3.3 v Regulator = £ 0.17 (pob ntawm 25 los ntawm RS Comp)

5v Regulator LM7805 = £ 0.30

H-choj SN754410ne = 00 3.00

Lloytron rov them 2700 maH AA roj teeb x 12 = £ 22.00. (qis dua MAH cov roj teeb tau pheej yig dua)

Capacitors, pots, pins, txuas, thiab lwm yam = £ 2.00 kwv yees kwv yees

Cov ntaub ntawv 190x110x60 mm =.00 8.00

Transmitter - xov tooj them / roj teeb = 00 2.00

Kauj ruam 2: Transmitter

Tshaj Tawm
Tshaj Tawm

Daim duab qhia hluav taws xob tau qhia qhov twg D2 rau D8 pins ntawm Arduino Pro Mini txuas nrog lub keypad. A 100k ohm potentiometer txuas nrog Analog tus pin A0 rau kev hloov kho nrawm. Qhov SDA thiab SCL pins tsim PCF8574 nti txuas nrog pins A4 thiab A5 ntawm Arduino Pro Mini los ntawm kev siv cov xaim hluav taws xob txuas rau cov pins ntawm txheej sab saum toj ntawm Pro Mini.

Daim duab Arduino tau txuas rau rub tawm.

Kuv tau siv 20 x 4 LCD zaub tso cai rau 4 kab ntawm cov ntaub ntawv nrog 20 tus cim ib kab.

1 txog 9 = qhov chaw nyob loco * = kev taw qhia 0 = teeb # = Cov ntawv qhia zaub mov rau cov yuam sij 1 txog 8

Cov lus piav qhia yooj yim ntawm Arduino Pro Mini kos duab: Kab kab ntawv no teeb tsa DCC lus hauv HEX hom ntawv. struct Message msg [MAXMSG] = {

{{0xFF, 0, 0xFF, 0, 0, 0, 0}, 3}, // tsis muaj lus nug

{{locoAdr, 0, 0, 0, 0, 0, 0}, 3} // 3 byte chaw nyob

};

Txhawm rau khaws cov teeb tsa rau txhua qhov chaw, cov kab ntawm cov kab ke tau teeb tsa raws li hauv qab no:

int la [20]; // array tuav cov lej loco

int sa [20]; // array tuav qhov tseem ceeb ceev

int fda [20]; // array tuav dir

int fla [20]; // array tuav lub teeb

int f1a [20]; // array tuav kev lom zem1…..

int f8a [20]; // array tuav fun8

Txhawm rau kom DCC cov lus qhia hloov kho thaum peb mus:

Rau cov lus qhia ceev: tsis muaj qhov hloov pauv_speed (teeb tsa Xov & x) {

x.data [0] = locoAdr;

x.data [1] = 0x40; // locoMsg nrog 28 qib nrawm}

Rau cov lus qhia ua haujlwm:

tsis muaj dab tsi hloov_group1 (struct Message & x) {

x.data [0] = locoAdr;

x.data [1] = 0x80; // locoMsg nrog pab pawg ib qho kev qhia 0x80}

Lub voj loj ntawm daim duab:

lub voj void (tsis muaj dab tsi) {yog (read_locoSpeed ()) {assemble_dcc_msg_speed ();

xa_data_1 (); // xa cov ntaub ntawv los ntawm wireless

ncua (10);

xa_data_3 (); // tso saib cov ntaub ntawv ntawm LCD zaub

xa_data_4 (); // tso saib cov ntaub ntawv ntawm cov saib txuas}

yog (read_function ()) {

sib dhos_dcc_msg_group1 ();

xa_data_1 ();

ncua (10);

xa_data_3 (); }}

Hloov cov ntaub ntawv thaum qhov hloov pauv nrawm:

boolean read_locoSpeed () Qhov no txheeb xyuas qhov chaw nyob tshiab, nrawm lossis teeb tsa thiab hloov kho HEX 'cov ntaub ntawv' raws li qhov no. Ntawm no kuv tau teev 28 qib nrawm thiab kom tau raws li NMRA tus qauv S 9.2, cov ntaub ntawv nrawm yuav tsum pom los ntawm saib lub rooj hauv 'speed_step ()'

void speed_step () {hloov (locoSpeed) {

rooj plaub 1: cov ntaub ntawv | = 0x02; tawg;

rooj plaub 2: cov ntaub ntawv | = 0x12; tawg;

rooj plaub 3: cov ntaub ntawv | = 0x03; tawg;

………

rooj plaub 28: cov ntaub ntawv | = 0x1F; tawg; }}

Hloov cov ntaub ntawv thaum cov haujlwm hloov pauv:

boolean read_function ()

yog (fla [locoAdr] == 0) {data = 0x80;

} // Lub taub hau teeb tawm

yog (fla [locoAdr] == 1) {

cov ntaub ntawv = 0x90;

} // Lub taub hau teeb rau

Rau txhua Txoj Haujlwm:

yog (f2a [locoAdr] == 0) {data | = 0; }. // Muaj nuj nqi 2 tawm

yog (f2a [locoAdr] == 1) {

cov ntaub ntawv | = 0x02; // Muaj nuj nqi 2 ntawm} 'cov ntaub ntawv' tau tsim los ntawm kev sib txuas ['| =' sib xyaw me ntsis lossis] HEX cov lej rau txhua txoj haujlwm.

Kauj ruam 3: Txais

Txais
Txais

Daim duab hluav taws xob tau qhia pom qhov twg pins 5 thiab 6 ntawm Arduino Pro Mini tau siv los muab DCC teeb liab muab rau H-choj. H-choj khub tau txuas nrog ua ke kom nce peev txheej tam sim no. Nyob ntawm qhov tam sim no kos los ntawm qhov chaw, lub rhaub dej kub yuav xav tau txuas nrog 16 tus pin DIP ntaus ntawv, lossis lub luag haujlwm hnyav H-choj yuav txuas nrog sab nraud.

Daim duab Arduino tau txuas rau rub tawm. Qhov teeb liab DCC tau tsim los ntawm lub moos khiav ntawm 2MHZ

void SetupTimer2 () ua txoj haujlwm no.

Lub moos suav nrog 'luv luv pulses' (58us) rau '1' hauv DCC cov ntaub ntawv thiab 'pulses ntev' (116us) rau '0' hauv DCC cov ntaub ntawv.

Lub voj void, tau txais cov ntaub ntawv los ntawm xov tooj cua thiab yog tias pom txoj hlua raug, cov ntaub ntawv hloov pauv mus rau DCC cov ntaub ntawv.

void loop (tsis muaj dab tsi) {yog (radio.available ()) {bool ua = tsis tseeb; ua = radio.read (inmsg, 1); // nyeem cov ntaub ntawv tau txais

char rc = inmsg [0]; // muab tus cwj pwm nyeem rau hauv kab ntawv no

yog (rc! = 0) {. // yog tus cwj pwm tsis sib npaug rau xoom

inString.concat (rc); // tsim cov lus}

if (rc == '\ 0') {// if character is '/0' kawg ntawm cov lus

Serial.println (inString); // luam tawm cov lus sib dhos

hlua (); // de-build txoj hlua xov kom tau txais DCC cov lus qhia

} } }

Kauj ruam 4: Khiav Locos

Khiav lub Locos
Khiav lub Locos

Txhawm rau zam kev cuam tshuam ntawm cov ntaub ntawv los ntawm kev khiav ntau lub tsheb ciav hlau ntawm tib txoj kev, koj yuav tsum txiav tawm kev sib cuag ntawm lub log thiab txoj kab rau txhua qhov chaw thiab tsheb thauj neeg ua haujlwm.

Txaus siab rau cov tsheb ciav hlau khiav dawb tsis hais txog qhov xwm txheej twg - qhov txawv li cas! Tsis muaj teeb meem, tsis muaj qhov pib nres thiab tsis xav tau kev ntxuav.

Cov roj teeb uas kuv siv yog rov tau LLoytron AA x 12. Kuv tau tsim lub roj teeb tshwj xeeb rau lawv uas them 6 ib zaug. (saib qhia tau)

Pom zoo: