I want to replace a mechanical Potentiometer in a remote control for electric skateboard with Arduino controlled digital Pot. It had mechanical Potentiometer B103, I replaced it with digital pot MCP41010 but it doesn't work. There is a scheme and a code how I connected it to Arduino and to wires from mechanical Potentiometer. I'll appreciate any ideas.
#include <SPI.h>
const int CS = 9;
void setup() {
pinMode (CS, OUTPUT);
SPI.begin();
}
void loop() {
MCP41010Write(100);
delay(100);
}
void MCP41010Write(byte value)
{
digitalWrite(CS,LOW);
SPI.transfer(B00010001); // This tells the chip to set the pot
SPI.transfer(value); // This tells it the pot position
digitalWrite(CS,HIGH);
}
"It doesn't work" is almost enough to make me go on to the next post, where the poster just might actually explain what the code does, what he/she expects, and how he/she has determined that the correct output is not being obtained.
PaulS:
"It doesn't work" is almost enough to make me go on to the next post, where the poster just might actually explain what the code does, what he/she expects, and how he/she has determined that the correct output is not being obtained.
I'm sorry for this, but I don't know how to explain it. The electric skateboard moves when I use the mechanical pot in the remote control and doesn't do any attempt to move when I use the digital pot.
What is interesting. If connect the wiper to A1 on arduino for see voltage on Serial Monitor I put this code
/*MCP41010 Tutorial*/
#include <SPI.h>
const int CS = 9;
int PotWiperVoltage = 1;
int RawVoltage = 0;
float Voltage = 0;
void setup() {
pinMode (CS, OUTPUT);
Serial.begin(9600);
SPI.begin();
}
void loop() {
// move the potentiometer in one direction
for (int level = 0; level < 255; level++)
{
MCP41010Write(level);
delay(100);
RawVoltage = analogRead(PotWiperVoltage);
Voltage = (RawVoltage * 5.0 )/ 1024.0;
Serial.print("Level = " );
Serial.print(level);
Serial.print("\t Voltage = ");
Serial.println(Voltage,3);
}
delay(2000); // wait a couple seconds
// Now mover potentiometer in other directions
for (int level = 255; level > 0; level--)
{
MCP41010Write(level);
delay(100);
RawVoltage = analogRead(PotWiperVoltage);
Voltage = (RawVoltage * 5.0 )/ 1024.0;
Serial.print("Level = " );
Serial.print(level);
Serial.print("\t Voltage = ");
Serial.println(Voltage,3);
}
delay(2000);
}
void MCP41010Write(byte value)
{
// Note that the integer vale passed to this subroutine
// is cast to a byte
digitalWrite(CS,LOW);
SPI.transfer(B00010001); // This tells the chip to set the pot
SPI.transfer(value); // This tells it the pot position
digitalWrite(CS,HIGH);
}
I see this:
Level = 1 Voltage = 1.187
Level = 2 Voltage = 1.211
Level = 3 Voltage = 1.309
Level = 4 Voltage = 1.948
Level = 5 Voltage = 3.408
Level = 6 Voltage = 3.936
Level = 7 Voltage = 3.940
...
So I guess the wiper got some voltage but remote control doesn't send a signal to skateboard to move.
PaulS:
We'll need to see a full schematic showing how you have connect the chip to the Arduino and to the motor and power supply.
We'll also need a link to the data sheet for the chip.
data sheet for the chip http://ww1.microchip.com/downloads/en/DeviceDoc/11195c.pdf
Chip connected to the Arduino as on my pic in the first post. It doesn't connected to motor. I try to control a remote of the skateboard. The power supply of the remote is 3.7V, on Pot wires goes 3V, on wiper in the midle position 1.5V