Esp32 pinout programming? - SOLVED

Hello a friend of mine gave me 2 of these esp32 wlan mini they call them https://a.co/d/iYZC9VO. They are about the same size as the esp8266 d1 mini.

The problem is I’m trying to add a spi module and looking up the pin out there might be two spi channels. I can’t confirm it and was wondering from the community which pins are for spi?

Joseph

Yes there should be 2 SPI port available on an ESP32, have a look at this tutorial. It depends a bit on the board which pins are exposed, and i have issues with the default HSPI pins, connect devices to some of the pins causes the esp to crash. But fortunately you can more or less assign any pin to be used for SPI

The ESP32 has multiple SPI channels on board. One is used to read the code from the external memory chip, one is not normally pinned out, and VSPI is the default (Arduino compatible) SPI channel and HSPI is the other free channel. See the ESP32 SPI demo program SPI_Multiple_Buses.

Hello all, thanks for the reply. I’m using the wiznet w5500 module board. I just didn’t know which spi pins do I use? Sense I never used a esp32 before?

Hey thank you for the link and information. I’m looking at it now and I’ll try it out when I return home.

Get the data sheet, at least the pinout, for your board.

If you have a scope then you can write test programs and find out which alternate functionality goes to which pin by default. Or find out how to map the internal ports to any pin, using the ESP32 I/O MUX.

I do not have a scope. I can’t even afford one. Maybe one day.

I did look up the pinout. I’ll try them when I get back home. Thank you

i have a good example for W5500

#include <SPI.h>
#include <Ethernet.h>

#define LED_YELLOW 2
#define VSPI_SCK 18
#define VSPI_MISO 19
#define VSPI_MOSI 23
#define W5500_CS 5 
#define SPI_FRQ 32000000

byte mac[] = {  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,2);

//SPIClass * vspi = NULL;

void setup() {
  Serial.begin(115200);
  pinMode(LED_YELLOW, OUTPUT);
  digitalWrite(LED_YELLOW, LOW);  // active LOW
  //vspi = new SPIClass(VSPI);

  //vspi->begin(VSPI_SCK, VSPI_MISO, VSPI_MOSI, W5500_CS);
  //vspi->setFrequency(SPI_FRQ);
  SPI.setFrequency(SPI_FRQ);
  
  Serial.println("Starting ethernet");
  Ethernet.init(W5500_CS);  // set the CS pin
  Ethernet.begin(mac,ip);
  delay(1000);
  Serial.println(Ethernet.localIP());
}

void loop() {
}

using the standard ethernet.h library.

I also have a webserver example but that requires 'Ethernet_Generic.h' and a modification of the ESP32 core's Sever.h

Thank you very much. I will try it when I get home from the doctors.

Edit: I’m guessing I would need to use the VSPI pinout for the Ethernet module from your code it looks like.

that is the default for a w5500, some libraries allow for the alternate HSPI, but i had difficulty finding a way to use the custom pins for it. The commented out section shows how you could use different pins, by creating a pointer to the SPI object, but i can not pass the pointer to the Ethernet object on initialization (like i can with the SD library) The default pins on VSPI are available and have no other default functions so there is actually no reason not to use them.

I finally got my ethernet modules in. https://europe1.discourse-cdn.com/arduino/original/4X/e/8/c/e8c898ef69e2aed7884bdd40f4089ea3558a74f1.jpeg

Now I'm trying to match up the pinout before I can program it on the esp32 board. one pin that I'm confused on it a nINT pin bottom left of that image. Also The n RESET pin. Does that reset pin goes to the reset of the esp32 board?

Edit: your pinout has:
#define VSPI_SCK 18
#define VSPI_MISO 19
#define VSPI_MOSI 23
#define W5500_CS 5

Are they gpio pins 18,19,23 and 5 same as on the Esp32 board https://m.media-amazon.com/images/I/71NCINnyq9L.AC_SL1500.jpg?

