ESP8266 and Arduino connected by SPI interface


#1

Hi,
I have just uploaded two projects to github that in my oppinion solve the problem with using ESP8266 modules as slaves to Arduino MCUs.
Instead of the serial interface the SPI interface is used here. Therefore the ESP module must be reflashed to a custom firmware.

The WiFiSpiESP project is in fact an application and must be flashed to ESP module while the WiFiSpi project is an Arduino library. I tried to keep the library objects and functions as close as possible in its behaviour to the default Arduino’s WiFi library in order to make migration to the WiFiSpi library easy.

I know that flashing ESP module may not be a solution for beginners, but I am afraid there is no chance to make a robust solution on AT command protocol and SoftwareSerial class.

The projects are:



#2

Hi @JiriBilek
This is great! Only today I saw this.
I will try it, I hope in the next days.
If I understand well I need to flash SPI Slave for ESP8266 module and use the SPI library for Arduino AVR to connect with ESP8266, it seems easy :slight_smile:
I will give a feedback for sure.
Thanks!


#3

Hi @Andrei_Sousa,
exactly. Just be careful and do not connect 5V to ESP module. A simple solution is to power the Arduino with 3.3V :slight_smile: .


#4

Hi @JiriBilek!
Thanks for remeber these important details.
I hope have time to do this in the next days.


#5

Hi @JiriBilek!
Everything works great and easly.
At this moment I only want to make a simple example to test thinger.io.
I´m using the last lybrary from here https://github.com/thinger-io/Arduino-Library

#include <WiFiSpi.h>
#include <ThingerWifi.h>


#define username "****"
#define deviceId "****"
#define deviceCredential "****"

#define ssid "****"
#define pass "****"
//int status = WL_IDLE_STATUS; //I´m not sure if I need this here

ThingerWifi thing("username", "deviceId", "deviceCredential"); // I get an error here

WiFiSpiClient client;

void setup() {
  
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Initialize the WifiSpi library
  WiFiSpi.init();

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  String fv = WiFiSpi.firmwareVersion();
  if (fv != "0.1.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFiSpi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  // configure wifi network
  thing.add_wifi(ssid, pass);

  pinMode(5, OUTPUT);

  // pin control example (i.e. turning on/off a light, a relay, etc)
  thing["led"] << digitalPin(5);

  // resource output example (i.e. reading a sensor value, a variable, etc)
  thing["millis"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop() {
  thing.handle();
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFiSpi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFiSpi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFiSpi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

I need to change in “ThingerWifi.h” where is “WiFi” to “WiFiSpi”?
The error is:
C:\Users\admin\Documents\Arduino\libraries\Arduino-Library-master\src/ThingerWifi.h:46:17: error: 'WiFi' was not declared in this scope

I need your help to make the first example.
Thanks!
AS


#6

Exactly, you have to change WiFi to WiFiSpi because each belongs to a different library.


#7

Hi @JiriBilek!
I was doing several errors in the example I sent before.
First I need include the file ThingerESP8266AT.h and now I have a difrent error:
ThingerESP8266AT.h:64:5: error: 'TinyGsm' does not name a type

What I should I do?
Thanks!
AS


#8

Hi @Andrei_Sousa,
you have to change Thinger header as well, sorry, I forgot to mention it.
J.

ThingerWifiEspSpi.h (2.8 KB)


#9

Hi @JiriBilek

Now I can do the upload to the Arduino with no errors.
But for some reason the STATE of the device is always Disconnected, I don´t understand what I´m doing wrong.

The issue is in the code I upload?

The code I upload now is:

#include <WiFiSpi.h>

#include <ThingerWifiEspSpi.h>


#define username "***"
#define deviceId "***"
#define deviceCredential "***"

#define ssid "***"
#define pass "***"
int status = WL_IDLE_STATUS;

ThingerWifiEspSpi thing("username", "deviceId", "deviceCredential");

WiFiSpiClient client;

void setup() {
  
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Initialize the WifiSpi library
  WiFiSpi.init();

  // check for the presence of the shield
  if (WiFiSpi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  String fv = WiFiSpi.firmwareVersion();
  if (fv != "0.1.0") {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFiSpi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  // configure wifi network
  thing.add_wifi(ssid, pass);

  pinMode(5, OUTPUT);

  // pin control example (i.e. turning on/off a light, a relay, etc)
  thing["led"] << digitalPin(5);

  // resource output example (i.e. reading a sensor value, a variable, etc)
  thing["millis"] >> outputValue(millis());

  // more details at http://docs.thinger.io/arduino/
}

void loop() {
  thing.handle();
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFiSpi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFiSpi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFiSpi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

Any sugestion?

Thanks a lot!
AS


#10

Andrei,
try to simplify the setup function:

void setup() {
  
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // Initialize the WifiSpi library
  WiFiSpi.init();

  // check for the presence of the shield
  if (WiFiSpi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  String fv = WiFiSpi.firmwareVersion();
  if (fv != "0.1.0") {
    Serial.println("Please upgrade the firmware");
  }

  // configure wifi network
  thing.add_wifi(ssid, pass);

  ... etc. etc. ...

Don’t connect the wifi manually, let thinger do the work. If it doesn’t help, connect serial monitor to ESP and look at the output. The serial output from Arduino may help, too.

Jiri


#11

i used your library

but when i build in my IDE. had some prroblem

C:\Program Files (x86)\Arduino\libraries\wifi3/ESP8266WiFiGeneric.h:27:22: fatal error: functional: No such file or directory

#include functional

i can not include functianal

can you help me?


#12

Hi,
what library are to refering to? The one for Arduino or are you trying to compile the part for ESP8266?
I tried to find the ESP8266WiFiGeneric.h file on my computer and I didn’t find it. So could it be you have more wifi libraries installed and the error comes from another library?