Pages: [1]   Go Down
Author Topic: mcp4261 does not name type "resolved" added second sketch\library  (Read 1395 times)
0 Members and 1 Guest are viewing this topic.
Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Please help me, I am trying to use a digital pot but, I can't get the code to compile. No matter whether I use IDE 22,23, or 1.0 I get "mcp4261 does not name type" error message. I am not sure how to fix it.

Using this page to find my example: http://arduino.cc/playground/Code/Mcp4261
Leads me to this link for the Library and example that I am trying to compile. https://github.com/dreamcat4/Mcp4261

Here is the only message that may be related to my problems:

Quote
Compatibility

This library is broadly compatible with the other devices in this series. They are: Microchip MCP4131, MCP4132, MCP4231, MCP4232, MCP4141, MCP4142, MCP4241, MCP4242, MCP4151, MCP4152, MCP4251, MCP4252, MCP4161, MCP4162, MCP4261, MCP4262. Just adjust these lines in the header file as appropriate

    const static bool         non_volatile    = true;
    const static unsigned int resolution      = resolution_8bit;


  
Code:
// This example demonstrates control over SPI to the Microchip MCP4261 Digital potentometer
// SPI Pinouts are for Arduino Uno and Arduino Duemilanove board (will differ for Arduino MEGA)

// Download these into your Sketches/libraries/ folder...

// The Spi library by Cam Thompson. It was originally part of FPU library (micromegacorp.com)
// Available from http://arduino.cc/playground/Code/Fpu or http://www.arduino.cc/playground/Code/Spi
// Including Spi.h vv below initializea the MOSI, MISO, and SPI_CLK pins as per ATMEGA 328P
#include <Spi.h>

// Mcp4261 library available from https://github.com/dreamcat4/Mcp4261
#include <Mcp4261.h>
#include


// Wire up the SPI Interface common lines:
 #define SPI_CLOCK            13 //arduino   <->   SPI Slave Clock Input     -> SCK (Pin 02 on MCP4261 DIP)
 #define SPI_MOSI             11 //arduino   <->   SPI Master Out Slave In   -> SDI (Pin 03 on MCP4261 DIP)
 #define SPI_MISO             12 //arduino   <->   SPI Master In Slave Out   -> SDO (Pin 13 on MCP4261 DIP)

// Then choose any other free pin as the Slave Select (pin 10 if the default but doesnt have to be)
#define MCP4261_SLAVE_SELECT_PIN 10 //arduino   <->   Chip Select               -> CS  (Pin 01 on MCP4261 DIP)

// Its recommended to measure the rated end-end resistance (terminal A to terminal B)
// Because this can vary by a large margin, up to -+ 20%. And temperature variations.
float rAB_ohms = 5090.00; // 5k Ohm

// Instantiate Mcp4261 object, with default rW (=117.5 ohm, its typical resistance)
MCP4261 Mcp4261 = MCP4261( MCP4261_SLAVE_SELECT_PIN, rAB_ohms );

// rW - Wiper resistance. This is a small additional constant. To measure it
// use the example, setup(). Required for accurate calculations (to nearest ohm)
// Datasheet Page 5, gives typical values MIN=75ohm, MAX @5v=160ohm,@2.7v=300ohm
// Usually rW should be somewhere between 100 and 150 ohms.
// Instantiate Mcp4261 object, after measuring the real rW wiper resistance
// MCP4261 Mcp4261 = MCP4261( MCP4261_SLAVE_SELECT_PIN, rAB_ohms, rW_ohms );

void setup()
{
  // First measure the the wiper resistance, called rW
  Mcp4261.wiper0_pos(0); // rAW = rW_ohms
  Mcp4261.wiper1_pos(0); // rAW = rW_ohms
  delay(5000);
  
  // (optional)
  // Scale to 100.0 for a percentage, or 1.0 for a fraction
  // Eg if scale=100, then wiper(100) = max rAW resistance
  // Eg    scale=1.0, then wiper(1.0) = max rAW resistance
  // Mcp4261.scale = 1.0;

  Mcp4261.scale = 100.0; // For the timeout example, below

  // Mcp4261.wiper0(40); // set pot0 rAW = 40% of max value
  // Mcp4261.wiper1(80); // set pot1 rAW = 80% of max value
  //
  // delay(5000);
  //
  // Mcp4261.wiper0(5);  // set pot0 rAW =  5% of max value
  // Mcp4261.wiper1(50); // set pot1 rAW = 50% of max value

  // Go back to using ohms
  // Mcp4261.scale = Mcp4261.rAB_ohms;
}




// Cycle the wipers around at 20% increments, changing every 2 seconds
long timeoutInterval = 2000;
long previousMillis = 0;
float counter = 0.0;

void timeout()
{
  if(counter > 100.0)
    counter = 0.0;

  // These resistances are just percentages of 100
  Mcp4261.wiper0(counter);
  Mcp4261.wiper1(100 - counter); // Invert the wiper1

  counter += 20.0;
}

void loop()
{
  if (  millis() - previousMillis > timeoutInterval )
  {
    timeout();
    previousMillis = millis();
  }
  // Loop.
}

« Last Edit: February 14, 2012, 10:52:19 pm by cyclegadget » Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using 1.0. Spi.h is now SPI.h, so you need to replace all occurrences of 'Spi' with 'SPI', in the sketch, and also in Mcp4261.cpp in the library folder. After that, the example sketch compiled ok for me.
Logged

Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


  I fixed the problem of " mcp4261 does not name type" . I had my libraries inside of an additional set of folders because I have so many. I took it out of the folder and now I have many other problems.
Same code as above using IDE 23. It is driving me nuts!

Code:
In file included from Mcp4261Example.cpp:12:
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:12: error: expected `)' before 'slave_select'
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:15: error: expected `)' before 'slave_select'
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:63: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:65: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:66: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:68: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:69: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:71: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:72: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:74: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:75: error: 'uint8_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:77: error: 'uint16_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:78: error: 'byte' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:79: error: 'byte' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:81: error: 'uint8_t' has not been declared
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:88: error: 'uint16_t' does not name a type
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:89: error: 'byte' has not been declared
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:89: error: 'byte' has not been declared
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:90: error: 'byte' has not been declared
Mcp4261Example:26: error: no matching function for call to 'MCP4261::MCP4261(int, float&)'
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:9: note: candidates are: MCP4261::MCP4261()
C:\Users\asdf\Documents\arduino-0023\arduino-0023\libraries\Mcp4261/Mcp4261.h:9: note:                 MCP4261::MCP4261(const MCP4261&)
Logged


Greenville, IL
Offline Offline
Edison Member
*
Karma: 15
Posts: 1330
Warning Novice on board! 0 to 1 chance of errors!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


 I found a library that is a modification of the dreamcat library and I have had much better luck with it. My resources are listed in the sketch. This is for my mcp4251 digital pot. It should work for the mcp42xxx family chips.
Here is the source of the library used in this sketch. https://github.com/teabot/McpDigitalPot

Code:
// This example demonstrates control over SPI to the Microchip McpDigitalPot Digital potentometer mcp42xxx family
// SPI Pinouts are for Arduino Uno and Arduino Duemilanove board (will differ for Arduino MEGA)

/*mcp42xxx family
///////////////////////commands from data sheet////////////////
00000000 to write to pot 2
00010000 to write to pot 1 /////////////32?
11 Read Data 16-Bits
00 Write Data 16-Bits
01 Increment 8-Bits
10 Decrement 8-Bits
////////////////////////////Chip pins////////////////////////
1  -CS to DIGITAL PIN 10 (same as latch)
2  -SCK to DIGITAL PIN 13 (clock)
3  -SDI to DIGITAL PIN 11 (data IN)
4  -VSS GROUND
5  -P1B GROUND
6  -P1W (channel 2 wiper)
7  -P1A +5V
8  -P0A +5v
9  -P0W (channel 1 wiper)
10 -P0B GROUND
11 -WP on mine +5v, good luck
12 -SHDN +5v
13 -SDO to DIGITAL PIN 12 (data OUT)
14 -VDD +5v
//////////////////////////////////////////information sources///////////////////////////
Base code and library came from here https://github.com/teabot/McpDigitalPot
http://pdf1.alldatasheet.com/datasheet-pdf/view/306650/MICROCHIP/MCP4251-502E/MS.html
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1269918888/all
*/
#include <SPI.h>

// McpDigitalPot library available from https://github.com/dreamcat4/McpDigitalPot
#include <McpDigitalPot.h>

// Wire up the SPI Interface common lines:
// #define SPI_CS               10 //arduino   <->   SPI Chip Select           -> CS  (Pin 01 on McpDigitalPot DIP)
// #define SPI_CLOCK            13 //arduino   <->   SPI Slave Clock Input     -> SCK (Pin 02 on McpDigitalPot DIP)
// #define SPI_MOSI             11 //arduino   <->   SPI Master Out Slave In   -> SDI (Pin 03 on McpDigitalPot DIP)
// #define SPI_MISO             12 //arduino   <->   SPI Master In Slave Out   -> SDO (Pin 13 on McpDigitalPot DIP)

// Then choose any other free pin as the Slave Select (pin 10 if the default but doesnt have to be)
#define MCP_DIGITAL_POT_SLAVE_SELECT_PIN 10 //arduino   <->   Chip Select               -> CS  (Pin 01 on McpDigitalPot DIP)

// Its recommended to measure the rated end-end resistance (terminal A to terminal B)
// Because this can vary by a large margin, up to -+ 20%. And temperature variations.
float rAB_ohms = 10000.00; // 10k Ohm
float rW_ohms  = 94;       // 94 Ohm
// Instantiate McpDigitalPot object, with default rW (=117.5 ohm, its typical resistance)
//McpDigitalPot digitalPot = McpDigitalPot( MCP_DIGITAL_POT_SLAVE_SELECT_PIN, rAB_ohms );

// rW - Wiper resistance. This is a small additional constant. To measure it
// use the example, setup(). Required for accurate calculations (to nearest ohm)
// Datasheet Page 5, gives typical values MIN=75ohm, MAX @5v=160ohm,@2.7v=300ohm
// Usually rW should be somewhere between 100 and 150 ohms.
// Instantiate McpDigitalPot object, after measuring the real rW wiper resistance
 McpDigitalPot digitalPot = McpDigitalPot( MCP_DIGITAL_POT_SLAVE_SELECT_PIN, rAB_ohms, rW_ohms );

void setup()
{
   Serial.begin(57600);
  // initialize SPI:
  SPI.begin();
 
  // First measure the the wiper resistance, called rW
  digitalPot.setPosition(0, 0); // rAW = rW_ohms
  digitalPot.setPosition(1, 0); // rAW = rW_ohms
  //delay(5000);
 
  // (optional)
  // Scale to 100.0 for a percentage, or 1.0 for a fraction
  // Eg if scale=100, then setResistance(0, 100) = max rAW resistance
  // Eg    scale=1.0, then setResistance(0, 1.0) = max rAW resistance
  // digitalPot.scale = 1.0;

  digitalPot.scale = 100.0; // For the timeout example, below

  // digitalPot.setResistance(0, 40); // set pot0 rAW = 40% of max value
  // digitalPot.setResistance(1, 80); // set pot1 rAW = 80% of max value
  //
  // delay(5000);
  //
  // digitalPot.setResistance(0, 5);  // set pot0 rAW =  5% of max value
  // digitalPot.setResistance(1, 50); // set pot1 rAW = 50% of max value

  // Go back to using ohms
  // digitalPot.scale = McpDigitalPot.rAB_ohms;
}




// Cycle the wipers around at 20% increments, changing every 2 seconds
long timeoutInterval = 200;
long previousMillis = 0;
float counter = 0.0;

void timeout()
{
  if(counter > 100.0)
    counter = 0.0;

  // These resistances are just percentages of 100
  digitalPot.setResistance(0, 100 - counter);
  digitalPot.setResistance(1,  counter); // Invert the wiper1

  counter += 1.0;
}

void loop()
{
   
   
  if (  millis() - previousMillis > timeoutInterval )
  {
    timeout();
    previousMillis = millis();
    Serial.print((counter - 20) * 100);
    Serial.println("ohms");
      }
  // Loop.
}

Logged


Pages: [1]   Go Up
Jump to: