How to change the default Slave Select pin (Digital pin 10) on Arduino UNO R3 for SPI communication?
Currently I am working on an Arduino based project. My project require interfacing 6 servo motors and an SD card module to my Arduino UNO. The problem is that I need all the six PWM pins for six servos (Including pin 10) which happen to be the default Slave Select Pin for SPI communication. I don't want to use software based PWM on a digital pin. I could not find any resource on how to change the default SS pin to any other pin. Any help in this regard will be highly appreciated. Thanks!
1 Answer 1
Just declare it and use it:
byte ssPin = 7; // or any other pin, stay away from 0,1, leave those for Serial()
byte defaultSS = 10; // 53 on a 2560
pinMode (ssPin, OUTPUT);
digitalWrite (ssPIN, HIGH); // typical slave select OFF state
pinMode (defaultSS, OUTPUT); // 10 MUST be an output for device to be SPI master (328P)
SPI.begin(); // default is 4 MHz speed, MSBFIRST
// takes care of SCK, MISO, MOSI, don't need define/declare those
digitalWrite (ssPin, LOW);
SPI.transfer (ledData, 0xAA); // example data going to a device
digitalWrite (ssPin, HIGH);
-
1" The problem is that I need all the six PWM pins for six servos" The Servo.h library can drive 12 Servos on an Uno, and on any pin,not just PWM pins. Check it out. Servos need a 1-2mS (1000 to 2000 uS) wide pulse occurring every 20mS (50 Hz), which is not really PWM. (1mS = full turn one direction, 1.5mS = centered, 2mS = full turn the other direction, give or take a few uS). I bet that could be created using Blink without Delay technique even, 50 Hz is pretty slow.CrossRoads– CrossRoads2018年08月03日 15:41:42 +00:00Commented Aug 3, 2018 at 15:41
SD::begin()
?