I working on a project, I was faced with a challenge of creating a serial bus via multiple Arduino which could communicate with each other. My first intuition, after a little push in the right direction by Tom Igoe, was to create a Master/Slave setup where a Master micro-controller polls all the slave micro-controllers, and dispatches an action. Although this answered one of my question, polling didn’t allow for complete 2-way communication. It tuned out that the answer was mainly an oversight of my interpretation of the Wire documentation.
From Arduino Site:
Wire.begin()
Wire.begin(address)
====
Description
Initiate the Wire library and join the I2C bus as a master or slave.
====
Parameters
address: the 7-bit slave address (optional); if not specified, join the bus as a master.
====
Returns
none
I interpreted this explanation as Wire.begin(SomeAddress) would default as a slave, and not be allowed to be a Master. Being as curious, and stubborn as I typically am, i decided to forget what I thought I was being told, and instead try to break the library, so I could then see where it broke, and attempt to adjust it in a way that better suited my need. Surprise, surprise, it worked, and not need to change anything at all! The address parameter is optional and defaults as a master role if no address is set. However if you do plan on sending messages to the master, you could switch speaker and listener roles via a slaves Wire.onReceive(handler) rather then polling using onRequest(handler). Read more
Popularity: 9% [?]







Social Links