Jump to content
 

Arduino Applications and Programs


Simond
 Share

Recommended Posts

  • RMweb Premium

About a month ago, I decided that I needed to get on with rebuilding the control box for Porth Dinllaen loco shed, as I had only stuck a renumbered diagram over the old Greater Windowledge Railway diagram, and wired to suit.

 

The solution I’ve selected is Arduino based, using a Mega in the control panel as master, and a series of Nano as slaves. Actually the turntable has a Pro-Mini but the points and lighting will be nano controlled. Comms between the boards will be i2c.

 

That sounds like an interesting Project there Simon, I look forward to further developments.

Link to post
Share on other sites

  • RMweb Premium

Interesting stuff. We, the Winchester railway modellers, have done something similar on our Redbridge Wharf layout. No mega but a lot of nanos, 4 alone in one of the control panels. Beware long cable lengths with the I2C bus, we had to use bus extender chips.

 

Cheers

Dafe

Edited by eldavo
Link to post
Share on other sites

Thank you both. We’re talking two-and-a-half metres, which I hope will be fine.

 

Meanwhile I’m banging my head on the wall, as I’ve obviously done something daft...

 

MrsD is watching Les Miserables on telly. Not as many laughs as Les Dawson, I suppose the clue’s in the name so I’ll plough on!

 

Atb

Simon

Link to post
Share on other sites

Thank you both. We’re talking two-and-a-half metres, which I hope will be fine.

Interesting. I have never had a need to use I2C but from what I have read I am surprised that it works at 2.5m. I had the impression that 0.25m would be more like its limit.

 

...R

Link to post
Share on other sites

Oh dear. Maybe I’ll be disappointed...

 

Seems to be quite a lot of discussion on line, there are indeed comments about half-metre lengths, equally there is talk about tens of metres, even hundreds by using extenders.

 

If it doesn’t work, I’ll have to put in TX / RX lines for three slaves. Still got room in the wire!

 

Thanks for the heads-up

Simon

Link to post
Share on other sites

If it doesn’t work, I’ll have to put in TX / RX lines for three slaves. Still got room in the wire!

 

With a pullup resistor for the "master" RX and diodes on the slave TX lines (to prevent them pulling the master RX high) you can have several slaves connected to the same Serial connection.  I am doing that for a club layout where the turnout and uncoupler servos are controlled by Atmega 328s receiving instructions from a Mega as master on the control panel. 

 

...R

Link to post
Share on other sites

Robin

 

thanks.  I failed miserably to establish comms yesterday, so will borrow a laptop from work tonight to be able to have both master and slave on serial monitor - I'll then find out where I mucked up the program. 

 

Then I'll try it in place with the actual wire lengths and establish whether or not I can make it fly.  If it is not reliable, it is presumably due to cable capacitance, and could be addressed with resistors, I understand, however, given I have the spare ways in the umbilical, there is no great need to fight physics withthe i2c, nor indeed to daisy-chain the slaves with the parallel-UART approach, though it's interesting  - I presume you broadcast the same message to all, and each slave reacts only to the parts of the message for which it is programmed?

 

atb

Simon

Link to post
Share on other sites

  • RMweb Premium

Oh dear. Maybe I’ll be disappointed...

 

Seems to be quite a lot of discussion on line, there are indeed comments about half-metre lengths, equally there is talk about tens of metres, even hundreds by using extenders.

 

Simon, did you consider MERG's CBUS before deciding on I2c ?

Link to post
Share on other sites

 I presume you broadcast the same message to all, and each slave reacts only to the parts of the message for which it is programmed?

 

Yes. Each message contains the ID of the slave it is addressed to and when it receives a message with its ID the slave replies. That way only one slave uses the "bus" at any one time. If the master does not hear the Reply within a specified time it goes on the next slave - or deliberately causes the system to stop. The IDs are set on the slave boards with a jumper (or 2).

 

...R

Link to post
Share on other sites

Well, on hold for the evening as the kind IT soul who provided the laptop didn’t hear the “I’ll be installing the Arduino IDE” so forget to set me up as a local admin. So tomorrow...

 

Robin, ta, understood,

 

John, you’ve got a footnote on here saying “David” too. Did the mods set you up on another user called “PannierTank” by any chance? Or if you’re actually David, there’s a Pannier Tank called John on WT! It’s all quite confusing & curious!

 

Anyway, I was a MERG member for a couple of years, and found it quite interesting, however never really had time to indulge. I also found that there was plenty of “not at all challenging” and plenty of “oh, err, that’s a big project”, but not so much in the middle. The Arduinos are somehow more appealing.

 

Best

Simon

Link to post
Share on other sites

  • RMweb Premium

Well, on hold for the evening as the kind IT soul who provided the laptop didn’t hear the “I’ll be installing the Arduino IDE” so forget to set me up as a local admin. So tomorrow...

 

Robin, ta, understood,

 

John, you’ve got a footnote on here saying “David” too. Did the mods set you up on another user called “PannierTank” by any chance? Or if you’re actually David, there’s a Pannier Tank called John on WT! It’s all quite confusing & curious!

 

Anyway, I was a MERG member for a couple of years, and found it quite interesting, however never really had time to indulge. I also found that there was plenty of “not at all challenging” and plenty of “oh, err, that’s a big project”, but not so much in the middle. The Arduinos are somehow more appealing.

 

Best

Simon

 

Hello Simon,

 

