Jump to content
Sign in to follow this  
splanky

Arduino Bridge and missing Rotary Encoder signals

Recommended Posts

I'm using a (genuine) Mega2560 with some dual rotary encoders (the type with the pushbutton center). Some are from Propwash and some are Bourns encoders but they both operate the same way. There are no V+ pins on these dual encoders so, using a simple loop sketch for testing, they're coded with INPUT_PULLUP resistors on the Mega. Every detent generates an output. This works as expected in a loop sketch on the Auduino IDE with output:

Direction: CW -- Value: 0
Direction: CW -- Value: 1
Direction: CW -- Value: 2
Direction: CW -- Value: 3
Direction: CCW -- Value: 2
Direction: CCW -- Value: 1
Direction: CCW -- Value: 0
Direction: CCW -- Value: -1
Direction: CCW -- Value: -2
Direction: CCW -- Value: -3
Direction: CW -- Value: -2
Direction: CW -- Value: -1
Direction: CW -- Value: 0

Whenever I use the Arduino Bridge with Axis and Ohs the encoders are registered during Add Button Assignment for, say, COM radios. The issue is that only every other detent is detected. In other words, it takes a movement of 2 detents to get only one increment of change on the radio frequency. I can see the green indicator flash within the Assgned Buttons list, but again, only every other detent. The detents in between do not light the green indicator.

Behavior is the same when entering the button assignment. A 2 detent movement is required to cause a change in the Assigned button/key area when assigning a new button.

AAO version 2.70 b37
Arduino Bridge version 1.0 b12

I'd appreciate thoughts on how to proceed.

Share this post


Link to post
Share on other sites
1 hour ago, splanky said:

I'd appreciate thoughts on how to proceed.

Sorry, but I see no practical way how I could diagnose or fix behavior like this without having the actual encoders here. It seemed to work fine with the "defaults". 

These Bridge programs are just hobby projects, like it says on the website. I made them to demonstrate how the WebAPI of AAO may be used by other programs. There are definitely better Arduino-to-flightsim solutions out there.


LORBY-SI

Share this post


Link to post
Share on other sites

I see. I'm afraid I've run off and gotten married to AAO with the Honeycomb shortcomings (for which AAO works very well).

3 hours ago, Lorby_SI said:

There are definitely better Arduino-to-flightsim solutions out there.

If there is no user access to your Mega2650 sketch, which I expect is proprietary, and given I want to stick with AAO if possible, would you suggest an alternative for the Arduino that would play nicely with Axis and Ohs (and MSFS 2020)?

Share this post


Link to post
Share on other sites
8 hours ago, splanky said:

I see. I'm afraid I've run off and gotten married to AAO with the Honeycomb shortcomings (for which AAO works very well).

If there is no user access to your Mega2650 sketch, which I expect is proprietary, and given I want to stick with AAO if possible, would you suggest an alternative for the Arduino that would play nicely with Axis and Ohs (and MSFS 2020)?

I'm not really fond of that sketch to be honest. The code has been taken from one of the professional LWR products and there it had kind of a different purpose, so it doesn't really fit the use case (too much data overhead). But that also means that I can't share it, sorry. I always wanted to make a new one, but there just never was time for that.

If you are familiar with sketches, there may be a "native" alternative. You could drop a LAN/WiFi shield on the board and acccess the WebAPI of AAO directly using your local network.

For testing I modified the default example for the Ethernet board. It sends a simple button press and release - full specs for the Web API are in the AAO manual

#include <SPI.h>
#include <Ethernet.h>

// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
IPAddress myDns(192, 168, 0, 1);

// initialize the library instance:
EthernetClient client;
byte server[] = { 192, 168, 178, 41 };

int currentState = 0;
int lastState = -1;

void setup() {
  // You can use Ethernet.init(pin) to configure the CS pin
  //Ethernet.init(10);  // Most Arduino shields
  //Ethernet.init(5);   // MKR ETH shield
  //Ethernet.init(0);   // Teensy 2.0
  //Ethernet.init(20);  // Teensy++ 2.0
  //Ethernet.init(15);  // ESP8266 with Adafruit Featherwing Ethernet
  //Ethernet.init(33);  // ESP32 with Adafruit Featherwing Ethernet
  // start serial port:

  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  Serial.println("Initialize Ethernet with DHCP:");
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware) {
      Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
      while (true) {
        delay(1); // do nothing, no point running without Ethernet hardware
      }
    }
    if (Ethernet.linkStatus() == LinkOFF) {
      Serial.println("Ethernet cable is not connected.");
    }
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip, myDns);
    Serial.print("My IP address: ");
    Serial.println(Ethernet.localIP());
  } else {
    Serial.print("  DHCP assigned IP ");
    Serial.println(Ethernet.localIP());
  }

  // give the Ethernet shield a second to initialize:
  delay(10000);

  // initialize the buttons
  pinMode(51, INPUT_PULLUP);
}

