Motorized Rotary Potentiometer Serial.read max/MSP

I am attempting to create a motorized rotary potentiometer connected to max/MSP for recall of parameters. I have gotten one potentiometer to work, but when I try it with two one of the pots controls the other. Max is not reading the information for both Voltages separately. Attached are my patches and circuit.
The Alps pot pins are labeled, left to right: Dummy|A-read|GND|5v|A-read|GND|5v|Dummy
Here is a video showing how it works.
Here is the Max/MSP patch:
MAX/MSP Patch

and here is the code for one potentiometer:

    const int servoPos=7;
    const int servoNeg=8;
     
    float potVolt = A1;
     
    void setup(){
      Serial.begin(9600);
      pinMode(servoPos, OUTPUT);
      pinMode(servoNeg, OUTPUT);
    }
     
    void loop(){
      byte positive;
      float potVolt = analogRead(A1)/ 4;
     
        if (Serial.available()) {
         positive = Serial.read();
                    //threshold of +/- 1.5 so pot doesn't bounce around
          if (potVolt > (positive + 1.5)) {
          digitalWrite(servoPos, LOW);
          digitalWrite(servoNeg, HIGH);
        }
        else if (potVolt < (positive - 1.5)) {
          digitalWrite(servoPos, HIGH);
          digitalWrite(servoNeg, LOW);
        }
              if (potVolt == positive) {
          digitalWrite(servoNeg, LOW);
          digitalWrite(servoPos, LOW);
        }    
        }
     
      Serial.print(positive);
      Serial.print(" ");
      Serial.println(potVolt);  
     
    }

Attached here is the code for ONE POT and TWO POTS that I attempted as well.

The ONE POT (POTS_SERIAL.ino) works. 2alps_serial.ino doesn't.

POTS_SERIAL.ino (745 Bytes)

_2alps_serial.ino (1.36 KB)

How are you sending the values to the Arduino? I suspect everytime you send a value it is going into the variable pot1.

You almost certainly need a more sophisticated system for receiving data. Either ALWAYS send two bytes at a time OR have some system to tell the Arduino which variable the byte is intended for.

Also you use if Serial.available() which only guarantees the availability of 1 byte even though you REQUIRE two bytes.

Put in some Serial.print() statements so you can see how your program is actually working.

...R

Hi, I am sorry but I have no idea what your fizzing diagram is showing, that is the geared thing that the two arduino outputs 7 and 8 go to?
What is the knob representing and what area all the red and black wires doing?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?
But not a fitzle diagram.
Show how it is powered and all your connections, if you are serious about this project, then a circuit diagram is essential when it comes to seeking help as well as helping yourself.

Tom...... :slight_smile:

The Alps potentiometers have the motor built into it already. I just used 123dcircuits.com to create the diagram, and they didn't have a pot coupled with a motor so I just placed them both in independently. 7 and 8 are what turn the motor either clockwise or counter clockwise. If my voltage is read as a number lower than what my input (in max/msp) is, then the pot will turn up, causing the voltage to rise and (reading it in max/msp) shut off the motor once the voltage matches my integer.
I stated in the OP,
The Alps pot pins are labeled, left to right: Dummy|A-read|GND|5v|A-read|GND|5v|Dummy

Robin2:
How are you sending the values to the Arduino? I suspect everytime you send a value it is going into the variable pot1.

I'm using the serial between Max/MSP and Arduino. When I look at the Serial Monitor in the IDE it reads both of the voltages and continually scrolls, so I know it's sending two, but in max/MSP it's only receiving the voltages in one of the integer objects, and interpolating between them.

I know nothing about Max/msp - sorry.

...R

Hi, like I said, circuit diagram would have explained all that, thankyou.
How are you powering the ALP?
Please proper circuit diag.

Tom..... :slight_smile:

Tom,
I don't know how to make a circuit diagram, I'm new to this. I'm plugging the arduino into the computer via usb... the diagram I made shows the positive pins connected to the 5v pin. Again, the serial monitor is reading the voltages separately, it's not sending to max properly though. Everything on the hardware side is connected properly and runs fine. The issue is when I use the code for two pots, max is reading them on only one integer object.

This is my first post on here so I'm sorry if I'm a little unorganized, and I'm just a noob with Arduino and Max. Thanks for the help though, I appreciate everything!

The problem here is not many people have MAX due to its cost, I know that is why I don't have it at the moment. So can you post a screen dump of your patch so we can see how you are distinguishing between the two values you are sending.

Hi Mike, here is a screenshot of my max patch.

The code that is in my OP is for one pot, but the code for two pots is in the attachments. Here is that code though, if you want to read it on here.

const int servoPos1=2;
const int servoNeg1=3;
const int servoPos2=7;
const int servoNeg2=8;
byte pot1,pot2;

float potVolt1 = A5;
float potVolt2 = A1;

void setup(){
  Serial.begin(9600);
  pinMode(servoPos1, OUTPUT);
  pinMode(servoNeg1, OUTPUT);
  pinMode(servoPos2, OUTPUT);
  pinMode(servoNeg2, OUTPUT);
}

void loop(){

  float potVolt1 = analogRead(A1)/ 4;
  float potVolt2 = analogRead(A5)/ 4;
  
    while (Serial.available()) {
     pot1 = Serial.read();
     pot2 = Serial.read();
     
      if (pot1 > (potVolt1 + 1.5)) {
      digitalWrite(servoPos1, LOW);
      digitalWrite(servoNeg1, HIGH);
    }
    else if (pot1 < (potVolt1 - 1.5)) {
      digitalWrite(servoPos1, HIGH);
      digitalWrite(servoNeg1, LOW);
    }
          if (pot1 == potVolt1) {
      digitalWrite(servoNeg1, LOW);
      digitalWrite(servoPos1, LOW);
    }    
    
    
          if (pot2 > (potVolt2 + 1.5)) {
      digitalWrite(servoPos2, LOW);
      digitalWrite(servoNeg2, HIGH);
    }
    else if (pot2 < (potVolt2 - 1.5)) {
      digitalWrite(servoPos2, HIGH);
      digitalWrite(servoNeg2, LOW);
    }
          if (pot2 == potVolt2) {
      digitalWrite(servoNeg2, LOW);
      digitalWrite(servoPos2, LOW);
    }    
    
    }
  
  Serial.print(pot1);
  Serial.print(" ");
  Serial.println(potVolt1);  

  Serial.print(pot2);
  Serial.print(" ");
  Serial.println(potVolt2);  

}

Classic error:-

while (Serial.available()) {
     pot1 = Serial.read();
     pot2 = Serial.read();

So you are saying if one byte is available then read two bytes.

It should be:-

while (Serial.available() > 1) {
     pot1 = Serial.read();
     pot2 = Serial.read();

So that only when at least two bytes are available you read two bytes.

I haven't looked at the rest of it but fix that and see if it changes the behavior.

Grumpy_Mike,

That worked in allowing max to read both of the voltages separately!! Thanks. Now I have to figure out how to send the data back to the arduino as multiple integers because it's now reading the feedback data as an interpolating integer >.<

thanks a bunch for the help though!