Go Down

Topic: MCP41010 Potentiometer connection with Arduino Leonardo? (Read 2 times) previous topic - next topic

thlpap

Good evening,

I have a project where I have to connect a Digital potentiometer mcp41010 with an arduino leonardo in order to control the volume of a buzzer.
The problem is that i can't find somewere on the internet an image that shows how to connect these two.
I have only found images that connect mcp41010 with different arduinos like UNO for example.
I suppose that there are differences between arduino leonadro and UNO, thus the connection should be different.

Does anyone know which pins of the pottentiometer should be connected with which, on arduino Leonardo?
I also attach an image of this potentiometer connected with an arduino UNO (i think..)

Thanks in advanve!

Aeryck

First of all, the image you posted does not correspond with the the pot you're using. I pulled this image off the forum with the correct one (mcp41010 instead of mcp41100). Not sure if there is a difference, but just to be sure.


As long as you connect the wires that are displayed as connected to digital PWM ports correctly (to PWM ports), you should be fine. I don't see why there should be a big difference between wiring to the Leonardo or to the Uno.

Hackscribble

#2
May 27, 2014, 03:52 pm Last Edit: May 27, 2014, 03:57 pm by Hackscribble Reason: 1
Hello thlpap

The MCP41010 uses SPI bus to connect to Arduino (according to its datasheet).

On the Uno, the SPI pins are where the connections are in the image posted by Aeryck.

However, the following is from the Leonardo page on this website.

Quote
SPI: on the ICSP header. These pins support SPI communication using the SPI library. Note that the SPI pins are not connected to any of the digital I/O pins as they are on the Uno, They are only available on the ICSP connector. This means that if you have a shield that uses SPI, but does NOT have a 6-pin ICSP connector that connects to the Leonardo's 6-pin ICSP header, the shield will not work.


So I think you will have to move the connections onto the ICSP header for them to work.

EDIT:  This has details of Leonardo ICSP header and SPI pins.

http://www.instructables.com/id/Step-by-Step-Guide-to-the-Arduino-Leonardo/


Regards

Ray
Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

thlpap

Thank you very much for your replies!

What i do not understand though, is WHICH pins of the MCP41010 should I connect with WHICH ports of the arduino, or the ICSP header.
The only pin of the ICSP header that matches the MCP41010 (as I can see from the datasheet, and the site you have sent me) is the SCK.

As you can see from the image below (from the MCP41010 datasheet), there remain 7 pins to be connected. CS, SI, Vss, Vdd, PB0, PW0 and PA0.

Should I connect them like the image that Aeryck posted?
Should I connect some of them like that, and some other to the ICSP header?
If this is the case, which of them, to where?

I am sorry but I am a newbie in the Arduino world :)

Thanks again for any reply!

Hackscribble

#4
May 28, 2014, 01:16 am Last Edit: May 28, 2014, 01:25 am by Hackscribble Reason: 1
Hi

From the datasheet, the 41010 can work on a +5V supply.  So connect Vdd to +5V on Arduino, and connect Vss to GND on Arduino.

PA0, PB0 and PW0 are the potentiometer connections, so they need to connect to the circuit you want to control.

SCK connects to SCK on the ICSP header.  SI is short for MOSI (master out - slave in), so it connects to MOSI on the ISP header.

Connect CS (chip select) to a digital pin on the Leonardo, for example pin 10. Your program will need to control this pin, rather than the default SS (slave select) pin.

Do you have a program to control the 41010?  If so, please post it.

Regards

Ray


Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

thlpap

Thanks again SO much for your answer. I have put the connections like you told me and I think it works!

To put you in context of what is the project, it goes like this:
I connect a buzzer and an electret microphone to an Arduino Leonardo. I want to control the volume of the buzzer, depending on the values that the microphone gives. For example, the value of the mirophone stays at 109-110 units. If it goes beyond a threshold of 4-5 units (meaning less than 105 and more than 113), I want to lower the volume of the buzzer.
Its like when you listen to some music from the PC, and someone from Skype video calls you, the volume of the music instantlly lowers.

