REGISTER/ SIGN-IN, YOU MAY BE MISSING OUT ON A FEATURE TOPIC. REGISTRATION IS FREE If you are seeing this message you may not be registered or signed-in. If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register or sign-in before you can access all areas of MyCockpit: click the register link above to proceed. To start viewing messages, select Forum from the above menu.

If you enjoy reading the
content here, click the below
image to support MyCockpit site.

PWM/code limit? analog instruments cessna 206

so after successfully controlling a meter with link2fs, with the help of Jim and a few other members, i quickly rushed to build my own instruments. i dont know how to scale images to fit the meter, so i had to resort to very crude methods, and actually draw the tachometer on a piece of paper, to scale. it didnt come out too bad, surprisingly. (picture attached) anyway, i got it working and had my very first instrument working, perfectly synced with fsx and correctly calibrated. excited, i quckily went out and bought a few meters. After a few runs to the market, i found an even cheaper alternative. AC voltmeters used in household UPS. they cost me 30 cents a piece. i opened them up, bypassed the massive resistor, and had full deflection from the arduino's 5.5V 40ua. my excitement grew, and i spent a the weekend making fuel guages. (again, by hand, sadly) plugged in the meters, and now i had two fuel guages, all calibrated and good to go.

My next aim was oil temp and oil pressure guages. following the same procedure, i made the guages. added a few lines to the code. the code, did become quite lengthy at this point, running 5 instruments. it lost its efficiency. i figured that, thats because it has to read all those line to reach the end of the loop, to go back to the begining of the loop, and thus loses time to make the needles move smoothly. it reads a value say 1500RPM. as i increase RPM, the needle stays there for a good second, although my actual RPM is now 2500 since it takes time to reach the end of the loop. when it startes the loop again, it reads the new value, "2500" and moves the needle directly to 2500. at least thats what i think is happening.

I was fine with the jerky movements, but then i decided to add the MAP instrument. (manifold pessure) the meter fails to respond completely. it responds sometimes, spurradically, but doesnt move from that value. i checked the code many times. seems to be fine. i copied the code which drives the MAP seperately onto a new sketch, and it works flawlessly. i even tried changing it to fuel flow. the same problem arises.

is it possible that i cant drive more PWM with this code? i have 14 PWMs. only used 6.

I know that the code has become very crude and inefficient because of the size and logic. i'd be grateful if someone could help me out. am i on the right track at least?

If you enjoy reading the
content here, click the below
image to support MyCockpit site.

Re: PWM/code limit? analog instruments cessna 206

Hello.
I can understand the reason there is such a lag! As the arduino runs down your code, it is stealing information from the serial buffer. By luck or chance it reads the correct combination to make the instruments work. That's ok, because here is the reason:
1.) At the top of the void loop, you need to read one character from the serial buffer. This character will be an identifier such as "=", "
2.) After obtaining the identifier, it now needs to read one more character- the alphabet character to know what instrument.
3.) Read a determined amount of characters (set by L2FS) to determine the value of the instrument. It's common for people to read too many characters or not enough characters in this area; thus, it messes up streaming information down the line.

So, if you look at your previous code, you'll notice it was told read from the serial buffer, not because an identifier told it to but, because of the statement " if (Serial.available() > 0)". The serial read directly after that statement was stealing characters from you.

I hope I was able to shed light on the 'why' the code was lagging and not performing to expectations.

If you enjoy reading the
content here, click the below
image to support MyCockpit site.

Re: PWM/code limit? analog instruments cessna 206

oh man! you just made my day. thanks for going through the code and actually explaining what i was doing wrong. i understand what you said completely. didnt know i was completely off. thanks for your help and what you offer to the communiy. ive been following you around on the forums and you've done some awesome work.

re-wrote the whole sketch with the help of what you said above and the example. everything is working perfectly. the lag is comepletely gone. when i monitor the serial, the values change at an astonishing rate and thus no lag.

one question though. link2fs reads fuel tank as "0045" (for full fuel). so when i reduce character reads to 2, it doesnt work. thats what i mapped

If you enjoy reading the
content here, click the below
image to support MyCockpit site.

Re: PWM/code limit? analog instruments cessna 206

Hi Jahanzeb .I also have made som analog instruments, and as you, I got problems!
I tryied the code for all of my instruments separatly, and they works fine. But putting things together, not so much.
I could run (a bit unsure) 5 meters without error, but adding more, gave me problems.
My solution was to run four Edgwice Meter's on a Mega card, and four Edgwice Meter's on a Uno card. 8 in total.I whispered to Jim that there could be a limitation in Link2fs, but he says that there should be no problems running 8 on a card ........ so?
Maybe we should sponsor James, so he can buy some Edgwice Meters, and give us the solution

If you enjoy reading the
content here, click the below
image to support MyCockpit site.

Re: PWM/code limit? analog instruments cessna 206

Buzz,
ive been on that thread, stalking you guys. you did manage to get 8 PWMs to work at the same time right? my code was wrong, so i figured that maybe i couldnt connect more, cuz of that. with Jmeller's help, im gonna try 8 PWM on the mega and see what happens. your cockpit is coming along nicely. exactly the kind i want. taken your advice, and actually learned photoshop basics and the instruments are coming along nicely. calibrating them, is a whole new story. today, im going to be playing with servos. read some interesting stuff on this forum, esp the one that Jim recently posted.
Jim, looking forward to your results.
cheers

If you enjoy reading the
content here, click the below
image to support MyCockpit site.

Re: PWM/code limit? analog instruments cessna 206

J,
I had re-read your question about the mapping. It had more to to do with string operators than mapping. What you need to do, as you already know, is discard the two characters if they are "0". This can be done a multitude of ways, but below is an easy to follow (untested) example:

With the above I read the flaps on the baron in FSX ,, maximum expected figure is 57.
For a 'play' I limited the input to 50 using 'constrain' and it works fine.
If I had not used 'Constrain' ,,, then when the flaps position hit 51 (or higher) the 'map' function would crash and the output could be anything.
I think this may be the area that is causing you Guys trouble (out of range mapping) ???
In proper coding both those "50"s would have been 57. (Maximum expected figure)
I would think it's good insurance to use 'constrain' prior to any mapping.