Hi all:
Let me first point you here but long story short, my GPIO pins, specifically my SPI clock (SCK) pin was not set to the default in the esp32-C3 datasheet. I then went digiing and found this file on github:
is pins_arduino_h part of arduino_h library or is it loaded as part of the board set-up? Can this file be used to change the gpio behavior? At any rate…at least it answers my question as to why my pins were behaving like they were!
The build system adds the variant folder (as defined in the PlatformIO board definition) to the include paths and the Arduino.h file does
So yes, The pins_arduino.h is autoincluded as part of Arduino.h (and SPI.h etc.) and that fiel does control the standard pinmapping.
With the SPI code in particular however you can easily control the used SPI pins with the SPI.begin(...); call
If you are using a library that in turn uses the SPI library for communication, then you have to look whether you can pass the SPI pins to its constructors (or methods). Sometimes they also allow that custom SPI object / pointers are passed to the class, which you can create and pre-initialize.
On the other hand, it is totally possible to redirect the used the pins_variant.h (and related files in that variant) to your own folder. That’s the entire point of this code
And that will make the builder script use the given base directory and subfolder for the variant instead of framework-arduinpespressif32/variants/lolin_c3_mini. You can easily start off by duplicating those original files inside the project folder’s custom_variants/my_custom_variant folder and adapt the needed standard settings.
Another observation: I am using an spi display. As part of the code the frames per second is printed. I recall a while back trying to use a method similar to the SPI.begin to change the pin assignment but the frames per secon were dramatically reduced. I came across some forum discussions that were about “software spi”(slower) vs “hardware spi” and assumed that is what I was seeing. I will try the spi.begin again to confirm.
On a side note - could I just add #include " pins_arduino.h" in my src folder in my project?
@maxgerhardt
A quick follow-up. I had some code on esp32-C3 and I wanted to move it over to an esp32-S3 board. I am using an SH1106 display. So I began a new project with an esp32-S3 board and just copied the code over. The display was garbled so I loaded a program that was a simple graphics test and confirmed there was an issue with talking to the display. I am using a graphics library U8g2 and I think the issue is with the default SPI pins. I wanted to check the default pins for the esp32-s3 board. So I used the following code in setup: