Arduino as a Rocnet (co)master node

http://wiki.rocrail.net/doku.php?id=roc ... netnode-en
Post Reply
DavidH
Posts: 26
Joined: 05.09.2015, 11:18

Arduino as a Rocnet (co)master node

Post by DavidH » 23.10.2015, 16:17

I want to use an Arduino (uno or mega) as a RocNet (I2C) node which can read/write to rocnet ports.

Any and all comments will be very welcome!

Thank-you
DavidH

SmileyVie
Posts: 93
Joined: 13.10.2011, 21:48
Location: Vienna, Austria

Re: Arduino as a Rocnet (co)master node

Post by SmileyVie » 23.10.2015, 19:21

Hello David,

Do you want to use an Arduino as a RocNetNode or as a Client connected to the RocNetNode? In the subject you wrote master node, in the text you wrote I2C node.... So for both possibilities I will answer you :)
Technically should both possible. For the Master you have to implement the protocol in the Arduino. If the ethernet library is able to use multicast I did not tried, but I guess it should not be a problem. Some years ago I played a little bit with this Protocol and Arduino, but it was before RocNetNode was build.

If you want to use the Arduino as an I2C slave attached to the RocNetNode you have to be careful about the timing.
To be compatible with an Pi-04 you have to use 100kHz bus speed.
I developed the RocDisplay, there I use the same microcontroller as it's build in an Arduino Uno.
The only thing is that the Raspberry Pi don't want clocksteching from a slave device.
I don't know how the Wire library in the Arduino manages the Bus timing in view of clock streching.
But I did not used the Arduino Framework, I wrote the I2C communication on my own.
If you don't send very long messages over the bus (like for a Display Communication it's needed) and all values that will be read from the Master are in RAM stored it should not be a problem. If you need to read them first from the eeprom it can happen that the wire library will strech the clock and the next clock impuls from the raspberry is too short that it's recognized on the microcontroller.
A workaround for that is, if you can't avoid clock strching, to strech the clock impuls more than 0,5*clockImpulsTime....

Hope this helps you ;)

Best Regards
Walter

DavidH
Posts: 26
Joined: 05.09.2015, 11:18

Re: Arduino as a Rocnet (co)master node

Post by DavidH » 23.10.2015, 20:33

Hello Walter,

Sorry about the confusion - I want to connect the Arduino to RocNet (using I2C (wire library) as a RocNet node, and to run it as a Master (along with the RaspPI) - hence the term co-master.

I understand that I2C can run with multiple Masters

The Pi will continue to be the Master node using ethernet to talk to RocRail. So no ethernet on the Arduino.

Hope that is clear

Thank-you

DavidH

SmileyVie
Posts: 93
Joined: 13.10.2011, 21:48
Location: Vienna, Austria

Re: Arduino as a Rocnet (co)master node

Post by SmileyVie » 23.10.2015, 23:29

Hello David,

OK as far as I understand you want to run the Arduino as master on the same I2C Bus - right?
I would rather use an ethernet shield on the Arduino and implement the documented protocol.

That the RocNetNode can read datas from the arduino as I2C slave. But you can't send as an I2C Master data's to the RocNetNode, because it don't act as an I2C slave. You have to implement the addresses and registers of the used IC's that the RocNetNode can read them.
That is maybe more tricky than to implement the protocol with an ethernet shield.

What kind of things you want do implement on this way?

BR
Walter

DavidH
Posts: 26
Joined: 05.09.2015, 11:18

Re: Arduino as a Rocnet (co)master node

Post by DavidH » 24.10.2015, 12:55

Hello Walter,

Yes. I want to run the Arduino as a (co) master on an I2C bus

My intention is to use an Arduino as an automated CTC or SignalBox which controls a shunting yard, (not a fancy a shunting puzzle), with a Lead Siding, an arrive/dispatch siding, and few other sidings accessible from the Lead, using trains with T4T couplers.

My intention is to communicate with RocRail using 'sensors', which will be read by RocRail as signals to trigger routes, driving the trains automatically, to wire each sidings 'In' event Hall Effect Sensor input (to the Pi02) direct to an Arduino Interrupt Pin - using a (wired diode protected ?) OR gate) so that the Arduino will know when a route has finished (without blocking the RocNet by repeated requests to read the sensor).

So no need for the raspPi or RocRail to know anything about the presence of an Arduino (any more than it knows about a human signalman pressing buttons) - so the Arduino can act as a (co)Master on I2C net, reading sensors by interrupts and setting the sensors using their I2C addresses (i.e act like a an automated set of signal 'Buttons').

Does all that make sense?

Regards,

DavidH

SmileyVie
Posts: 93
Joined: 13.10.2011, 21:48
Location: Vienna, Austria

Re: Arduino as a Rocnet (co)master node

Post by SmileyVie » 24.10.2015, 23:26

Hello David,

I looked in the datasheet of the RasPi IO chip BCM2835. Link here: http://www.farnell.com/datasheets/1521578.pdf
There is on Page 28 Point 3.1 described that it supports only single Master operation. So a second Master on the Bus would result in a chaos...
This means that an Arduino can not act as a co master... Only as an slave device on the Bus.

BR
Walter

DavidH
Posts: 26
Joined: 05.09.2015, 11:18

Re: Arduino as a Rocnet (co)master node

Post by DavidH » 25.10.2015, 18:27

Hello Walter,

Thank-you for the reference - it made me stop and think - BCM2835 is compliant with the I2C spec. clearly that means it does not implements all features.

If my arduino acts as an 'automated signalbox or CTC' then it simply replaces manually operated buttons etc. which would be wired direct to a Pi03 - so an Arduino Mega2560 with 54 digital I/O pins will be fine (or I could use Multiplex shield )- only one I/O will be used at any one time to generate inputs to RocRail - where it used to trigger routes.

Much simpler - but at the expense of wiring which I had hoped to avoid by using a bus - but an SPI bus is an option if I can find a cheap SPI node to support (say) 8 I/O pins).

regards and thank-you again,

DavidH

Post Reply

Return to “RocNetNode”