-1

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!

migrated from electronics.stackexchange.com Aug 3 '18 at 14:58

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 3
    Other than passing a different argument to SD::begin()? – Ignacio Vazquez-Abrams Aug 3 '18 at 13:01
  • Hmm, I though any GPIO pins could be used for slave selecting. – Long Pham Aug 3 '18 at 13:53
  • pin 10 is CS if Atmega 328 is a SPI slave. if Atmega is master pin 10 must be output otherwise the chip switches to slave. pwm is output – Juraj Aug 3 '18 at 16:37
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 Aug 3 '18 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy