• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

change SPI library Pin numbers

Q&A Forum › Category: ESP32 › change SPI library Pin numbers
0 Vote Up Vote Down
Peter Colls asked 4 years ago

I am using VS Code and PlatformIO to program the ESP32, plus I am using the ESP-Prog to debug the code. The ESP-Prog uses pins 12, 13 and 15. I am using 4 SPI devices, DAC, ADC and two for the touch screen. I am using the VSPI pins for SPI processing. I am using the standard SPI Library (“#include<SPI.h>”). My question is “How can I reassign the VSPI pin numbers to this library???
Many Thanks
Peter

Question Tags: SPI.h Library
1 Answers
0 Vote Up Vote Down
Best Answer
Sara Santos Staff answered 4 years ago

Hi.

At the beginning of your code, declare the pins you want to use, for example (the VSPI pins):

#define SCK  17
#define MISO  19
#define MOSI  23
#define CS  5

In the setup(), create a new SPI class on VSPI.

SPIClass spi = SPIClass(VSPI);

Initialize SPI communication protocol on the pins defined previously:

spi.begin(SCK, MISO, MOSI, CS);

Then, use the regular SPI functions.

If you’re using libraries to interact with your devices, you might need to pass this new spi object when initializing the libraries.

Tell me if this helps.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.