Hi,
I'm having trouble connecting my MFRC522 RFID card reader. I tried some of the libraries, but no success.
I guess I still have the wrong pinnings or settings ?!
Example here:
MFRC522DriverPinSimple ss_pin(10);
But what about the other pins?
I'm using this pinnings:
But how to configure in Arduino IDE? Thank you for any hint!
yes, I'm using the schematic from the link. But I'm also able to rewire, no problem.
Maybe that was misleading, I know Arduino is not using micropython, but I think that the point is missing where I tell Arduino or more specific the used libraries which pins to use.
So what are you hoping to do?
Convert it into C/C++ and run it in the RP2040 under one of the two Pico boards?
Or use one of the 3V3 Arduinos and write the code in C?
The key is identifying the SPI pins if you want to use the SPI interface hardware built into the processor. Otherwise you can bit bang the SPI protocol on any input / output pins.
I have interfaced three RFID readers over SPI but on a Raspberry Pi, not a Pico. But I did use Python. Schematics and software are available if you are interested.
Hey Mike,
I don't need to convert anything, I have sample programs and can upload them to the pico.
What I do not know is, which pins to use. And I'm also wondering how to set the used pins, since in the sample programs I only read about ss_pin and rst_pin, but nothing about MOST/MOSI/SDA.
So I hope to find an answer here, what would be the "standard" pins on a pico to use the arduino example programs.
The Pico has two SPI interfaces, called SPI0 and SPI1. Each appears on an number of different pins, but basically they are only two. The resit and select lines can be any pins you want to specify.
Find the pin out anywhere on the net, but this link has one.
Thank you Mike for always coming back to this thread, even though we talk past each other !
Of course I know the pinning of the pico.
But: When I open an example program within an arduino module for MFRC522, it tells how to connect the pins to arduino boards, but how do I do it for the pico?
I hoped to easily change to the correct GPIO PINS of Pico, but the program itself only defines two pins (RST and SS). But how can I change the others (SDA, MOSI, MISO, ...)?
Yes sorry I am trying to get an angle on what you are trying to do and how you are going about it.
You seem to me to be avoiding answering some of my questions. Can you answer these two specifically please.
are you trying to use an Arduino C/C++ RFID program on the RP2040?
if you are you need to run it under a system that allows the IDE to communicate with the Pico. There are two methods you can do this, using mBed (the official system) or using the unofficial Earle Phil Hower framework?
In future can you please not post code as images. They are restricted in how much you can post, but more importantly no one else can run your code, whiteout typing it in. No one is going to do that especially as it is so easy for you to post code correctly for this forum. If you don't know how to do this then look at the getting the best from this forum link which is at the start of each section.
If you use the Earle F. Philhower framework then there extra commands to allow you to control what pins have the Tx (MOSI) and Rx (MISO) pins for each of the two SPI interfaces in the bus.
You will find the details on this link:- SPI pins.
When I was using the Pico under the Raspberry Pi API, then the functions were different and looked like this:-
// SPI Defines use SPI 0, and allocate it to the following GPIO pins
#define SPI_PORT spi0
#define PIN_MISO 4
#define PIN_CS 5
#define PIN_SCK 2
#define PIN_MOSI 3
// global variables for SPI out
uint8_t buf[] = {0x6b, 0x00};
uint8_t daConfig = 0x70;
int16_t d_a_out = 0;
void spi_setup(){
// SPI initialisation use SPI at 8MHz.
spi_init(SPI_PORT, 8000*1000); // 8MHz
gpio_set_function(PIN_MISO, GPIO_FUNC_SPI);
gpio_set_function(PIN_CS, GPIO_FUNC_SIO);
gpio_set_function(PIN_SCK, GPIO_FUNC_SPI);
gpio_set_function(PIN_MOSI, GPIO_FUNC_SPI);
// SPI Chip select is active-low, initialise it to high
gpio_set_dir(PIN_CS, GPIO_OUT);
gpio_put(PIN_CS, 1);
}
void sendSample(int16_t sample){
buf[1] = sample & 0xff; // least significant byte
buf[0] = ((sample >> 8) & 0x0f) | daConfig; // most significant nibble
// send out the data to the D/A through the spi
cs_select();
spi_write_blocking(SPI_PORT, buf, 2);
cs_deselect();
}
static inline void cs_select() {
asm volatile("nop \n nop \n nop");
gpio_put(PIN_CS, 0); // Active low
asm volatile("nop \n nop \n nop");
}
static inline void cs_deselect() {
asm volatile("nop \n nop \n nop");
gpio_put(PIN_CS, 1);
asm volatile("nop \n nop \n nop");
}
Of course these contain calls to built in functions of that API and can't be directly copied into code running under one of the Arduino frameworks.
Note that these pins can be any of the pins of the same name in the Pico pinout diagram.
So for example SPI0 Tx pin can be either GPIO 0, GPIO 4, or GPIO 19, without restricting your choice of what GPIO pins your other SPI0 signals are on.