Go Down

Topic: Railstars CmdrArduino lib help (Read 4922 times) previous topic - next topic

mowcius

Quote
to make a complete Arduino-based command station.

Pretty neat :)

Don Goodman-Wilson


That explains alot, with the booster hooked up to pin 11 it's working perfectly!


Excellent! Glad to hear it! I'll merge the branches later today.

The Mega has a different pinout for the internal timers, which necessitates using a different pin for the signal output. I clearly need to better document this fact!

Do let me know if any other issues crop up, or if there's a feature you'd like to see added, and keep us abreast of the fun things you do with CmdrArduino!

beige

You asked for more issues, and I think I have one...

CV programming, using the latest version I can't program anything, however if I use the old version from January I can program CV2 and above, programming the short address CV doesn't have any effect..

I've tried this on 2 decoder with the same effect, using the Hornby Select I can program the address, but for some reason it re-programs lots of unrelated CVs, which is annoying...

Don Goodman-Wilson

THat's no good! I'll have a look a bit later to see what's changed.

You can't program an address in ops mode, in general. I don't know if that's in the NMRA specs or not, but my Digitrax Zephyr won't do it either. So that, at least, is not a bug :D But the other things are. Do you think there is a pattern to what's getting programmed?

beige

The only thing I've noticed is while CV programming works fine in the old version of the library, if setSpeed128 etc. are called in the same loop as opsProgramCV it all seems to become very unreliable, only programming 10% of the time.

Need to do some more experiments to narrow it down yet i think.


As to the lack of address change is ops mode, thats not very useful, I guess service mode is needed.

Don Goodman-Wilson

Service mode is, unfortunately, another can of worms. Need sensitive current-detection hardware. A different project altogether. But on my plate!

samhain77

#21
Aug 06, 2015, 02:06 am Last Edit: Aug 08, 2015, 10:46 am by samhain77
Unfortunately eStop bug still exist on my Arduino Uno. :(

samhain77

#22
Aug 08, 2015, 10:47 am Last Edit: Aug 08, 2015, 11:00 am by samhain77
When I try to run my loco after Stop, the loco can move only forward with small speed and functions is not working. This bug appears very often. I have tried to disconnect wires from rails and connect them again, but it not helps me, only Arduino reset helps.

BTW: For Arduino control I'm using IR remote on Timer 2.

pgahtow

#23
Aug 11, 2015, 10:29 am Last Edit: Aug 11, 2015, 10:31 am by pgahtow
I had also trouble years ago with the CmdrAdruino Library. So I hope I can help.

I build up my own DCC Master (Zentrale) with the CmdrArduino Lib but the Library doesn't repeat DCC loco informations. :-(
So I changed nearly everything inside of the library. It now repeats the information and save them, so you can request the latest state of loco or switches. You can now also programm (CV) on the main track and change the timer for the signal generator. Of course, the eStop works for all and for each loco and I add a power command to stop the Signal gernerator.
Here you can Download my changed version of the library: Arduino DCC Interface Library
I hope you find this changes helpful and it works?
BTW: I'm sorry that my website doesn't support another language then german.

samhain77

#24
Aug 13, 2015, 02:14 pm Last Edit: Aug 13, 2015, 02:15 pm by samhain77
Hello Philipp,
Thank you for your library.
I have tried it and discovered the following things:
- Speed "0" is working as regular stop (in original library it works as emergency stop)
- Speed "1" is working as emergency stop (in original library it works as regular stop)
- Speed "-1" is working as high backward speed (in original library it works as regular stop from low backward speed)
- Speed "-127" is working as low backward speed (in original library it works as high backward speed)
Are those bugs or features?

FrktLille

As samhain77 does, I have tried and found the following problems :
- Speed "0" is working as regular stop (in original library it works as emergency stop)
- Speed "1" is working as emergency stop (in original library it works as regular stop)
- Speed "-1" is working as high backward speed (in original library it works as regular stop from low backward speed)
- Speed "-127" is working as low backward speed (in original library it works as high backward speed)


There are a lot of errors in code proposed by pgahtow in his DCCInterfaceMaster Library Arduino DCC Interface Library v2.3
There was some errors in CmdrArduino proposed by Don Goodman-Wilson code too ...
The main error in both is usage of unsigned integer instead of integer (signed)  :smiley-confuse: .Using this type, reverse running can't be detected, and negatives value are read as positive from 128 to 255 !


Merging the new code from pgahtow and the original one from Don Goodman, and correcting some errors, i found the solution.

You have now to change the code as follow to run correctly (I have only check the 128 steps speed control, I didn't check regular stop or emergency stop yet).
  • in "DCCPacketScheduler.h"
    Replace "bool setSpeed128(uint16_t address, uint8_t speed);"
    with      "bool setSpeed128(uint16_t address, int8_t speed);"
  • in "DCCPacketScheduler.cpp"
    Replace method : "bool DCCPacketScheduler::setSpeed128(uint16_t address, uint8_t speed) { ... }"
    with (major changes in red) :     
    bool DCCPacketScheduler::setSpeed128(uint16_t address, int8_t speed) {
       if (address == 0) return false;

       byte slot = LokStsgetSlot(address);
       bitWrite(LokDataUpdate[slot].f0, 5, !bitRead(speed, 7));   //Dir
       uint8_t abs_speed = abs(speed);
       LokDataUpdate[slot].speed = abs_speed;

       
       if ((LokDataUpdate[slot].adr >> 14) != B11) //3=>128steps, write into register
          LokDataUpdate[slot].adr = LokDataUpdate[slot].adr | 0xC000;

            uint8_t speed_data_uint8_ts[] = { 0x3F, 0x00 };
            speed_data_uint8_ts[1] = abs_speed;
            speed_data_uint8_ts[1] |= (0x80*!bitRead(speed, 7));
    //flip bit 7 to indicate direction;

       /*
       why do we get things like this?
       03 3F 16 15 3F (speed packet addressed to loco 03)
       03 3F 11 82 AF  (speed packet addressed to loco 03, speed hex 0x11);
       */
       DCCPacket p(address);
       p.addData(speed_data_uint8_ts, 2);
       p.setRepeat(SPEED_REPEAT);
       p.setKind(speed_packet_kind);

       //speed packets get refreshed indefinitely, and so the repeat doesn't need to be set.
       //speed packets go to the high proirity queue

       //return(high_priority_queue.insertPacket(&p));
       if (railpower == ESTOP)   //donot send to rails now!
          return periodic_refresh_queue.insertPacket(&p);
       return repeat_queue.insertPacket(&p);
    }
  • You can now call this method in .ino file with function like
    "dps.setSpeed128(locAddr,speedValue);  // Loco Addr as Int, SpeedValue as Int (-127 <-> 127)"


Have fun !

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy