Totally understood. Sorry for not being more specific... I'm using an Arduino UNO Rev. 3 I've attached all the info I have on the mc-2100.
Below are two sketches.
Both I get power/ground from the mc2100:
- power from the mc2100 (say it should be 9VDC but more like 12VDC) by connecting RED to Vin
- grounding using the mc2100 ground by connecting BLACK to GND (just above Vin)
For incline I'm using the following setup:
- 22K resistor between VIOLET (incline sensor signal from mc2100) and pin 2
- sending 5VDC to the mc2100 to trigger incline/decline through pins 10/11 down wires ORANGE/YELLOW
I can count the pulses and seem to be getting a fairly accurate reading where 5 pulses = 1 deg of incline. The only issue I have is figuring out the current incline as the sense signal only seems to cover define the current distance being moved. As of now, I think I just need to store the position or always zero out the incline on shutdown.
The second, reading the speed, is where I have some problems.
- The GREEN speed sense from the controller connected to pin 3.
- The BLUE wire connected to pin 9 and I'm using Timer 1 to set the PWM.
Here I can control the power but have no clue how to read the current speed.
Treadmill incline sketch
// treadmill incline
const int sensorPin = 2;
const int sensorInterruptPin = 0;
const int elevatUp = 10;
const int elevatDn = 11;
const int timeoutValue = 5;
volatile unsigned long lastPulseTime;
volatile unsigned long interval = 0;
volatile int timeoutCounter;
volatile int pulseCount;
volatile int currentPosition = 7;
const int maxPosition = 50;
int inclineCommand = 0;
boolean newCommand = false;
void setup(){
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pinMode(elevatUp, OUTPUT);
pinMode(elevatDn, OUTPUT);
digitalWrite(elevatUp, LOW);
digitalWrite(elevatDn, LOW);
attachInterrupt(sensorInterruptPin, sensorInterrupt, RISING);
Serial.begin(9600);
lastPulseTime = micros();
timeoutCounter = 0;
pulseCount = 0;
}
void sensorInterrupt(){
unsigned long now = micros();
interval = now - lastPulseTime;
lastPulseTime = now;
timeoutCounter = timeoutValue;
pulseCount = pulseCount + 1;
currentPosition = currentPosition + inclineCommand;
reachedFinish();
}
boolean reachedFinish(){
if(currentPosition == 0 || currentPosition == maxPosition){
inclineCommand = 0;
inclineStop();
if(currentPosition == maxPosition){
Serial.println(" -- Now in Max position");
} else {
Serial.println(" -- Now in Min position");
}
return true;
} else {
return false;
}
}
void inclineStop(){
digitalWrite(elevatUp, LOW);
digitalWrite(elevatDn, LOW);
Serial.println("Stop");
pulseCount = 0;
}
void inclineDecrease(){
if(currentPosition - 1 > 0){
inclineStop();
digitalWrite(elevatDn, HIGH);
Serial.println("Decrease");
} else {
reachedFinish();
}
}
void inclineIncrease(){
if(currentPosition + 1 < maxPosition){
inclineStop();
digitalWrite(elevatUp, HIGH);
Serial.println("Increase");
} else {
reachedFinish();
}
}
void loop(){
if(newCommand){
newCommand = false;
switch (inclineCommand) {
case 1:
inclineIncrease();
break;
case -1:
inclineDecrease();
break;
default:
inclineStop();
break;
}
}
if (timeoutCounter != 0){
--timeoutCounter;
Serial.println("Interval: "+(String)interval);
Serial.println("Pulses: "+(String)pulseCount);
Serial.println("Current position: "+(String)currentPosition);
Serial.println("Incline direction: "+(String)inclineCommand);
}
delay(500);
}
void serialEvent() {
String content = "";
char character;
while(Serial.available()) {
character = Serial.read();
content.concat(character);
}
if (content != "") {
inclineCommand = content.toInt();
newCommand = true;
}
}
Treadmill speed sketch
#include <TimerOne.h>
const int speedPin = 9;
const int maxDuty = 870;
const int minDuty = 164;
const int stpDuty = 0;
const int mphIntervals = 71; // guessing here
const int sensorPin = 3;
const int sensorInterruptNum = 1;
const int timeoutValue = 5;
/* variable delcorations and defaults - start */
int currentSpeed = 0;
float speedSetTo = 0;
volatile unsigned long lastPulseTime;
volatile unsigned long interval = 0;
volatile int timeoutCounter;
volatile int pulseCount;
int currentCommand = 0;
int inputCommand = 0;
boolean newCommand = false;
void setup(){
Timer1.initialize(50000); // initialize timer1, and set a 1/2 second period
Timer1.pwm(speedPin, 0); // max 870 (85%)
Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
attachInterrupt(sensorInterruptNum, sensorInterrupt, RISING);
Serial.begin(9600);
lastPulseTime = micros();
timeoutCounter = 0;
}
void callback(){
if(newCommand){
currentCommand = inputCommand;
newCommand = false;
if(currentCommand <= maxDuty){
switch(currentCommand){
case maxDuty:
speedSetTo = maxDuty;
break;
case 0:
speedSetTo = stpDuty;
break;
default:
// float newSpeed = currentCommand;
speedSetTo = currentCommand;
break;
}
Timer1.setPwmDuty(speedPin, speedSetTo);
}
Serial.print("Change speed to: ");
Serial.println(speedSetTo);
Serial.println((float)interval);
}
}
void sensorInterrupt(){
unsigned long now = micros();
interval = now - lastPulseTime;
lastPulseTime = now;
timeoutCounter = timeoutValue;
pulseCount = pulseCount + 1;
}
void loop(){
if (timeoutCounter != 0){
--timeoutCounter;
Serial.println((float)interval);
}
delay(500);
}
void serialEvent() {
String content = "";
char character;
while(Serial.available()) {
character = Serial.read();
content.concat(character);
}
if (content != "") {
inputCommand = content.toInt();
newCommand = true;
}
}
[modified: attached PDFs to original post: Controller Manual and possible Reverse Engineered schematic of mc-2100]