Hello
Like I wrote in the description. I want to connect a MCP2515 to an Arduino Nano ESP32 because I want to use an BMW iDrive controller as an HID for Android. I've testet the code with an Adafruit Feather ESP32 and it worked (without HID). Yesterday I got the Nano and since I am trying to figure out why it doesn't work with the Nano. I am using the BMW Idrive demo by Darren Siepka (Github) as a starting point.
Hope someone can help.
Please add a forum reply here that provides a detailed explanation of what you mean by "doesn't work", including:
- What did you do?
- What were the results you expected from doing that thing?
- What were the results you observed that did not match your expectations?
Make sure to include the full and exact text of any error or warning messages you might have encountered.
Please post a link to where you downloaded the demo from.
Sorry...wasn't sure if I can post links.
only thing I changed where the CS and INT Pins in Line 36 and 37. For the feather I changed them to 2 and 12. After bridging the 120 ohm resistor the iDrive came to live and I received Can messages.
With the Nano I tried the default pins 6 and 10. And other pins but nothing ist happening. Maybe I have to define the pins different on the nano Esp than on the feather!?
You should probably specify the exact Adafruit Feather esp32 you’re using, there are quite a few options….
I am going to guess this is another pin numbering issue maybe??
when using this individuals library, by defining “pins” he is defining the exact gpio on the esp32 chip whereas when you use this library with your new Nano Esp32, you are using arduino pin numbering and defining completely different gpio’s??
Looks into that… arduino guys/gals have been really good at helping others and posting help and links for this, just search “numbering” in this exact sub forum
The feather is an Huzzah32. I read about the numbering but nothing seems to work.
My connection:
MCP -> Nano32
VCC. 3,3v
GND. GND
CS. D10
MISO. D12
MOSI. D11
SCK. D13
INT. D6
I have tried D6 and D10, 6 and 10, 9 and 21 (for GPIO) in Arduino and legacy Mode but nothing.
Then I have tried an Arduino Leonardo and everything is fine.
Leonardo would work but I would love to use the nano because of its size.
Hey @malte_entzmin,
I have tried D6 and D10, 6 and 10, 9 and 21 (for GPIO) in Arduino and legacy Mode but nothing.
The safe bet in your case is choosing "Legacy" and using labels for pins (D10
, not the number 10
) in your code everywhere. I don't see any other obvious problem, but I have some suggestion for more testing:
- can you force your pin selection by calling
SPI.begin()
at the beginning ofsetup()
with all parameters? The hidden parameters on the ESP32 target are in the following order:
void begin(int8_t sck=-1, int8_t miso=-1, int8_t mosi=-1, int8_t ss=-1);
- can you post your serial log?
Let us know your results!
[OT] Lovely device for a hacking project a HID interface would be sweet!
Not sure if what I did is correct. Here is a part of my code:
// CAN0 INT and CS
#define CAN0_INT D6 // Set INT to pin 6
MCP_CAN CAN0(D10); // Set CS to pin 10
void setup()
{
SPI.begin(13,12,11,10);
delay(5000);
Serial.begin(115200); // CAN is running at 500,000BPS; 115,200BPS is SLOW, not FAST, thus 9600 is crippling.
// Initialize MCP2515 running at 8MHz with a baudrate of 500kb/s and the masks and filters disabled.
if(CAN0.begin(MCP_ANY, CAN_500KBPS, MCP_8MHZ) == CAN_OK)
Serial.println("MCP2515 Initialized Successfully!");
else
Serial.println("Error Initializing MCP2515...");
// Since we do not set NORMAL mode, we are in loopback mode by default.
CAN0.setMode(MCP_NORMAL);
pinMode(CAN0_INT, INPUT); // Configuring pin for /INT input
//Serial.println("MCP2515 Library Loopback Example...");
}
I uploaded it in legacy mode.
Serial Monitor:
"Error Initializing MCP2515...
Error Sending wakeup Message...
Error Sending rotary init Message...
Error Sending wakeup Message...
Error Sending rotary init Message...
Error Sending wakeup Message...
Error Sending rotary init Message...
Error Sending wakeup Message...
Error Sending rotary init Message...
Error Sending wakeup Message...
Error Sending rotary init Message...
Error Sending wakeup Message...
Error Sending rotary init Message...
Error Sending wakeup Message...
Error Sending rotary init Message..."
Please try with
SPI.begin(D13, D12, D11, D10);
to keep using labels and not numbers. It makes a huge difference, since that hides the complexity of GPIO number mapping. Labels will work every time, with numbers... it's a lot trickier
Oh. Was too fast. But with...
SPI.begin(D13, D12, D11, D10);
Still the same
Damn... I tried!
One last thing. I assume your CAN board and transceiver supports 3.3V? The Leonardo is 5V so that would have worked on both 5V only and 3.3/5V boards.
Otherwise, I'm out of ideas on what the issue could be.
Out of curiosity, do you confirm that if you switch MOSI, CLK and/or SS pins in the begin
call to LED_RED
, LED_GREEN
or LED_BLUE
you see the RGB LED blinking briefly? (of course this won't fix the issue but it confirms the proper GPIOs are being used).
I've also tried the same sketch with the adafruit Huzzah32 (which is 3,3v) and everything works. So I guess that's not the problem.
Do you mean by switching the pins...
SPI.begin(D13, D12, D11, D10);
to the corresponding pins for the LEDs? like....
SPI.begin(LED_RED, LED_GREEN or LED_BLUE);
Thank you for your help
If I do
SPI.begin(LED_RED, LED_GREEN or LED_BLUE);
The LED blinks RED and then pulsing in orange (mixed color)
Hello @malte_entzmin, I have tried connecting a MKR CAN Shield to the Nano ESP32 using your pinout, and managed to connect successfully to the MCP2515...
(it then fails sending messages, but there is nothing on the CAN bus, so that part is expected).
What I did:
- downloaded "master" branch of the Github project linked above as zip
- from the zip:
- copied
libraries
folder to the Arduino sketchbook (Arduino/libraries/MCP_CAN-master
) - copied
idrive_controller_demo
to the Arduino sketchbook (Arduino/idrive_controller_demo
)
- copied
- opened
idrive_controller_demo
in the IDE - modified
D6
andD10
as the above picture - selected "By GPIO number (legacy)" in the Tools menu
- verified and uploaded the sketch
hmm...strange maybe there is something wrong with my Nano Esp32. Sadly it's the only one I have so I can't test it with another one.
Thank you for testing it with your board.