Go Down

Topic: editing files to use SPI pin numbers on mega? (Read 356 times) previous topic - next topic


So I'm using a sparkFun AutoDriver, with libraries for it linked here.

I found this information in a user review:

ATTENTION ARDUINO MEGA USERS: The libraries provided for the autodriver are excellent, however the .ccp files have hard-coded references to the SPI pin numbers on the Uno. In order for this board to function on the Mega, you must edit the files to use the SPI pin numbers on the Mega. Hopefully this will save someone some time (it would have saved me a few hours…).
... So since I know the problem, it shouldn't be too much of an issue.

However, I have no idea how to go about fixing the problem. This is my first time doing anything with an Arduino, and could really use some help.

Thanks in advanced!


The Uno uses SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK).
The Mega uses SPI: 50 (MISO), 51 (MOSI), 52 (SCK), 53 (SS).

So it looks like you need to edit the library .cpp file(s) to reflect the difference.  Personally I would use Notepad++ to edit the files and comment out the Uno specific lines rather than deleting them and add new lines with the relevant Mega pins.  Bear in mind that this will make the library unusable with the Uno.  There are ways round this if it matters to you.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


Dec 21, 2015, 05:51 pm Last Edit: Dec 21, 2015, 05:52 pm by guix
Hello and welcome,

I took a (quick) look at the library files and I didn't spot a problem. The comment that you are quoting was written 9 months ago, but the library was updated 8 months ago. So maybe this was fixed.

But what about just trying the examples of this library, and see if they work on your Mega ?


I can't find any hardcoded pin number references in there - only place I see the pins being referenced, they're using MISO/MOSI/SCK, and I think those defines should just work?
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Go Up