PCB v2 encoder function. autosteer code editing

Hi, I need help changing the arduino udp code. I am installing agopen gps hydraulic valves. I have a NO pressure switch. I connect the sensor to the “remote” input (pcb v2). I turn on the turn sensor and set the value to 1. Turning off is not working properly. When I had the NC pressure switch everything worked as it should. What should I change in the autosteer code so that when the pressure switch contacts are closed, the steering will be disconnected?

if (encEnable)
{
  thisEnc = digitalRead(REMOTE_PIN);
  if (thisEnc != lastEnc)
  {
    lastEnc = thisEnc;
    if ( lastEnc) EncoderFunc();
  }
}

} // end of main loop

//ISR Steering Wheel Encoder
void EncoderFunc()
{
if (encEnable)
{
pulseCount++;
encEnable = false;
}
}

I didn’t understand well, but i think the part of code you are looking for is that:

else if (steerConfig.SteerButton == 1)    //steer Button momentary
      {
        reading = digitalRead(STEERSW_PIN);      
        if (reading == LOW && previous == HIGH) 
        {
          if (currentState == 1)
          {
            currentState = 0;
            steerSwitch = 0;
          }
          else
          {
            currentState = 1;
            steerSwitch = 1;
          }
        }      
        previous = reading;
      }

You shouldn’t need to change the code. It’s looking for a state change, and having the pressure sensor as an encoder you are just telling it to turn off auto steer at the first change in state it sees. Check in AgIO that the encoder(switch) is functioning as it should. If you expand the the screen there should be spot where you can see if your switches are toggling like they should.

Have you changed the pressure switch or is this a new installation?

You are correct, it will only count the closed-open option.

So you have two ways to fix your problem the first is below. Notice the ! In the last line, this will make it only count the movement from open-closed.


if (encEnable)
{
  thisEnc = digitalRead(REMOTE_PIN);
  if (thisEnc != lastEnc)
  {
    lastEnc = thisEnc;
    if ( !lastEnc) EncoderFunc();
  }
}

Maybe a better option is to read the remote pin and just force autosteer off till the next button press, if you wanted help to make that small change just ask otherwise try adding that ! as shown above

1 Like

Quite right. Difference between a 1 and a 0.

Baraki had posted once that we should just set aog to 0 in count. No need to change ino.
0 is possible, in versions after 5.6.2 (maybe a little earlier, but not 5.4.5)

In the Teensy code I’m using, just set AGOPEN to 0 and it works fine. If you do not want to change the code, just pull up the remote output to GND, e.g. with a 1K resistor, and connect +5/12v to the pressure switch and it will work with the counter set to 1.

Here is the encoder code I use on teensy
// encoder
if (steerConfig.ShaftEncoder)
{
PulseRead = digitalRead(Encoder_Pin);
if ((PulseRead != PulseLast) && (millis() - PulseStart > SWdebounce))
{
PulseStart = millis();
PulseLast = PulseRead;
SwitchPulseCount++;

		if (SwitchPulseCount >= steerConfig.PulseCountMax)
		{
			SteerSwitch = HIGH;
			switchByte = SteerSwitch << 1;
			SWprevious = HIGH;
			SwitchPulseCount = 0;
			Latched = true;
		}
	}
}

Thank you. Your help solved my problem

Hello,

If i see it right then the sensor closes and opens and that is 1 count or am i wrong? We have trouble with how baraki sensor is working. We want just like Current or pressure sensor. We now need to wiggle the wheel to disengage. I have put the ! in the code but its still not as we want.

What did you mean by “Maybe a better option is to read the remote pin and just force autosteer off till the next button press”

Thnx in advance

You are right, so use the other side of the pressure switch.
Connect so when in autosteer the switch is closed, (half way through the cycle) when steering wheel is turned by hand the switch open, and you have a full 1 count

Any change to make it that it only see close or open then disengage. Like reading remotepin and see if something comes in then disengage.

I think now it comes in and when input drops it reacts.

Can i do something like below?

if (encEnable)
{
thisEnc = digitalRead(REMOTE_PIN);

  if (thisEnc == LOW && previous == HIGH)
  {
    if (currentState == 1)
    {
      currentState = 0;
    RemotePin = 0;
    }
    else
    {
      currentState = 1;
     RemotePin = 1;
    }
  }
  previous = thisEnc;
}

}

Probally not right coding. but not behind pc now