SPI problems on Arduino Pro Mini

I recently bought a Digital Potentiometer (MCP41010), and I am wanting to control it using the Arduino Pro Mini (5V, ATmega328), communicating using the SPI library.

First I tested the Digital Potentiometer using an Arduino Mega, connecting the SS to pin 53, SCK to pin 52, and the MOSI to pin 51, and ran a test sketch that worked fine.

However when I run the test sketch on a 5V Arduino Pro Mini, it does not work (it appears to be sending random data to the Pot). When using the Pro Mini, I connect SS to pin 10, SCK to pin 13 and MOSI to pin 11.

Below is the sketch I used. Note that when swapping between Arduino Pro Mini and Arduino MEGA, the variable SSpin needs to be altered.

//Test Code to find/control a digital potentiometer (MCP41010)
//Uses SPI communication
//
//Based on 'DigitalPotControl', the SPI library demo code
//
// Potentiometer connections (from chip to arduino):
// Chip Select CS(1) is connected to SS (pin 53 on Arduino mega, pin 10 on Arduino Pro mini)
// Serial Clock SCK(2) is connected to SCK (pin 52 on Arduino mega, pin 13 on Arduino Pro mini)
// Serial Input SI(3) is connected to MOSI (pin 51on Arduino mega, pin 11 on Arduino Pro mini)
// Neg Power Vss(4) is connected to GND
// Ouput pin PA0(5) is connected to GND
// Wiper pin PW0(6) is connected to pin A1
// Input pin PB0(7) is connected to 5V
// Pos Power Vdd(8) is connected to pin 3

//Include the SPI library
#include <SPI.h>

//Set the slave select pin (as in description)
const int SSpin = 10; //set to 53 for Arduino MEGA
//Set the wipe input pin (as in description)
const int Wpin = 1;
//Set the power pin (as in description)
const int POWpin = 3;

//Define variables for storing current and last read voltage
float voltage = 0;
float prevoltage = 0;

//Main setup function
void setup() {
  //Set Power pin as output, and set it high to turn on chip
  pinMode(POWpin, OUTPUT);
  digitalWrite(POWpin, HIGH);
  //Set slave select pin as output, and set it high to de-select chip
  pinMode(SSpin, OUTPUT);
  digitalWrite(SSpin, HIGH);
  //Set wiper pin as input
  pinMode(Wpin, INPUT);
  //Initialise SPI
  SPI.begin();
  //Initialise Serial
  Serial.begin(9600);
}
 
void loop() {
   //Loop through 128 channel, to find the digital potentiometer:
   for (int channel=0; channel<256; channel++) {
       //Get initial voltage, and store in prevoltage
       prevoltage = (float)analogRead(Wpin)*5.0/1024.0;
       //Loop throught the resistance on this channel, from min to max
       for (int resist=0; resist<256; resist++) {
           //Set resistance
           MCP41010Write(channel,resist);
           delay(2);
           //Read input, and convert to Volts
           voltage = (float)analogRead(Wpin)*5.0/1024.0;
           //If it has changed from previous voltage (by at least 0.005 Volts) display results
           if (abs(voltage-prevoltage)>0.01) {
             //Print results to serial
             Serial.print("Resitance on Channel ");
             Serial.print(channel);
             Serial.print(" set to ");
             Serial.print(resist);
             Serial.print(", reading: ");
             Serial.print(voltage);
             Serial.println("V");
           }
           delay(2);
           //Update previous voltage
           prevoltage=voltage;
       }
       //Print update
       Serial.print("Done testing channel ");
       Serial.println(channel);
   }
   //Turn off Chip, and display end of test message
   Serial.println("End of Test");
   digitalWrite(POWpin, LOW);
   digitalWrite(SSpin, LOW);
}
 
void MCP41010Write(int address, int value) {
  //Take the slave select pin low, to select chip
  digitalWrite(SSpin, LOW);
  //Send the address, followed by the value to set
  SPI.transfer(address);
  SPI.transfer(value);
  //Take the slave select pin high, to de-select the chip
  digitalWrite(SSpin, HIGH);
}

What am I doing wrong? I feel that the problem is related to the Clock.

I doubt that the clock is the trouble maker, SPI will fail only if the clock is way too fast. More likely long cables will cause problems, or wrong operating voltage (3.3V instead of 5V).

My Pro Mini can run on both 3.3V and 5V, when the 5V supply is connected to RAW (3.3V) or to Vcc (as supplied). Check the data sheet of your board, whether it includes an 3.3V or 5V regulator, and power it accordingly.

Make sure that you program the board as Pro Mini 5V 16MHz, not 3.3V 8MHz.

I have tried two Arduino MiniPro 5V,16Mhz boards with an OLED SPI display and neither one is driving the SPI serial clock (D13), Mosi (D11) is fine as well as the D_C (D7) and SS (D10) ? Pro Mini 168 is selectable but I dont see selections for 5V vs 3.3V or 8Mhz vs 16Mhz? I use the <SPI.h> Set to MODE3, MSB first. The SCLK is just staying at 3V level when its configured.

Can you post a schematic and code?

sclk D13, MISO D12, MOSI D11, SS D10, plus D_C for OLED 1603 Data/Command

Hi,
Can you post your code please?

Thanks.. Tom... :slight_smile:

I dont see any button for appending or posting a file?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html.

It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

I have read the introduction, but cannot find the "Additional Options" so that I can load the ziped C-code or append a schematic.

Hi,
Please do not attach a zip file.
Attach an .ino file, or a txt file, or put your code into you post using </> code tags.

You are using "Quick Reply"

Before you post your post, click on "Preview" then you will see the Attachments

If you use "Reply" you will see the features you need.

Tom... :slight_smile: