Control mega by nano : need experienced knowledge!

hi all,

at this hot summerday in germany cant work hard but thinking
on idea with 2 arduino's for model railway issues

1 arduino nano v3 with roadway-manager sketch
should control arduino mega2560 which should manage all
interfaces to switch-servos, signals, locomotives (motor-current via bridges)

in particular :

  1. the nano gets 5V from extra dc-dc-modul
  2. the mega gets 8V from extra dc-dc-modul
  3. is it ok to connect GND between them ?
    4a) is it ok to connect a nano output to
    a mega input (may be over a resistor ca 1k) ?

4b) is it ok to connect a mega output to
a nano input (may be over a resistor ca 1k) ?
[thats for info from passed trains by light-barriers]
5) is it necessary to do something with RX/TX ?

I have not experience with these issues and my
english ... not my mother-language, sorry

Not so much OK but it is essential.

You can also connect inputs to outputs from any processor.

No need for this unless you plan to use them as part of the system to communicate between the two micro computers.

Note it is often much easier to use one Arduino with port expanders than to use two.

Not only OK, but essential

Yes

Yes

Only if you use a serial interface to communicate between the 2 boards, but in any case, don't use pins 0 and 1 on either board

Why not run all of the system on the Mega and avoid communication between 2 Arduinos. How do you intend that the Nano should communicate with the Mega and control it ?

1 Like

The project will be simpler without the Nano, certainly. But, is it your expectation that, in future, there might be more than one Mega in the system(distributed across a large room, for example), and the Nano will be managing them all? That is one usage scenario that might work, though in that case depending on what work is involved, you may find the memory limitations of the Nano quite awkward.
C

thanks to all for your interest !

my mention is to separate programming projects for easier check on errors
in my mind
first the mega sketch should work with all planned hardware and is able to
control this manually and has to work perfectly
after this the nano control sketch is easier to check against programming errors and unknown problems

If the Maga can (must) do everything that you need then why the need for the Nano ? What does it bring to the party except complexity ?

i've to tell what my mind goes on
i'm afraid combining roadway-manager-jobs and hardware-control-jobs
in only one sketch will be too complex in structure to handly
..and someone should be aware in dealing with millis or delay.

Fortunately the just tested capacitive-sensors work well ,
unbouncing seem not to be necessary..one problem eliminated

On the contrary, it may be much easier to manage if there is any need for the two purposes to communicate. Since you are asking about connecting inputs and outputs of the two controllers, I presume you do wish them to co-operate.

You most certainly do not want to be using "delay()".

good morning to all,

You most certainly do not want to be using "delay()"

I've read here many opinions about millis and delay,
not all preferred miliis.. I use millis instead of delay ,
but this very rarely..

Do you use millis in a non blocking way? If you do that is identical to using delay, it blocks any further progress until it is over.

I guess that that should be "If you don't" :wink:

1 Like

hi this late evening,
what about space-consuming by a big sketch ?
to combine the jobs in 1 sketch it will expand , for instance
is class-building space-consuming ?
with java on default pc its not a problem, but here ?

One question: is your entire model railway layout powered by one central device and shares the same polarity?

If you want two devices to communicate with each other, they need either a common ground, or you could separate them with an optocoupler.

If your layout is split into multiple areas with different power supplies, there is no guarantee that they will be on the same phase, which at least to my understanding means it would be unwise to directly connect their grounds and you really should put an optocoupler between them.

On the other hand, if all your tracks have electric links between them anyway, so there's only one single ground on your entire layout, directly connecting the two Arduinos' grounds should be fine. (If you want to separate them anyway, an optocoupler would still work.)

Note: optocouplers only work on fairly slow data lines, even something like MIDI requires a pretty good optocoupler and I'm not familiar enough with digital model railway systems like DCC to say for sure if their signals would be able to travel through an optocoupler.

If your filling up a mega then you need to be quite poor at writing code to run out of space,

hi all,

about GND : it is not a great model railway..there is no protocol..there are
several trackline.pieces powered by bridges and turned on/off by ardiuno.
the 5 switches (5 servos) have common power supply and may have common ground

..run out of space
is it posible to add memory card to add more space for sketch or is that only available for data (i.e. raodway-data) ?

thanks for your interest and have a good night..

I'm not sure if it is possible to run code from a SD card on the Arduino (or, more precisely, load it into RAM and execute it from there), but if it is, it'll be slow and painful. Either find ways to optimize your code for small binary size, or switch to a controller with more program memory. People on here will be able to help you with both if you show your code.

hi,

at the moment there are only pieces of code and brainstorming..after my opinion to split code jobwise on two ardiuno's(mega and nano) i was told to better combine code in One ardiuno (please look whole thread here)
which could expand code but i cant imagine how much..

where?

Start with one Arduino. Much easier to debug. Only go to a second if you are forced to and even there, look to get something more capable instead if you need extra flash, RAM or speed.

Note that this is not the way that most Arduinos work. They run code direct from flash memory as a modified Harvard architecture machine. The modification is that only code running in one sector of flash can write to other flash locations. That is where the boot loader code is situated. Normally this is a 1K sector and packing it in is difficult.