void loop() {

  currentState = digitalRead(51);
  if(lastState != currentState){
    if (currentState == HIGH){
        httpRequest(127);   
    }
    else{
        httpRequest(0);   
    }
   lastState = currentState; 
  }
}

// this method makes a HTTP connection to the server:
void httpRequest(int state) {
  // close any connection before send a new request.
  // This will free the socket on the WiFi shield
  client.stop();
  // if there's a successful connection:
  if (client.connect(server, 6080)) {
    String queryString = String("?dev=101&chn=1&btn=5&bval=") + String(state);
    client.println("GET /webapi" + queryString + " HTTP/1.1");
    client.println("Host: 192.168.178.41");
    client.println("User-Agent: arduino-ethernet");
    client.println("Connection: close");
    client.println();
  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
  }
}

 

Edited by Lorby_SI

LORBY-SI

Share this post


Link to post
Share on other sites
22 hours ago, Lorby_SI said:

You could drop a LAN/WiFi shield on the board and acccess the WebAPI of AAO directly

I saw that the other day when searching for answers in another thread here. Since the arduino is on the simulator machine's USB I won't be buying add'l hardware simply for a network connection.

Also, figuring out appropriate code is, for me, a time consuming task since I don't write html, so I'm better off throwing a little money at another software solution. Will see what's available in the morning,

Again, thanks for your suggestions.

Share this post


Link to post
Share on other sites

It jumps outside of AAO but Mobiflight is another solution since it focuses on the home cockpit crowd, it's pretty straight forward with an active Discord

  • Like 1

WW5130.png

| i9-10900F - 2080Ti | 32 GB RAM | Win 11 Pro | HC Bravo | AAO | StreamDeck | Air Manager |

Share this post


Link to post
Share on other sites
On 12/8/2022 at 2:46 PM, mrm0508 said:

... is another solution

Thanks, Mike. I've found a solution using another competitor, spad.next, which interfaces well with the Aruduino Mega2560 I'd already built out.

Share this post


Link to post
Share on other sites
7 hours ago, splanky said:

If you decide, at some time, to revisit your Arduino Bridge, this may be of help.

Actually, my sketch does the same thing. But at some point I disabled the quater step branch since we were only using the full step kind of encoders. Problem is, that even when I expand this to reactivate it, I don't have the encoders that work this way to test it. Which ones did you buy exactly?

[snip]

Edit: OK, so I did this "in the blind" and reactivated the code. In the new version 1.01 of the Arduino Bridge you have the option to select Full-Half-Quarter Steps for a rotary encoder. I've tested it with my encoders, and when changing this setting I get either 1, 2 or 4 distinct events for each "click". Since I have no other hardware to test this with, it is probably "hit or miss" if it works as intended in a specific use case.

Edited by Lorby_SI

LORBY-SI

Share this post


Link to post
Share on other sites
9 hours ago, Lorby_SI said:

Which ones did you buy exactly?

This is the rotary encoder that's part of the popular Propwash kit:

http://ljvraphael.blogspot.com/2016/08/ljv-dual-shaft-rotary-encoder-re08223ax.html

https://www.propwashsim.com/store/dual-encoder-kit

This are a nice kit because it contains the LJV rotary encoder, PCB, inner and outer knobs, and header pins.

For half the money, one can buy a similar half step Bourns dual concentric rotary encoder with pushbutton switch from Digi-Key. These, however, require one to figure out a mounting solution, 3d print their own knobs and fiddle with wiring from the data sheet vs having a premade/labeled PCB. Still, they're a perfectly workable product with a gentle switching feel, lighter than the LJV. The LJV, however, is more similar in feel to, say, a real Garmin G1000 flight panel.

https://www.bourns.com/docs/product-datasheets/pec11d.pdf

The takeaway from a simple test of your update is that both of these dual encoders work properly using the Half-Step option as configurable in your 'hobby project'. 😉

Congrats. The Arduino DIY crowd, tiny as it likely is, will find this helpful in opening up simple to use possibilities for AAO.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...