Welcome to Cockpitbuilders.com. Please login or sign up.

March 28, 2024, 01:29:34 PM

Login with username, password and session length

PROUDLY ENDORSING


Fly Elise-ng
110 Guests, 0 Users
Members
Stats
  • Total Posts: 59,639
  • Total Topics: 7,853
  • Online today: 142
  • Online ever: 582
  • (January 22, 2020, 08:44:01 AM)
Users Online
Users: 0
Guests: 110
Total: 110

COUNTDOWN TO WF2022


WORLDFLIGHT TEAM USA

Will Depart in...

Recent

Welcome

A320 Motorized Trim and arduino

Started by iwik, September 19, 2023, 02:56:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

iwik

Need some help with this setup.Took the design off the net but the operation isnt as expected.The problem is that it starts but want to pause then start agin a couple of times then it will run till it matches the trim in MSFS.
It uses a stepper,there is no binding.
It has a Arduino sketch and a Python script to i/f it to Fsim.
I have attached the two files and hope someone can help.Tried to contact the developer but no luck.
Thanks
Les

ame

Well, it's certainly poorly documented code. Can you post a link to where you got it from?

Does it have an input and an output function in your specific setup? i.e. is the Arduino driving the stepper motor (output) and collecting data from some other attached hardware (input).

Have you actually built the hardware (so you can observe the conditions you mentioned), or have you only got the software set up and you are just observing messages going to and from the various parts (flight sim, Python script, Arduino code)?

iwik

Thanks ame for replying.
Let  me better explain what i have.
The stepper motor (Nema 17 42-34) driven from a A4988 module which in turn is controlled by a Arduino Pro Micro.
I bought the files from Cults3d site and all got was the stl files,Sketch and Python script.No instructions so had to trawl the net to find out how to run the script.I dont know anything about Arduino programimg or Python,i was expecting better docs.
I think the Python connects thru a special python simmconnect which had to be installed so it could communicate with MSFS.
If used with the A320 in MSFS it works and tracks the Fsim trim wheel.
It was during my testing i decided to do the following test.
I placed Fsim trim wheel at one end and my Throttle at the opposite end.When i started the script the stepper would go for about 1 sec and would pause for a second then repeat the cycle 3 to 4 times then would continue on till just before the desired point it would pause then finally reach its destination.
If its going to be a hassle then its not worth its as it appears to do what i want under normal conditions.Just trying to work out if there was something wrong with script.
The hardware is built and thats from observation.Here is the link but it adds very little
https://cults3d.com/en/3d-model/game/a320-throttle-quadrant#comments
thanks
les 

ame

No worries. I do have experience with Python and Arduino, so I have no qualms about diving in. I also enjoy this sort of thing, although I can't commit to any kind of timeframe.

First thing to point out is that there is no magic, so anything the hardware does is due to some specific cause. The trick is to ensure that the specific causes are intended. Or at least, if they are unintended that you are aware of the reason for it, and have decided to accept it.

I'm very wary of "oh, it just does that".

iwik

Thanks,
yes weather it be intentonal or unitentional is what i am trying to find out.No doubt if its outside of the window of operation then it doesnt matter.even with this quirk it doesnt really bother me.I have been in contact with the russian developer but further questions have received no reply.
Will update you if anything changes.If you are up for the challenge great but dont put any emphasis on it.Thanks

ame

Ok. I have looked briefly at the code, and here's what I found.

Firstly, looking at "trim.py", this is basically a helper application that links to the simulator using SimConnect (which is similar to FSConnect for earlier versions of MSFS). The first thing it does is to look for the Arduino by making a list of all available serial ports, opening them up one by one, sending the character "i" and looking for a reply. If the reply "TU0" is received then the code uses that port for communication with the Arduino.

Next, it tries to establish a link with the flight simulator by making a request for "ELEVATOR_TRIM_POSITION" (which is set up to repeat every 100 milliseconds, or 10 times a second).

Finally, it enters an endless loop, which checks for new values from the simulator, and if they are valid, sends the data to the Arduino via the serial port as "snnnn", where nnnn is the value of the elevator trim position multiplied by 5732.

There is also a section of code that doesn't run because it's within an "if False" clause. This part will look for stuff coming back from the Arduino, and send commands into the flight simulator. This could be in response to switches or knobs on the Arduino that have various defined functions, but in the code you have, this is ignored.

So, that's pretty simple: find Arduino, keep serial port open, link to MSFS, get ELEVATOR_TRIM_POSITION every 100 ms, multiply by 5732 and send to the Arduino.

Now let's look at the Arduino code. Luckily we can ignore the inputs which get sent back to the simulator, because that all gets ignored by "trim.py". But then again, there are a lot of things like that defined in the code, so someone must have found them useful.

For the stepper motor in the trim wheel, these are interesting:
#define STEP_PIN 15
#define DIR_PIN 14
#define EN_PIN 16

They are the Arduino pin numbers attached to the stepper motor driver. Your wiring must match this.

Then there is a timer-interrupt driven function that actually moves the motor. It is called regularly, and checks the desired position of the motor (which is set by incoming position data from the simulator) to the current position. If the desired position differs from the current position then the code will cause a step pulse to happen in the desired direction. Basically it compares a variable called trimmer_steps_cur with trimmer_steps_set and decides what to do.

If the desired position matches the current position, nothing happens.

There are two key functions in Arduino code. "setup", and "loop". "setup" is run once to initialise things. Here it opens the serial port with a speed of 115200 baud (which matches the speed set in trim.py), and configures the stepper motor pins (STEP, DIR, and EN).

"loop" runs continuously. In this code it looks at the various inputs that you have (but are ignored by trim.py), then looks at incoming data from the serial port.

If the code sees "snnnn" it gets the incoming number, multiplies it by STEPS_MULT, and assigns it to trimmer_steps_set. STEPS_MULT is 41. I don't know why, but don't forget, the value from the simulator was multiplied by 5732 before it was sent...

Ok. Before I get much further it would appear that there is a pot connected to the trimmer, so, as the trim wheel is moved (by the user, or by the stepper motor) its position can be determined.

I'll have to dig a bit deeper...

ame

Just out of interest, have you actually built this thing? Did you buy it as parts and put them together, or was it already assembled?

ame

There is probably a step missing. In the information page it says "After assembly, connect to PC and start callibration arduino sketch to get MAX and MIN for potentiometers and wrote those values to main sketch."

It's possible that you have omitted this step, so I'll see if there are instructions.

iwik

Hi Andrew,
Saw your pm,sorry i havent answered.I have decided to abandon the motorized portion.Wasted to much time and run out of patience.I did the calibration thing.At times i get some other weird happenings.
So thanks for your help.May return sometime later.

ame

Ah, ok.

Apart from needing better documentation it looks very cool. If you want to get it going just reply to this thread, or send me a PM. Cheers.

iwik

Thanks Andrew,
when things look better maybe will take another look.

Like the Website ?
Support Cockpitbuilders.com and Click Below to Donate