I was struggling to get my new ESP32-C3 board to work with a sensor on the SPI bus for the last few days. I was able to resolve the problem using the SPI.begin(SCK, MISO, MOSI, SS) command to re-assign the MISO pin from the default GPIO9 to another pin on the board. That solved the problem and hours and hours of trial and error!! Thanks a ton!!
Should have seen this video first when I started playing with esp32. Different board different peripheral and library, it's a jungle specially the first time. You think you did something wrong, when it's just the library or something else, or reading documentation for different board.. Great video even in 2022 !!!!
Thanks, David. You are the one I turn to these days. I made notes on this! Going to pass them to a friend who has trouble with these pins. Your ePaper WX app is running just fine here, still. Just found out that the ePaper display can do a pretty good grey scale. Never realized it before. Going to update it with those greyscale moon pix with I find them again. Good job!
Good to hear, the speed difference over a software implementation is significant. If you use any other pins than the designated hardware ones then Arduino emulates SPI in software, this is why it makes such a difference.
You are Right SPI is it time consuming a lot. after I connect one TFT 9486 parallel to the ESP32 I want to use the SD-Card reader on that board connected via 5,18,19,23 with a picture demo sketch. Serial.print(SCL) tells me Pin 22 is use instead of 18. If I can change it with SPI.begin(18,19,23,5) your video is helpful. SCL=18 have no effect in the Arduino IDE. I will choose the names MOSI,MISO,SCL and SS in the Sketch because of the predefines in the most libraries.
If you define the pins away from the compiler default the Arduino IDE implements a software emulation of the SPI bus. You can find what’s are used by the compiler by either printing out the key names or by inspecting the hardware folder for the board the file starts win ‘pins’ a parallel SD card drive should work ok, just make sure both the display and SD card reader have separate and unused pins for their Chip Select (CS)
@@G6EJD , thanks for your answer. I have found the issue, in this demo ( read a picture from SD-Card and Transfer to the TFT ) sketch the author forget the SPI.begin() complete. After insert the begin statement I can read the SD with Pins 18,19,23,5. I think this SPI is not emulated because of the very fast speed. I will compare The same pictures loading from SPIFFS and see how times faster this is.
@2:25 SDO is Serial Data Out; SCL is Serial Clock and SDI is Serial Data In. This is irrespective of whether you are using your device as a controller or as a peripheral. You could just hook up your controller's SDO to peripheral's SDI and vice-versa.
@@benjaminshields9421 well it’s semantics as the SPI bus has the concept of Master and Slave devices and that is a one-to-many relationship, so there can be many Slaves. When someone is learning it seems best to me to use the term Slave so as not to confuse them with another term.
Is "SS" (chip select) needed if only ONE device is running on the SPI bus? Can't it be hardwired to VCC or GND to be always selected? (trying to save pins)
You can but it’s not easy to implement. The SPI bus is comprised of a Master and Slaves, the libraries are configured to be the Master so for the other device you’d need to set that up as a Slave, there is provision in the SPI library from Espressif to set up an ESP32 as either master or slave.
You can have a duplex communication MOSI and MISO are for that, but Von Neumann architectures can only achieve full duplex by switching between processes. Many SPI devices send and receive data. Your challenge is to get the other processor to operate in Slave mode like a sensor would. Not sure why you can’t use I2S or serial as the performance would be close.
An ESP32 DevKitC board works well with an ST7735 TFT screen and the TFT_eSPI library and the board also works well with the VS1053 board and esp_wifi library. However, running SPI and Wifi together results in a problem with SPI as the ST7735 screen whites-out. Any suggestions would be very welcome.
There is nothing especially different with the Devkit C variant so I would try using Adafruit's ST7735 library and dropping the TFTeSPI library and is almost certainly what is causing the conflict. Using the in-built (assuming your IDE is current 1.8.10 and 2.4.2 and 1.0) libraries should result in no issues.
There is no difference between SPI and HSPI both run at the same speed, I think what’s caused this confusion is Espressif’s use of the H and V port designators. Both ports are identical and the SPI specification is what it is, there is no specification for a High speed version.
@@G6EJD How is possible to use HSPI for the SdFat library and the VSPI for an ADC (MCP3208) at the same time? I can work with both of them independently, but I can't merge them. Cheers!
You can’t merge them and I assume you have two I dependent circuits for each SPI bus which includes a CS for each device. Are you sure you are creating two instances of the SPI I stance spi1.begin and spi2.begin and using the correct identifier when reading each bus? I have not seen any libraries that allow more than one instance to be created!
@@G6EJD Yes, I have two independent SPI connections and two CS pins. I tried to follow different topics about two instances, but it doesn't work. Is there some clear example somewhere? I'll give a try with SD.h, but is slower than SdFat.h
Great David, thanks great explanation! There are also some SPI components like cameras that have additional SDA / SDL pins too, do you know if they also have a constant defined ?
Martin, no only the pins for the standard I2C bus will be defined, unless a specific camera device is listed in the boards section, but I know of none. It seems like just a need to connect the I2C bus to the camera as well as the SPI connections.
Thanks! Here in this sketch : github.com/martinberlin/FS2/tree/board/esp32 Serial.println(SDA); // Works! But SCL has no constant I added the pins like David described. For the Arducam (2MP or 5MP) the SCL is 22 and SDA is 21. If you have any Arducam around try it out. Supported models are: OV2640 / OV5642
Interesting video thanks! The PIN 5 on the Lolin board also lights the on board led, so every time SS goes low the led will light. Might be an interesting effect and useful in debugging, but I cant see any way to disable the led on the board apart from physically disconnecting it. Have you found away around this or will you simply use another PIN?
Check out the file in your IDE location, mine is at ArduinoIDE\hardware\espresssif\esp32\variants\lolin32 in there is a file called pins, which you can change so that Slave Select is on another pin, it’s a small design error/bad choice of Wemos to have used pin-5 for the LED unless you like the light show when the SPI devices are being used!
Thank you so much! I could not find this pin info before when looking thru various files created during compiling. So easy to change when you know how. The Wemos Lolin32 is a great little board but its good to know I can change pin 5 so easily. Keep the videos coming I'm learning so much from watching them!
Hello, the video was good. Is it possible to communicate with esp32, ads1256(SPI), LIS3MDL(I2C) and 20x4 lcd(İ2C) together? What kind of connection should I make?
Yes, the ESP32 has an SPI and I2C bus. The I2C devices have separate device addresses so are all wired in parallel and the SPI bus except for Chip Select lines are also wired in parallel and each device has its own CS connection/pin.
@@G6EJD David, is it a problem to have peripherals of different resolutions on the i2c line? For example, to esp32 microcontroller; Suppose a 24bit ads1256(i2c), 16bit lis3mdl(spi) and 20x4 liquid crystal LCD display are connected. Do you think there is a problem here?
@@ahmetozdemir7173 none whatsoever, the sensor readings are transferred in a scalar way, so if a sensor has a 64-bit reading the request for a reading would ask for 8-bytes (8x8=64) or a 16-but reading just 2-bytes, the libraries take care of all that.
Yes there is a hardware spi bus using specific GPIO pins assigned by espressif but if you want to use other pins then the spi bus gets implemented in software to allow the chosen pins to be used.
Thanks, David. But, i have trouble when i want to connect and communicate Wemos LoLin ESP32 with arduino due. I try to connect with I2C and Serial Communication, but this is not work for me. Everyone can help me ? please :)
Miski Lastname, you can’t cross connect the I2C bus but you can with the serial, make sure Tx goes to Rx and Rx to Tx and the baud rate and data format is correct for both devices e.g. both 8N1 meaning 8-bit No parity and 1 stop bit.
So the due is Rx and Tx data ok and the ESP32 is receiving only, in which case I suspect you have the wrong pin for Tx data what pins are you using on the ESP32 for Rx and Tx
Thanks for preparing this. This helped me unkink a problem I had but, unfortunately, the ILI9489 still does not work. It was supposed to be in ILI1394 but they sent the wrong display. Have been trying to get it to show for hours. My brain hurts!
I can understand how much hard work you put into this and give it all to us for free. I'm grateful to you.
tradecycles, thank you
I was struggling to get my new ESP32-C3 board to work with a sensor on the SPI bus for the last few days. I was able to resolve the problem using the SPI.begin(SCK, MISO, MOSI, SS) command to re-assign the MISO pin from the default GPIO9 to another pin on the board. That solved the problem and hours and hours of trial and error!! Thanks a ton!!
Great tip about serial outing the SPI pin aliases, - saved me a lot of time. Thanks.
Same!
Many, many thanks! It was a great help for me to understand the SPI Bus!
Thanks for sharing this, I got hit by this problem a day ago, and this video makes it easy
Hi David,
Tried to connect my first SPI device (ePaper display) to an ESP32 board. This one really helped me a lot.
Thanks!
3:02 you absolute legend... been ages trying to figure this out
Should have seen this video first when I started playing with esp32. Different board different peripheral and library, it's a jungle specially the first time. You think you did something wrong, when it's just the library or something else, or reading documentation for different board.. Great video even in 2022 !!!!
Thanks, David. You are the one I turn to these days. I made notes on this! Going to pass them to a friend who has trouble with these pins. Your ePaper WX app is running just fine here, still. Just found out that the ePaper display can do a pretty good grey scale. Never realized it before. Going to update it with those greyscale moon pix with I find them again. Good job!
Thanks, yes epaper images can be dithered to simulate a grey scale, I must investigate too.
Thanks for this! I now have HW SPI working and it's much faster!
Good to hear, the speed difference over a software implementation is significant. If you use any other pins than the designated hardware ones then Arduino emulates SPI in software, this is why it makes such a difference.
Super useful! Thanks for sharing!
it saved my time, thank you david.
Great David, thanks great explanation!
Thank you for your valuable contribution!
clears it up, thanks!
From Brazil, Thank you!!
You are Right SPI is it time consuming a lot. after I connect one TFT 9486 parallel to the ESP32 I want to use the SD-Card reader on that board connected via 5,18,19,23 with a picture demo sketch. Serial.print(SCL) tells me Pin 22 is use instead of 18.
If I can change it with SPI.begin(18,19,23,5) your video is helpful. SCL=18 have no effect in the Arduino IDE.
I will choose the names MOSI,MISO,SCL and SS in the Sketch because of the predefines in the most libraries.
If you define the pins away from the compiler default the Arduino IDE implements a software emulation of the SPI bus. You can find what’s are used by the compiler by either printing out the key names or by inspecting the hardware folder for the board the file starts win ‘pins’ a parallel SD card drive should work ok, just make sure both the display and SD card reader have separate and unused pins for their Chip Select (CS)
@@G6EJD , thanks for your answer. I have found the issue, in this demo ( read a picture from SD-Card and Transfer to the TFT ) sketch the author forget the SPI.begin() complete.
After insert the begin statement I can read the SD with Pins 18,19,23,5. I think this SPI is not emulated because of the very fast speed.
I will compare The same pictures loading from SPIFFS and see how times faster this is.
Big up to you !
Merci from France
This was very helpful, thanks a lot
Thank you, thank you, thank you.
@2:25 SDO is Serial Data Out; SCL is Serial Clock and SDI is Serial Data In. This is irrespective of whether you are using your device as a controller or as a peripheral.
You could just hook up your controller's SDO to peripheral's SDI and vice-versa.
I’m not sure what your saying, I was pointing that MOSI is often called SDO and MISO called SDI
@@G6EJD You were saying Slave Data In/Out and Slave Clock when that's not what it is. It's Serial Data In/Out and Serial Clock
@@benjaminshields9421 well it’s semantics as the SPI bus has the concept of Master and Slave devices and that is a one-to-many relationship, so there can be many Slaves. When someone is learning it seems best to me to use the term Slave so as not to confuse them with another term.
Is "SS" (chip select) needed if only ONE device is running on the SPI bus? Can't it be hardwired to VCC or GND to be always selected? (trying to save pins)
Henrik Östman, don’t know, you could try it to find out, most likely if there are issues it’s at startup.
Is it possible to communicate between 2 ESP32's via SPI? for some reason i have to use SPI and i cannot use UART (rx, tx).
You can but it’s not easy to implement. The SPI bus is comprised of a Master and Slaves, the libraries are configured to be the Master so for the other device you’d need to set that up as a Slave, there is provision in the SPI library from Espressif to set up an ESP32 as either master or slave.
@@G6EJD Thank you for the quick reply, also it is not possible to make it a duplex SPI right?
You can have a duplex communication MOSI and MISO are for that, but Von Neumann architectures can only achieve full duplex by switching between processes. Many SPI devices send and receive data. Your challenge is to get the other processor to operate in Slave mode like a sensor would. Not sure why you can’t use I2S or serial as the performance would be close.
Thanks a trillion.
I really appreciate.
What library do you use for the test sketch to serial print the parmeters?
No library, all built in functions.
thanks. you saved my day
An ESP32 DevKitC board works well with an ST7735 TFT screen and the TFT_eSPI library and the board also works well with the VS1053 board and esp_wifi library. However, running SPI and Wifi together results in a problem with SPI as the ST7735 screen whites-out.
Any suggestions would be very welcome.
There is nothing especially different with the Devkit C variant so I would try using Adafruit's ST7735 library and dropping the TFTeSPI library and is almost certainly what is causing the conflict. Using the in-built (assuming your IDE is current 1.8.10 and 2.4.2 and 1.0) libraries should result in no issues.
you saved my live
TY
Thanks, SPI and HSPI take so much time to understand, This video made the process of understanding SPI on esp32 a lil bit simpler ^._.^
There is no difference between SPI and HSPI both run at the same speed, I think what’s caused this confusion is Espressif’s use of the H and V port designators. Both ports are identical and the SPI specification is what it is, there is no specification for a High speed version.
@@G6EJD How is possible to use HSPI for the SdFat library and the VSPI for an ADC (MCP3208) at the same time?
I can work with both of them independently, but I can't merge them.
Cheers!
You can’t merge them and I assume you have two I dependent circuits for each SPI bus which includes a CS for each device. Are you sure you are creating two instances of the SPI I stance spi1.begin and spi2.begin and using the correct identifier when reading each bus? I have not seen any libraries that allow more than one instance to be created!
You can easily use both the ADC and SD card on the same SPI bus, the CS for each device determines which device is active
@@G6EJD Yes, I have two independent SPI connections and two CS pins.
I tried to follow different topics about two instances, but it doesn't work. Is there some clear example somewhere? I'll give a try with SD.h, but is slower than SdFat.h
Great David, thanks great explanation! There are also some SPI components like cameras that have additional SDA / SDL pins too, do you know if they also have a constant defined ?
Martin, no only the pins for the standard I2C bus will be defined, unless a specific camera device is listed in the boards section, but I know of none. It seems like just a need to connect the I2C bus to the camera as well as the SPI connections.
Thanks! Here in this sketch : github.com/martinberlin/FS2/tree/board/esp32
Serial.println(SDA); // Works! But SCL has no constant
I added the pins like David described. For the Arducam (2MP or 5MP) the SCL is 22 and SDA is 21. If you have any Arducam around try it out. Supported models are: OV2640 / OV5642
Great video!!
Is there any video for ESP32 and ILI9486/ILI9481?
You can get a driver from here: www.arduinolibraries.info/libraries/waveshare-ili9486
Interesting video thanks!
The PIN 5 on the Lolin board also lights the on board led, so every time SS goes low the led will light.
Might be an interesting effect and useful in debugging, but I cant see any way to disable the led on the board apart from physically disconnecting it.
Have you found away around this or will you simply use another PIN?
Check out the file in your IDE location, mine is at ArduinoIDE\hardware\espresssif\esp32\variants\lolin32 in there is a file called pins, which you can change so that Slave Select is on another pin, it’s a small design error/bad choice of Wemos to have used pin-5 for the LED unless you like the light show when the SPI devices are being used!
Thank you so much!
I could not find this pin info before when looking thru various files created during compiling. So easy to change when you know how.
The Wemos Lolin32 is a great little board but its good to know I can change pin 5 so easily. Keep the videos coming I'm learning so much from watching them!
Hello, the video was good. Is it possible to communicate with esp32, ads1256(SPI), LIS3MDL(I2C) and 20x4 lcd(İ2C) together?
What kind of connection should I make?
Yes, the ESP32 has an SPI and I2C bus. The I2C devices have separate device addresses so are all wired in parallel and the SPI bus except for Chip Select lines are also wired in parallel and each device has its own CS connection/pin.
@@G6EJD David, is it a problem to have peripherals of different resolutions on the i2c line?
For example, to esp32 microcontroller; Suppose a 24bit ads1256(i2c), 16bit lis3mdl(spi) and 20x4 liquid crystal LCD display are connected. Do you think there is a problem here?
@@ahmetozdemir7173 none whatsoever, the sensor readings are transferred in a scalar way, so if a sensor has a 64-bit reading the request for a reading would ask for 8-bytes (8x8=64) or a 16-but reading just 2-bytes, the libraries take care of all that.
I guess there is hardware spi and software spi in esp32 but not sure I got confused too
Yes there is a hardware spi bus using specific GPIO pins assigned by espressif but if you want to use other pins then the spi bus gets implemented in software to allow the chosen pins to be used.
Thanks, David. But, i have trouble when i want to connect and communicate Wemos LoLin ESP32 with arduino due. I try to connect with I2C and Serial Communication, but this is not work for me. Everyone can help me ? please :)
Miski Lastname, you can’t cross connect the I2C bus but you can with the serial, make sure Tx goes to Rx and Rx to Tx and the baud rate and data format is correct for both devices e.g. both 8N1 meaning 8-bit No parity and 1 stop bit.
If i use serial communication Wemos lolin esp 32 can receive data but not send data back to arduino due
So the due is Rx and Tx data ok and the ESP32 is receiving only, in which case I suspect you have the wrong pin for Tx data what pins are you using on the ESP32 for Rx and Tx
I use the tx pin in wemos connect ro rx pin in arduino due
Miski Lastname, you cant use the Tx and Rx pins of the wemos they are used for programming the device use software serial to define the pins required
Thanks for preparing this. This helped me unkink a problem I had but, unfortunately, the ILI9489 still does not work. It was supposed to be in ILI1394 but they sent the wrong display. Have been trying to get it to show for hours. My brain hurts!
You need to find a screen driver for the ili9489, but haven’t seen any, the library is your problem
I’ve just checked, the ili9489 is an 8-bit parallel interface not an SPI variant so it’s no good
Update: It works. See below for help setting it up.
@@michealmorrow1481 so did you manage to find an SPI mode in the configuration pins?
Yes. I am sending you an email now.
The information for the SPI version of the ILI9486 is here: ua-cam.com/video/rq5yPJbX_uk/v-deo.html