alexandros
Well-known member
I'm trying to read four soft pots like this one (https://grobotronics.com/softpot-membrane-potentiometer-200mm.html) with a Teensy 3.6 but I can't get it to work properly.
Here's the code:
When I open the serial monitor I get some readings and then nothing at all. When I use the same code and circuit with an Arduino UNO, it works properly, printing values to the serial monitor when I change my finger position on the soft pot (ribon). But with a Teensy 3.6 or LC it doesn't seem to work. Additionally, with I try to upload the code to any Teensy board, initially the upload process takes some time and when Teensyduino is launched and uploads the code, I get an upload error message in the Arduino IDE, but I can still open the serial monitor. Once I close the serial monitor (which hangs for a couple of minutes before it closes) and upload the code again, it uploads fine without any error messages in the Arduino IDE.
Here's a Fritzing image of the circuit with normal pots instead of soft pots, cause my Fritzing installation doesn't have a soft pot part.
Any ideas why this works with Arduino but not with Teensy?
Here's the code:
Code:
#define RIBDELTA 3
const int ribons = 4;
int ribonPins[ribons] = { 2, 3, 6, 7 };
int ribVals[ribons] = { 0 };
int curVals[ribons] = { 0 };
bool extremeValSent[ribons] = { false };
const int floorVal = 5;
const int ceilVal = 1005;
void setup() {
Serial.begin(9600);
}
void loop() {
for (int i = 0; i < ribons; i++) {
curVals[i] = analogRead(ribonPins[i]);
curVals[i] = constrain(curVals[i], floorVal, ceilVal);
curVals[i] = map(curVals[i], floorVal, ceilVal, 0, 1000);
if (abs(curVals[i] - ribVals[i]) > RIBDELTA) {
ribVals[i] = curVals[i];
Serial.print("Ribon "); Serial.print(i);
Serial.print(": "); Serial.println(ribVals[i]);
if ((ribVals[i] == 0) || (ribVals[i] == 1000)) {
extremeValSent[i] = true;
}
else {
extremeValSent[i] = false;
}
}
if ((ribVals[i] == 0) || (ribVals[i] == 1000)) {
if (!extremeValSent[i]) {
ribVals[i] = curVals[i];
Serial.print("Ribon "); Serial.print(i);
Serial.print(": "); Serial.println(ribVals[i]);
extremeValSent[i] = true;
}
}
}
}
Here's a Fritzing image of the circuit with normal pots instead of soft pots, cause my Fritzing installation doesn't have a soft pot part.
Any ideas why this works with Arduino but not with Teensy?