Communicating between pics

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
poohbear
Posts: 26
Joined: Sat Apr 01, 2017 6:32 pm
Has thanked: 1 time
Been thanked: 8 times

Communicating between pics

Post by poohbear »

Hi
I am hoping someone can help me. My colleague is a model train enthusiast and he is wanting to put lots of sensors on his train layout( switching points as well as position of train) there will be around 192 sensors in all, each sensor will be either on or off, he then wants this information to be sent to a led display board ( individual LED's). this could do this by just connecting each sensor to an LED but the amount of wiring is enormous and any future faults would be hard to find. I was wondering if it would be possible to use multiple pic's along with the I2C or similar ( to reduce wiring)

If anyone has any ideas I would be grateful also examples as I have not had much experience of communication between pic's

Regards

Gary

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Communicating between pics

Post by Benj »

Hi Gary,

I2C is certainly an option as is a serial UART maybe with RS485 to help reduce noise and allow multiple slaves to sit on the bus.

Here is a project where I use TTL UART Serial daisy chained together.
https://www.instructables.com/RGB-LED-P ... ing-Table/

RS485 makes things a bit easier but you have the added expense of the driver IC.

This might help with an overview to I2C.
https://www.matrixtsl.com/blog/simplifi ... c-and-spi/

Here we have an I2C slave example, note it might not work on all devices.
https://www.matrixtsl.com/blog/i2c-slave-coming-soon/

poohbear
Posts: 26
Joined: Sat Apr 01, 2017 6:32 pm
Has thanked: 1 time
Been thanked: 8 times

Re: Communicating between pics

Post by poohbear »

Hi Ben
Thanks for the reply much appreciated

Gary

User avatar
Steve
Matrix Staff
Posts: 3429
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times

Re: Communicating between pics

Post by Steve »

With so many on/off sensors, I'd suggest having multiple "slave" chips each directly connected to 8 or 16 sensors. Then connect these slaves to a single "master" chip via a serial bus. Only 2 programs need to be developed - 1 for the master and 1 for the slaves - with all slaves running the same code (but having a different address on the bus). The master would request data from each slave in turn.

If this data is being transmitted to individual LEDs, you could use the same master chip to send the info to another set of slaves which each connect directly to 8 or 16 LEDs. You'd need to create another program for these slaves (again, with different addresses).

I2C is a good option as most chips have the appropriate hardware and it's easy to bitbang if not, and it also scales well. However, the length of the bus cabling could be a limiting factor (I2C is designed for chips communicating within the same PCB), but can be enhanced using a driver.

1-wire is another option. It's slower, but allows for longer cables.

As Ben suggests, RS485 is another option. I'd also consider CAN. Both require external driver chips, but cable length won't be a concern. RS485 is cheaper, but I think you'd need to create your own addressing system. Like I2C and 1-wire, CAN incorporates addressing in its protocol.

Sounds like an interesting project. Hopefully others on this forum have experience or ideas to share...

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: Communicating between pics

Post by LeighM »

Similar to Ben and Steve, a two wire RS485 or single wire-or'd (open collector driver) if data rates are slow.
As a very simple protocol ..
If you connect to an 8 bit UART you have 256 codes or addresses for the slaves
If you reserve 2 codes for on/off you could then use the master to poll each slave address in turn and expect an on or off reply.
A no reply timeout would indicate a disconnected slave.

Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times

Re: Communicating between pics

Post by Steve001 »

Hi Gary

Have a look at Mega points controller's website they have all sorts of devices to do what you wanting to do.
They have lots of documentation i think they communicate via i2C or can bus from memory when i had a nosey at an exhibition :lol:

https://megapointscontrollers.co.uk/?v=79cba1185463

Hope this gives you some idea's

Steve
Success always occurs in private and failure in full view.

poohbear
Posts: 26
Joined: Sat Apr 01, 2017 6:32 pm
Has thanked: 1 time
Been thanked: 8 times

Re: Communicating between pics

Post by poohbear »

Hi
Thanks to everybody for the replies it is really appreciated.
I have written a transmit and a receive program which works in a way but it doesn't appear to receive in the order that it is being transmitted. Can someone take a look at the programs and give me some ideas.

Thanks

Gary
Attachments
I2C slave test2.fcfx
(15.3 KiB) Downloaded 208 times
I2C Master test2.fcfx
(15.68 KiB) Downloaded 198 times

Post Reply