help needed with I2C

the old fart

Senior Member
Hi Guys,

I've been asked to look into a project to control a minature steam railway signalling.

I thought of using a number of 40x2 and 20x2 chips.

Interfacing between the chips using the I2C bus.

I've downloaded the tutorial and read it more than once.

Is it feasable to think along these lines, or should I go down a different route.

I have previously built a digital thermostat using I2C bus, but not connect picaxe chips.

Any pointers, sample code, greatfully accepted.

regards

TOF
 

edmunds

Senior Member
I2C is quite easy between picaxe chips if you have done it before with other devices. I have used it on several projects successfully. One problem I had to solve and which took me quite some time to figure out was a system for a master to know which slave is which, so I would not have to remember to program the right slave address into the right chip. I used an extra line that worked as a chip ID during the system initialisation and as an interrupt line for the slave to let the master know it has new data. This requires as many such lines as you have slave devices which might or might not be a problem with 40X2 in your project. However, it is always quite easy to add an I2C I/O expander while you are at it.


Good luck,

Edmunds
 

mikeyBoo

Senior Member
hi old fart (I'm an old fart too),
If you're just needing a bunch of discrete input/output points. Just use a single 20M2 & as
many MCP23017 I2C io chips as needed. You can have up to 8 MCP23017s on the bus for a total of
(16 x 8) 128 io points. The boards must be within a few feet of each other unless you use I2C extenders.
You could use the 20M2 like a PLC to control your logic:
01 Scan the input points -> image registers
02 Evaluate ladder logic
03 Update outputs (then back to step 01)
If this makes sense for your project,
Look at my Kayak Control Project software "Picaxe Kayak Control System.bas" for example.
Search for word joystick.
Good luck with your project.

If you could list how many & what kind of io you will be using, that would help.
 

Attachments

AllyCat

Senior Member
Hi,

How large is the "miniature steam" railway?

The I2C (IIC = Inter-IC) bus is very much intended for short-distance communications, often on a single circuit board or at least within a single enclosure.

It can be extended to some extent (maybe a few metres) , but what type of data are you trying to transfer that would make I2C an "appropriate" medium in preference to "RS232" (in some form or another) ?

Cheers, Alan.
 

inglewoodpete

Senior Member
If 'longish' distances are involved, don't discount RS485.

Only 2 wires between devices is another bonus.

Neil.
And RS485 is a balanced media, so ground currents are not a problem, allowing quite long busses. On the negative side, you must write your own code for identifying slaves and also reject data for other slaves if there are more than one. This can be quite tricky.

There are good and bad points for both transmission/protocol types.

i2c is very simple: addressing and rejecting data for other slaves is written into the firmware. Native i2c is good for about 1.2 metres but there are i2c bus extender chips that allow 12m metre busses typically. I have used this method quite successfully.

Contrary to comments above, an interrupt wire is not required if each slave can identify itself at bootup (pull down resistors used with the internal pullup on some pins is just one way to do this). The master should poll each slave in turn if status information is required.
 

hippy

Technical Support
Staff member
For PICAXE networking I would preferentially choose some sort of UART serial. If for no other reason than it being so much easier to debug if things are not working as expected.
 

the old fart

Senior Member
Hi Guys,

Thanks to everyone for the feedback.

I've programmed PLC's for many years, so I understand the 'ladder' programming method.

I've been told that the basic oval track is 600ft long, with about 6 turnouts.

I like the look of the MCP23017 chips. cheaper than using 20X2 as slave I/O. couple o/p with uln2803. with opto isolators on I/P.

Can't use track circuit detection, as its all welded together. I/R beams have been mentioned.I use them around my fishpond to deter herons and cats.

I envisage a central, clean, cabinet with display and buttons.

Don't know if going to hardwire to remote signals, or try radio, think might stick to hardwire.

This is going to take some time to install, as it's winter here, but I'll make a test pcb and have a play!!

Keep suggestions coming, all appreciated.

Dave (TOF)
 

hippy

Technical Support
Staff member
I've been told that the basic oval track is 600ft long, with about 6 turnouts
I would expect I2C over hundreds of feet to be very problematic, especially with dumb I/O expanders and no means of error checking.

Just a one bit glitch may incorrectly set or clear a signal, set the points to the wrong routing, have signals out of kilter with points.

I think you need to give us more detail on the system, its operation, and what is controlled, by who and how, to be able to judge whether safety critical or mission critical.
 

the old fart

Senior Member
I would expect I2C over hundreds of feet to be very problematic, especially with dumb I/O expanders and no means of error checking.

Just a one bit glitch may incorrectly set or clear a signal, set the points to the wrong routing, have signals out of kilter with points.

I think you need to give us more detail on the system, its operation, and what is controlled, by who and how, to be able to judge whether safety critical or mission critical.
The I2c would be confined to within the control cabinet.

External connections could either be hardwired, rs485, or something else.

The railway has been operating for many years without major problems, It's all slow speed movements.

Having driven diesel engines on, what was, British rail main line I can scale down the experience for this project.
 

mikeyBoo

Senior Member
Hundreds of feet & digital input/output. Sounds like an application for a small PLC with 24vdc isolated io. (Of course, in the US if open to the public, would require a visit to city/county codes office)

Since you're comfortable with PLCs, might wanna' take a look here:
http://www.automationdirect.com/adc/Overview/Catalog/Programmable_Controllers
Before I retired, we used to buy a lot of used PLC stuff off ebay very cheap.

If you decide to do the project with a Picaxe, take a look at the examples in attached pdf. Might give you some ideas.
Haven't needed any isolated io, but use extra lines on I2C to make sure bus can be hard reset & outputs shut down by program.
Boards are daisy-chained on an IDC10 ribbon cable.

Have fun & Merry Christmas to All !!
 

Attachments

the old fart

Senior Member
Want a laugh, two months ago I had a major chuck out.
Included siemens 103 with multiple 32 i/o moduals, program cable and pc program.
sob sob.
 

mikeyBoo

Senior Member
Want a laugh, two months ago I had a major chuck out.
Included siemens 103 with multiple 32 i/o moduals, program cable and pc program.
sob sob.
Oh no! Sounds like something I would do!
With all that distance & metal, isolated io would probably be prudent. Of course, you still might be able to get a cheap PLC, but probably looking at $100...$200 minimum.
You could still do it with Picaxe, but if you had to design & build isolated io boards, would eat up a lot of man-hours. Too bad I never designed any yet for the KYK stuff (most of my projects are on boats & small areas). If it was me (being lazy as I am), would probably just spring for a cheapo PLC. Would make your project a lot faster since you do ladder logic & save arguments if you have to deal with a codes guy (wasn't sure Norfolk was in USA or England).
Anyhow, good luck with your project & have fun!
 
Top