Multiple node mcu using spi

Hi everyone,
Trying to receive multiple sensor values from node mcus onto arduino uno using SPI protocol. Not able to find code for the same or figure it out. Can anyone help me with the code.

Thanks

Each node has a select pin that must be enabled by the bus master before a data transfer.

1 Like

For the Arduino, or for the Nodes? Or both?

Which part are you stuck on?

As far as the Arduino is concerned, this is no different to interfacing to any other SPI slave.

As @DrDiettrich said, each slave has a 'select' line

As far as the Nodes are concerned, you need to implement an SPI Slave on each one.

image

I wonder how you're doing that. What do you have, what have you tried?

(I'm probably a bad person, but I suspect you'd like the Uno as SPI MOSI to NodeMCU's as SPI MISOs "code".)

Hello everyone,
Thank you for the responses. My use case is as follows:
I have 8 node mcus each collecting sensor data. I want to collect it at a common node using serial commication and decided to use a arduino uno for the same.

Currently i am using a code where sensor data is stored on to a buffer on node mcu and is transferred to uno. This works only for a single node and slave.

I request you to please help me with a new code or reference code where the master can select the slave,collect the data and move to next slave.

So according to my understanding the node mcu code remains the same where as for arduino, the board has to select the nodemcu through slave select and then collect data. How do i achieve this?

Finding no reference to implenement master, which collects data from esch node mcu using select and deselect

It sounds like you need to read-up on the basics of how SPI works.

The same as what, exactly?

If that code acts as an SPI slave, and supports a slave-select line, then that is indeed what you need.

Yes.

This is standard SPI stuff:

  1. Select the required slave
  2. SPI.transfer()
  3. Deselect the slave

rinse & repeat.

Can you please share a reference code where the slave is selected, data is being collected and the slave is being deselected by the arduino

While SPI bus riders have to be selected to read or write to the bus,

it is not necessarily through the host. You can wire the all of the riders as selected by IIRC grounding their select pins.

And THEN what happens? They all read the host at the same time.

After that you need a data protocol of some kind to tell which rider gets the MISO line.
One way is to hard code an ID number in the rider codes and a table of IDs on the host.

The time to get it done will include learning/discovering between you now and you later so best to not play the deadline game.

Have you tried a search for something like, "Arduino SPI multiple slaves" ?
:thinking:

I want to restrict myself in this regard to just nodemcu and arduino and not involve other components

You don't need any other components.

Again, this is all standard SPI stuff - so any example will do!

if you dont mind..could you send me a reference code which i can directly use for reference.
Thanks

The link I gave you should be pretty much directly usable.

Code you say ... Hmmm ... Ok ... this is pretty much one of the best walk throughs of SPI on Arduino hardware that I can think of. It's easy to understand (in my opinion) and if you start from the top and read down as far as you need to, you should have an idea of what you need to do in your particular project.

Hi markd833,

Referring to this...but couldnt find a way to integrate mutiple slaves

But @awneil,
How do i handle the port expander part...when i am not using one

Have you used any of the example codes?

You have one board with 8 others on SPI.

From a link on the old Arduino Playground, a 2 part SPI tutorial.

Nick Gammon on SPI

What you want may be in the forum/archives, the forum does have a Search tool.
If you want to work it out with help; start with simple, make it solid and only then add more. Do NOT whip up a complete do it all sketch expecting to solve all problems at the same time unless you want to waste loads of time. Only introduce one new thing at a time and debug that before adding more. When you know the pieces it makes any go back and change parts easier to rebuild on top of.
Troubleshooting starts with reducing unkowns to one and crushing it like a bug.

1 Like

The only real difference between 1 slave and n slaves is the number of SS signals - one per slave.

If you have 3 slaves, then you have 3 SS pins. On an UNO, generally pin 10 is the first SS signal. Call that SS1.

Use pin 9 for SS2 and pin 8 for SS3 - for example.

To talk to slave #1, you simply set SS1 low, do your SPI transfer and then set SS1 high. To talk to slave #2, you set SS2 low, do your SPI transfer and then set SS2 high. Same for slave 3 etc.