Arduino DCC library with other libraries

Hello,

This is my first post on the Arduino Forum. I found a lot of information here but this is a specific problem.
So, I maked a sketch for my hobby (model-trains), the sketch turns lights in the houses on and off, switches and signals, servo's for crossings and etc.
Everything works perfectly, but when I ad the DCC library into my sketch, the Arduino doesn't read anything. The other stuff like lights, ... works well.

The example of the DCC library works perfectly but not in my sketch. I asked 3 other people to check my sketch and they can't find the problem, they think that the libraries give some conflicts.
These are my libraries:

Here is my sketch code (comments are in Dutch):
I can't post them here because it is to long, so here is the link to my website:
http://www.modeltreinen.comze.com/Arduino/ModuleDecoderV1_5_DCC_2.ino

'Rijweg' = actions to stop/start a train on the right track.
'Overweg' = a crossing.
'Terugmeding' = feedback.
'Sein' = a signal.
'Wissel' = a switch.

I hope that somebody can help me...

Kind regards,
minitreintje

P.S.: Sorry for my bad English, I isn't so easy to describe this problem in English for me...

Hello,

Problem is solved! The Arduino hasn't enough time to read the packages and the maker of the DCC library solved the problem.

regards,
minitreintje

Since I'm also interested in this, is the version 4 of the library the new one with resolved issues?

No, he just ad some code for me in a email. The Arduino reads only the DCC-packages if there is a DCC-package detected.

regards,
minitreintje

Would you mind forwarding me that email?

awesome dude

Like you wish:

The first way is to sprinkle multiple calls to DCC.loop() within your loop function. In psuedo code, your loop() is roughly:

void loop()
{
if( something )
{
Do work()
}
if( something )
{
Do work()
}
if( something )
{
Do work()
}
if( something )
{
Do work()
}

DCC.loop()
}

Try it like this:

void loop()
{
DCC.loop()
if( something )
{
Do work()
}
DCC.loop()

if( something )
{
Do work()
}
DCC.loop()

if( something )
{
Do work()
}
DCC.loop()

if( something )
{
Do work()
}
DCC.loop()
}

This gives the DCC library more time to process the bits coming in at interrupt time. I'd also remove, or limit, the calls to Serial.println() within loop. Calling it usually means missed data.

========================================================================================================

The second approach is a little more complicated, but a more robust and the one I'd recommend.

int receivedDataPacket = 0;

void BasicAccDecoderPacket_Handler(int address, boolean activate, byte data)
{
{ code exactly as you have it }

receivedDataPacket = 1;
}

void loop()
{
static int doWorkCountdown = 0;

if( doWorkCountdown>0 && receivedDataPacket==0 )
{
doWorkCountdown--;
DCC.loop();
return;
}

doWorkCountdown = 1000;
receivedDataPacket = 0;

{ code exactly as you have it in loop() }
}

What this does is make loop() only call DCC.loop() until a valid packet arrives. Then, only when a valid data packet arrives, do the large amount of work.

The doWorkCountdown variable allows the work to be executed once every 1000 calls. This may or may not be needed based on whether the large work happens from more than just DCC requests. It also lets the work happen when there is power but no DCC signal.

I guessed at the 1000 value. You'll know whether it even needs to execute without DCC data or not and can experiment with an appropriate value.

regards,
minitreintje

Thank you.
Have some karma.

Hi, first post on this most useful forum, is the ' modified working code available ' for personal use / development ?

choddles:
Hi, first post on this most useful forum, is the 'modified working code available' for personal use / development ?

Look at the post from 'minitreintje' on Mar 17, 2013.

It shows you that the solution is to change the User Sketch, not the DCC Library.

  • You can see that there are lots of added calls to DCC.loop();

These are inserted around the code written that processes the DCC Packets that arrive.

The issue is caused by the lack of Interrupt Servicing while the User's Sketch is running. In Real-Time, 'DCC.loop' isn't there to receive the Packet when it arrives, so it is lost. The added/repeated calls to 'DCC.loop' ensure that there are sufficient checks to avoid missing a packet.

With a limit of 16MHz for the MCU Clock, this limits how many Instruction Cycles are available between DCC Packets. As an Arduino Sketch is written in C, there are lots of Instruction Cycles that might get used between each line of C code.

Today is my first post here (I joined today too). I would like to be able to write Arduino Sketches for my own DCC Model Railway. Previously, I have been using Assembler on MicroChip MCUs (35 years in Software Engineering). The possibility of doing Development much faster has piqued my interest in the Arduino. So, I went onto eBay this week, and have ordered a couple Nano's (Built in USB) and a couple of Pro Mini's (Plug-in USB).

Now, I wait for them to arrive from China. As you can see, I'm doing my Background Research while I wait for my parcels.

One of the purposes for looking at the Arduino is to process RailCom packets too. I haven't found many tools to assist with RailCom development.

Regards from 'Down Under', EnigmaTS.