Arduino SPI problems

Hello I have a problem....

I have been searching the internet for a long time how I can connect a "NodeMCU Esp8266" with an "Aurduino UNO" via "SPI". I can't find a tutorial that explains how to do this... There is one that explains it, but the problem is that there are several web pages that say that the "MOSI" and "MISO" cables must have resistances, but according to me the pins of the "Arduino UNO" emit 3.3V and not 5V.

In short, I need the code for the "Arduino UNO" and "Esp8266" to make a "SPI" communication to send a Hello World before doing something else and how to connect them physically (the "Arduino UNO" must be the Slave).

Thank you! :slight_smile:

there are several web pages that say that the "MOSI" and "MISO" cables must have resistances

Can we get links to those pages? I don't know of any required resistance for SPI lines, maybe you are confusing SPI with I2C? Level shifters will be needed to interface between devices with different supply voltages.

the pins of the "Arduino UNO" emit 3.3V and not 5V.

The Uno is a 5V board. The pins output 5V. There is a regulator that outputs 3.3V but the max current from that regulator is not capable of, reliably, powering an ESP8266 by itself. Adding a 100uF across the 3.3V supply cap can solve that problem.

Here is a link.
https://www.esp8266.com/viewtopic.php?p=62196

The Esp8266 can only be powered by 3.3V, and I think the pins of the Arduino Uno only output 5V.

Pleace, I need Help

Please! I need Help!

Well you can help yourself.

Its already beem mentioned in post #1 that you need level shifters (sometimes also called logic level converters) to interface the 5V and 3.3V devices.

So try some Google searches on the topic, there is going to be heaps of stuff about it on the Internet, its a very common problem.

Really? That I answer myself? I said that the voltage was one of the problems that affected communication, but I also need the code, I tried several and none of them send me text, I don't know if it is because of the library or the connections ...

That is why I need the code and the connections (and also the library), because I think what I have is very wrong.

did you try the example from here:

or here

did any of those work?

The purpose of this tutorial is to send the string "Hello World" from NodeMCU to UNO using SPI Port.

1. Practically, the pins of NodeMCU are 5V tolerant; so, build the following circuit (Fig-1) between NodeMCU and UNO using SPI Port.
SPINodeUno.png
Figure-1:

2. Upload the following sketch in NodeMCU (tested):

#include <SPI.h>
char myData[] = "Hello World";
int i = 0;
void setup()
{
  Serial.begin(115200);
  SPI.begin ();
}

void loop()
{
  do
  {
    char x = myData[i];
    byte x1 = SPI.transfer(x);
    Serial.print(x);
    delayMicroseconds(10);
    i++;
  }
  while (myData[i - 1] != '\0');
  i = 0;
  Serial.println();
  SPI.transfer(0x0A);
  delay(1000);
}

3. Upload the following sketch in UNO (tested):

#include <SPI.h>
volatile bool flag = false;
char x;

void setup ()
{
  Serial.begin(115200);
  pinMode(SS, INPUT_PULLUP);  // ensure SS stays high for now
  pinMode(MISO, OUTPUT);
  SPCR |= _BV(SPE);
  SPCR |= !(_BV(MSTR)); //Arduino is Slave
  SPCR |= _BV(SPIE); //SPI.attachInterrupt();
  sei();
  SPDR = 0x67;  //test value
  delay(100);
}

void loop()
{
  if (flag == true)
  {
    Serial.print(x);
    flag = false;
    //Serial.println();
  }
}

ISR(SPI_STC_vect)
{
  x = SPDR;
  flag = true;
}

4. Serial Moniotr of NodeMCU (Fig-2)
SMnode.png
Figure-2:

5. Serial Monitor of UNO (Fig-3)


Figure-3:

SMnode.png

SPINodeUno.png

GolamMostafa:
1. Practically, the pins of NodeMCU are 5V tolerant;

When you use a device contrary to (and outside of) its published specifications, you become an Unpaid Test Pilot.

gfvalvo:
When you use a device contrary to (and outside of) its published specifications, you become an Unpaid Test Pilot.

There are quotes in the net from the anonymous users that the NodeMCU's pins are 5V tolerant.

GolamMostafa:
There are quotes in the net from the anonymous users that the NodeMCU's pins are 5V tolerant.

Well, if an anonymous source on the internet said it, then it must be true. Any competent engineer would follow that reference instead of the device's datasheet.

gfvalvo:
Well, if an anonymous source on the internet said it, then it must be true. Any competent engineer would follow that reference instead of the device's datasheet.

I agree with you that the field design/implementation must comply with device data sheets. But, NodeMCU is going with UNO without level sifters (Fig-1). As a demonstration purpose, we may operate them directly for a short period of time (say 2 minutes).:slight_smile:
nodeUNODirect.png
Figure-1:

nodeUNODirect.png

GolamMostafa THANKS!!!! It works!!! Now I can do my proyect....
Saludos desde Mexico y gracias!

খুশীর খবর যে এটা তোমার জন্য কাজ করে এবং তোমার কাজে লাগবে। আরও সাহায্যের দরকার হলে নির্দ্বিদায় বলবে।

Good news that it works for you, and it would be useful for you. Ask for further help without hesitation.

Ok, thanks