Hi @markd833 , data sending is trigger based so i am expecting a max of 4 5 times in an hour. They will be located next to each other on a rack
Well, you could use a serial port on each device with a very simple protocol.
The various nodes are connected so that:
UNO (Master) Tx -> NodeMCU #1 Rx
NodeMCU #1 Tx -> NodeMCU #2 Rx
NodeMCU #2 Tx -> NodeMCU #3 Rx
NodeMCU #3 Tx -> NodeMCU #4 Rx
NodeMCU #4 Tx -> UNO Rx
The UNO sends out a simple query packet such as [2] (left square bracket is the start marker, 2 is the data /address and right square bracket is the end marker).
NodeMCU #1 receives this packet and knows it is not addressed to it, so simply retransmits the packet.
NodeMCU #2 receives the packet and knows it is addressed to it, so responds with its readings. The data packet might be: [0,reading1,reading2,reading3].
NodeMCU #3 receives this packet and knows it is not addressed to it, so simply retransmits it.
The packet gets passed along until it eventually arrives back at the UNO.
The Serial Input Basics tutorial will get you the basics of packet reception - see example #3.
Hi @markd833 do the node mcus already have adresses that we can reference?
Simple answer is no. You give them simple addresses like 1, 2, 3 etc in your code.
The more complex answer is that they do have addresses relating to their wireless capability but those are over the top for your needs in this project.
So @markd833 what is your opinion about spi in my case. Is it really usable
@markd833 thanks for giving me an idea about this serial communication. Will let you know how it goes tmrw😊
Sure you can use SPI. As previously mentioned by several other contributors to this discussion, your UNO selects which NodeMCU it wants to talk to using 1 digital output per NodeMCU. If you have 8 NodeMCUs, then you have 8 digital outputs on the UNO. Each output is an "Oi you, listen up, i'm about to say something" signal to a specific NodeMCU.
I've no experience of SPI on the NodeMCU so can't comment on the library functions available for handling the device in slave mode.
However, SPI is intended to be a high speed interface - which for your project seems overkill.
Using SPI hinges on creating an ESP-as-SoftSPI-slave library.
(Good Luck.)
The logical thing to do is to use one processor, and port expanders.
Leo..
@markd833 this link says that it is not possible to use node mcu as a slave. Is it possible as of now?
Hi @runaway_pancake,
Could you please elaborate on the same .
Thanks
As I said back in post #67:
It's not hard to implement in software - for low speeds.
But there's no reason it can't be used at low speeds - loads of sensors have SPI even where high speed is not required.
Only one pair of pullups per bus - and you would only need one bus.
Addresses are far more scalable than having to dedicate a physical wire per device, IMO!
Please give an example how to implement an SPI slave on an Uno. Somewhat easy for a single byte transfer, almost impossible for multiple bytes in one go without at least double buffering.
and have special hardware for just that communication.
No, not really.
To my pointt - to get to this "NodeMCU as SPI slave" goal you, or someone else, will have to build, basically, a "NodeMCU as SPI slave" library or a bit-bang equivalent (performance unknown).
That's no mean feat.
Thank you for the reply @runaway_pancake. Is UART a good alternative to SPI in this use case?
@DrDiettrich Is UART a good alternative to SPI in this use case?
Asynchronous Serial via the UART ("9600 8N1") - probably not.
At least, not without -- Additional Hardware.