Arduino Micro Programming Trouble

Hi There,

I have this code that works completely with the Arduino Uno but I cant get it to work with the Arduino micro, the Arduino gets programmed but it does not increase the positions. I’m totally lost, I have no idea where is the problem, Any help will be appreciated.

/*
Digital Pot Control

The circuit:

  • CS - to digital pin 10 (SS pin)
  • SDI - to digital pin 11 (MOSI pin)
  • CLK - to digital pin 13 (SCK pin)

*/

// inslude the SPI library:
#include <SPI.h>
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
}

void loop() {
// go through the six channels of the digital pot:
for (int channel = 0; channel < 1; channel++) {
// change the resistance on this channel from min to max:
for (int level = 0; level < 255; level++) {
digitalPotWrite(channel, level);
delay(200);
}
while(1);
}
}

void digitalPotWrite(int address, int value) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin,LOW);
// send in the address and value via SPI:
SPI.transfer(address);
SPI.transfer(value);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
}

  * CS - to digital pin 10  (SS pin)
  * SDI - to digital pin 11 (MOSI pin)
  * CLK - to digital pin 13 (SCK pin)

Those are correct for the UNO and other 328P-based Arduinos, not for the Micro and other 32U4-based Arduinos. See the Leonardo (32U4-based) pinout in the SPI library reference.

so, I'm kind of new to Arduino, Can I polish up my code to make it work with the Arduino Micro Or this is not an option?

aghaderi2006: so, I'm kind of new to Arduino, Can I polish up my code to make it work with the Arduino Micro Or this is not an option?

You don't need to change your sketch at all. You just have to wire MOSI and SCLK through the ICSP header. SS can continue to use Pin 10. The SPI library is already using the ICSP header which is why connecting to pins 11 and 13 isn't working.

Thanks for the feedback, I finally got it to work. Thanks for the fast responses.