Arduino Library Development

Hello,

I have very little knowledge about Arduino libraries so please correct my mistakes.

I am trying to learn how to program Arduino Libraries. The first problem that I have just encountered was how do Arduino libraries set pins for certain modules. When I upload code with many Arduino sketches, such as code examples for my Arduino Nano IOT 33 using the Arduino WiFiNINA Library, the code just instantly uploads and works. However, what I am wondering is where are the pins set that tell microcontroller how to talk to the WiFi/Bluetooth module?

WiFiNINA Github

Does anyone know how this works? Where are the microcontroller pins set in certain libraries such as the Arduino WiFi NINA library, so that the microcontroller can talk to the WiFi/Bluetooth module.

I would love to hear what you think! I have come so far in the last year with Arduino, and am eager to learn more.

Thank you!

It's in utility/spi_drv.cpp:

The macros are defined in the variant file of each board, for example in the case of the MKR WiFi 1010:

Hello,

Thank you for your amazing feedback. I am slowly getting a better understanding, however, I have a few questions.

First of all, I think that origin of the pin definitions for the pins that talk to the module are on lines 70-712 and lines 116-119 of the variants.h file of the MKR1010. But, what I don't understand is what is the (30u)?

When the pin name is next to a (#u), what does that mean?

For example, to help me get a better understanding, if you were to change the pins of the main SPI on the MKR1010 that talk to the module, how would you change these pin definitions?

On the MKR1010, schematic, SPI pins PA12-PA15 are connected to the module. But, if you were to change those pins to PA16-PA19, how would you change these files for that to work? (MKR1010 datasheet can be found on arduino product page)

Thank you for your awesome help! Let me know if you have any questions.

Thanks again!

do you want to use WiFiNina with other then the Nina boards?

to make Arduino WiFiNINA library work with any Arduino, only add something like
-DNINA_GPIO0=4 -DSPIWIFI_SS=5 -DSPIWIFI_ACK=6 -DSPIWIFI_RESET=7
to build.extra_flags in boards.txt or boards.local.txt

and wire an esp32 with Nina firmware to SPI pins and the aditional required pins.

Thank you for your reply! I am not trying to specifically do that, but am trying to learn how to change the pins.

In your response, you said to add those certain lines of code, however, where are they written in the first place? Also, where do you find that certain file directory, boards.local.txt?

Finally, does anyone know that answer to my question in my previous post? What does the (30u) or something in Arduino board variants files do? Does that set a certain pin, because next to that thing was the pins number variables used in the Wifi NINA library?

Does changing that (30u) thing change the pins as well? Does anyone know what they are/where I can learn about them?

I would love some help! Thank you for your tine.

Does anyone know anything about this? Thanks!

kevin_smith_55:
Does anyone know anything about this? Thanks!

so for me it is too much writing in english. but here are some pointers:
https://arduino.github.io/arduino-cli/platform-specification/
the pins for a board are in variant file.
u si C syntax for unsigned constant
30 is a number of pin. this one used internally on board, not on pins header

Hello, thank you for your reply...

I'm sure I understand because when I look at the variant.h file of the MKR1010, the (30u) or something does not align with either the physical microcontroller pins, the PortB or PortA pins in the variant.cpp, or the pins for the arduino software...

I am extremely confused right now.... Does anyone know a solution/reference

I would love help and appreciate any responses.

Thanks again!

30 is the index of the g_APinDescription[] array:

Arduino pin numbers are just arbitrary identifiers assigned to IO pins. They don't necessarily have any relation to physical pin number or port number.

Thank you for your reply.

I understand that Arduino pins numbers can be what ever, however I don't understand where the microcontroller actual pin is linked to the made up Arduino pin...

Because in the variants.cpp file, the pin functions are set for the physical pins, and in the variants.h, I can see that variables are assigned a made up arduino pins number... However, where does that variable connect to the physical pin????

Do you know or is there a tutorial?

thanks

variant.cpp

line for pin 30. comment and struct initialization line.
do you see it? PA27?

 | 30         |                  |  PA27  | NINA_GPIO0      |  *15   |     |     |     |     |         |         |        |        |          | GCLK_IO0 |


 { PORTA, 27, PIO_DIGITAL,    (PIN_ATTR_NONE                                ), No_ADC_Channel, NOT_ON_PWM, NOT_ON_TIMER, EXTERNAL_INT_15 },

Hello,

Yes, I did notice that, however it is comment, so it doesn't do anything, right?

Where is the code that links the physical pin and arduino pins? I'm not understanding very well.

Thanks

Is there a tutorial?

kevin_smith_55:
Where is the code that links the physical pin and arduino pins? I'm not understanding very well.

the first two fields put in the struct are
PORTA, 27

and the index of this array item is the Arduino pin number.

the physical pin of the die has no meaning in software