My name is definitely David and I've been "Pannier Tank" on RMweb for quite a number of years going back to the original RMweb. There are a few derivatives of "Pannier Tank" here on RMweb "PannierTank" (no space) is one that springs to mind. Interesting that you should mention WT because I am also "Pannier Tank" (with a space) on WT (since the days of the Guvnor) but noticed today that I am unable to login to WT and am unable to reset my password. Maybe John has a variant of "Pannier Tank" (maybe with out a space?).. I'll have to try and contact admin to find out whats gone wrong with my login.

 

Ok on MERG; things have probably progressed quite a lot since you were a member, quite a few new CBUS modules.

Link to post
Share on other sites

Ok, David,

 

Yesterday, I was chatting with a Pannier Tank, by name of John, who had been offline from WT for sometime having lost his password. He signed off, “John”, but had a postscript on his post saying, as your post above “Regards, David”, which I questioned, as it was, as I said above, somewhat confusing.

 

It would appear that he has somehow (and I’m sure inadvertently) taken over your WT account. I’m sure a quick note to Adrian will sort it out!

 

(I made sure I’m SimonD on here, WT, and the G0G site too.)

 

If you need a hand, eg for me to pm Adrian, do let me know.

Best

Simon

Link to post
Share on other sites

  • RMweb Premium

Ok, David,

 

Yesterday, I was chatting with a Pannier Tank, by name of John, who had been offline from WT for sometime having lost his password. He signed off, “John”, but had a postscript on his post saying, as your post above “Regards, David”, which I questioned, as it was, as I said above, somewhat confusing.

 

It would appear that he has somehow (and I’m sure inadvertently) taken over your WT account. I’m sure a quick note to Adrian will sort it out!

 

(I made sure I’m SimonD on here, WT, and the G0G site too.)

 

If you need a hand, eg for me to pm Adrian, do let me know.

Best

Simon

 

Very strange! I would appreciate it if you could PM Adrian and let him know what's going on.

Link to post
Share on other sites

Yes. Each message contains the ID of the slave it is addressed to and when it receives a message with its ID the slave replies. That way only one slave uses the "bus" at any one time. If the master does not hear the Reply within a specified time it goes on the next slave - or deliberately causes the system to stop. The IDs are set on the slave boards with a jumper (or 2).

 

 

That is how the MERG RPC System works too, using RS485 as the half-duplex transport mechanism. The system and its protocol have been available to members for over 20 years now (the G16 range of MERG Technical Bulletins), and it now includes many other options which have been developed as a result.

Edited by Gordon H
Link to post
Share on other sites

That is how the MERG RPC System works too, using RS485 as the half-duplex transport mechanism.

I am not using RS485 as it is not an in-built feature of Arduinos and the distances for my data have not yet required me to add the extra hardware.

 

...R

Link to post
Share on other sites

Well, on hold for the evening as the kind IT soul who provided the laptop didn’t hear the “I’ll be installing the Arduino IDE” so forget to set me up as a local admin. So tomorrow...

 

Robin, ta, understood,

 

John, you’ve got a footnote on here saying “David” too. Did the mods set you up on another user called “PannierTank” by any chance? Or if you’re actually David, there’s a Pannier Tank called John on WT! It’s all quite confusing & curious!

 

Anyway, I was a MERG member for a couple of years, and found it quite interesting, however never really had time to indulge. I also found that there was plenty of “not at all challenging” and plenty of “oh, err, that’s a big project”, but not so much in the middle. The Arduinos are somehow more appealing.

 

Best

Simon

 

Hi,

 

Just for interest there appears to be a CBUS library for Arduino now.

I'm not sure if it along with an Arduino it is fast enough to deal with all the messages on the bus.

 

 

Regards

 

Nick

Link to post
Share on other sites

I am not using RS485 as it is not an in-built feature of Arduinos and the distances for my data have not yet required me to add the extra hardware.

 

 

So what will you do if/when it does become a requirement?

Surely you should select a hardware solution based on the requirements likely to be encountered.

Designing systems based merely on the apparent cheapness of Arduinos could quickly become a false economy in time and effort once real life practical considerations like this are included.

Link to post
Share on other sites

So what will you do if/when it does become a requirement?

We won't fall off that bridge until we get to it

 

Adapting the system to use RS485 would be straightforward

 

 

Surely you should select a hardware solution based on the requirements likely to be encountered.

I believe I have. But no plan survives contact with the enemy

 

...R

Link to post
Share on other sites

  • RMweb Premium

A comms line length of 2.5m will probably be OK with I2C. You can slow down the transmission rate to around 30kHz if necessary. We have bus extender chips on all our boards but we have some cables of 10 or more metres.

 

The Arduino implementation of I2C is not the finest of efforts but it works pretty well most of the time. If it didn't we would be in big trouble in a couple of weeks as we are taking our layout to Southampton exhibition. It relies on I2C for 90% of its operation!

 

Cheers

Dave

Link to post
Share on other sites

If I2C does not work you could look at wifi and the nodemcu ardrunios.   Cheaper than the nanos, I have tested them at 200m range with no problems.

Unless a person is already familiar with web programming the switch from I2C (or Serial communication) to WiFi will involve a very steep learning curve. The Nodemcu does provide a convenient package of wireless and microprocessor, but I don't think it has as many I/O pins as a Nano. There would also be a need for adding an ESP8266 to the Master Mega so it could communicate with the Nodemcus. For this sort of application the ESP-NOW capability would probably make more sense than using regular WiFi and web programming.

 

For my own wireless communication I use nRF24L01+ modules.

 

...R

Link to post
Share on other sites

  • RMweb Premium

If the i2c doesn't fly, I'll just revert to UART.

 

thanks all

Simon

 

UART's, that brings back a few memories for me. Back in the early 80's I used an 8250 UART as part of an RTTY (radio Teletype) Decoder using a Sharp MZ80A Computer!!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...