Now the initial problem was that i couldnt control at the same time the buzzers volume, and the electrets analog input, but I solved it with the Tone library since it has a non-blocking play() command with which I can make the buzzer playing a tone, and go to the next command, without the tone being stoped!

Now the problem that I have with the code, (and if i solve this I think the project will be finished :) ) is that I havent managed yet to lower the volume for some duration, and not permanently, if a louder sound is read by the microphone.

This is the code :

Code: [Select]
#include <Tone.h>
#include <SPI.h>

const int slaveSelectPin = 10;
Tone tone1;

int sensorPin = A0;    // select the input pin for the potentiometer
int sensorValue = 0;  // variable to store the value coming from the sensor
int level = 100;

void setup() {

  Serial.begin(9600);
  tone1.begin(13);
  tone1.play(NOTE_B3);
  pinMode (slaveSelectPin, OUTPUT);
  SPI.begin();
}



void loop() {

  digitalPotWrite(level);
  sensorValue = analogRead(sensorPin);
  Serial.print("sensor = " );                       
  Serial.println(sensorValue);
  delay(500);

  if (sensorValue > 113 || sensorValue < 105)
  {
    level = 50;
   
  }


}

int digitalPotWrite(int value)
{
  digitalWrite(slaveSelectPin, LOW);
  SPI.transfer(0x11);
  SPI.transfer(value);
  digitalWrite(slaveSelectPin, HIGH);
}



Thanks again, and if you have any idea about the duration problem let me know!
Cheers

Hackscribble

Hi there

Good to hear you have got it working :)

In your code, level is set to 100 when the program begins.  Then you have the following if statement where you set it to something different:

Code: [Select]
  if (sensorValue > 113 || sensorValue < 105)
  {
    level = 50;
  }


There is no code to set it back to 100.  You could add an else statement to the above and set level to 100 again.

Code: [Select]
if (sensorValue > 113 || sensorValue < 105)
{
    level = 50;
}
else
{
    level = 100;
}


BUT ... I'm not sure how this will work in practice.  Are you connecting JUST an electret microphone to the analog pin, or is it some kind of sound module that processes the sounds picked up and converts them to an average loudness signal? 

A microphone will give an output that varies thousands of times a second, so reading it every 0.5 seconds will give readings that look random.

Anyway, can you post a diagram of the circuit you are connecting to the analog pin.

Regards

Ray

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

thlpap

Oh you are right, I pasted the older version of the code. I had put another if command like this:

Code: [Select]
if (sensorValue > 113 || sensorValue < 105)
  {
    level = 50;

  }


To do the opposite but it didn't work.

With the "else" command that you mentioned it works! But it lowers the volume of the buzzer only for a duration of 500ms (which is determined by the delay(500) command)

Is there anyway to extend the period of time that the volume is lowered?
What i mean is that, if for example I shout to the microphone, and I get a value of 115 , so it exceeds the threshold, I want to lower the volume for three seconds, and then check again from the electret mic, if the analog input is within the threshold.

I tried to put a delay(3000) command into the if, but the result was that the rate of the analog print, paused for 3 seconds, and then the volume lowered to 50 units for 500ms (the value that was on the first delay), so this doesnt work!

In the following image is the way I have connected the electret mic to the Arduino:

Hackscribble

I don't think connecting just the electret microphone on its own to the Arduino will work the way you want it to. 

The microphone converts the sound it picks up to an alternating voltage.  BUT ... the changes in voltage are very low and the signal varies constantly, so you will get misleading readings if you just analogRead every 0.5 seconds. 

There is information on this link which could be useful background.  There is a graph of an audio signal which shows better than my words above what is happening.

http://electronics.stackexchange.com/questions/57824/how-do-i-get-5v-for-loud-noise-0v-for-silence-from-electret-microphone-or-oth

And if you search this website and google "arduino loudness measure", there may be other resources.

Regards

Ray

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com


Go Up