Yes looks like.

It is a pin that sends a (LOW ?) pulse in case of an event, i don't think there is any support for it in the library i am using.

I had it like that initially, but it caused some issues in case of a 'soft'- reset. In the end i connected it to a GPIO (output) pin and did a short reset pulse before init()

pinMode(W5500_RST_PORT, OUTPUT);
  digitalWrite(W5500_RST_PORT, LOW);
  delayMicroseconds(500);
  digitalWrite(W5500_RST_PORT, HIGH);
  delay(2);

I found some timing details in this Main thing for me was that i had to actually press reset when i just had it connected to RST on the esp32, although that was in some way good enough, i haven't had to reach for the board since i've added the reset routine.

In your code you have a yellow Led pin. Is that for the reset pin or just an Led pins?

I have a led connected to GPIO 2 (Active LOW !! VCC->LED->1K->GPIO2. If GPIO 2 is pulled LOW the ESP32 will enter the wrong boot mode, this pulls it up.) On some boards (i just got a 30-pin in) there is a builtin led on that pin.
I used GPIO 21 for reset, but any available output pin would work. There is no pullup on nRST on my module, but the pin should not be floating (ESP32 RST is pulled up) I just sacrificed a GPIO pin.

I didn't connect the reset pin and let it float. I used your sketch. Once uploaded I open serial monitor and saw.

ets Jul 29 2019 12:21:46

rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0030,len:1184
load:0x40078000,len:13260
load:0x40080400,len:3028
entry 0x400805e4
Starting ethernet
192.168.1.177

When I hit the reset button.

There is an example i have using Ethernet_Generic Library and EthernetWebserver.h (install both) and you need to modify Server.h as it explains on the github page of the webserver lib.


//#define W5500_RST_PORT   21
//#define ETHERNET_LARGE_BUFFERS
#define W5500_CS 5 
#define SPI_FRQ 32000000 

#include <WiFi.h>
#include <WebServer.h>

#include <SPI.h>
#include <EthernetWebServer.h>
#include "Ethernet_Generic.h"
// #include <EthernetUdp.h> // not needed yet

const char* ssid     = "xxx";
const char* password = "xxxxxxxx";

EthernetWebServer ethernetServer(80);
WebServer wifiServer(80);

const int led = 2;

void handleEthernetRoot() {
  ethernetServer.send(200, "text/plain", "Hello from ESP32 Ethernet!");
}

void handleWiFiRoot() {
  wifiServer.send(200, "text/plain", "Hello from ESP32 WiFi!");
}

void setup() {
  Serial.begin(115200);
  delay(100);
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  SPI.setFrequency(SPI_FRQ);

  Ethernet.init (W5500_CS);
  // start the ethernet connection and the server:
  // Use DHCP dynamic IP
  byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01}; 
  //uint16_t index = millis() % NUMBER_OF_MAC;
  // Use Static IP
  //IPAddress ip(192, 168, 2, 222);
  //Ethernet.begin(mac, ip);
  Ethernet.begin(mac);

  Serial.println("Currently Used SPI pinout:");
  Serial.print("MOSI:");
  Serial.println(MOSI);
  Serial.print("MISO:");
  Serial.println(MISO);
  Serial.print("SCK:");
  Serial.println(SCK);
  Serial.print("CS/SS:");
  Serial.println(W5500_CS);

  ethernetServer.on("/", handleEthernetRoot);
  ethernetServer.begin();

  Serial.print("HTTP EthernetWebServer is @ IP : ");
  Serial.println(Ethernet.localIP());

  wifiServer.on("/", handleWiFiRoot);
  wifiServer.begin();

  Serial.print("HTTP WiFiWebServer is @ IP : ");
  Serial.println(WiFi.localIP());
}

void loop() {
  ethernetServer.handleClient();
  wifiServer.handleClient();
}

This is my simplified version.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.