So i have this old power wheelchair sitting around and want to control it with my Turnigy TGY 9X(a common 2.4GHz RC wireless transmitter and receiver). For fun I want to run it through my Uno and not get some ESCs. I figured that the receiver puts out about .2 volts when I move the control stick to the highest point, .15 volts at the middle, and .1 volts at the lowest, having the Uno read the pin on A0 and A1 ( horizontal and vertical), but that only renders about 21 out of the 1023 for analogRead. I then thought that this data could be used to drive the PWM pins that would connect to where the joystick usually goes on the wheelchair micro controller. The joystick has 6 pins, +5 and GND, 2 for vertical and 2 for horizontal, when the stick is moved forward V1 reads +5 and V2 reads 0, in the middle they all read 2.5, in reverse V1 reads 0 and V2 reads +5, this is also true for H1 and H2.
What i am asking is how can i take the value read from the analog pins and smoothly integrate it to be PWM ready. Like its going to read a value from 11 to 21, how can that be translated to 0-255? and how can I take these variables and make this thing operate smooth, like i am just using the original joystick and not another micro controller? I've thought of the byte() function but I'm fairly new and not quite sure what im getting into here. thanks for the input.
Paranemertes:
What i am asking is how can i take the value read from the analog pins and smoothly integrate it to be PWM ready. Like its going to read a value from 11 to 21, how can that be translated to 0-255?
In these situations the first thing you need to do is to convert from the delta (difference) in the source to the delta in the destination.
21 - 11 = 10, so 10 is you delta in the source
255 - 0 = 255 so 255 is your delta in the destination.
To get from 10 to 255 you need to multiply 10 by 25.5.
But your actual signal starts at 11 you say. So you need to remove that offset
output = (input - 11)*25.5
where input is from 11 to 21 and output will go from 0 to 255.
Check it with a few values:
If input is 11 then output is 0.
If input is 15 then output is (15 - 11)*25.5 = 102
If input is 21 then output is (21 - 11)*25.5 = 255
Thats great, but I think i also need a function that would be the opposite of that one.
like:
input = 11 output = 255
input = 15 output = 102
input = 21 output = 0
thanks
Look at the map function. Your input range is 11 to 21. Your output range is 255 to 0.
yeah I'm aware of the range, I just don't know what to do with it, not exactly a math genius.
I just don't know what to do with it
Did you look at the map function?
map(value, fromLow, fromHigh, toLow, toHigh)
Parametersvalue: the number to map
fromLow: the lower bound of the value's current range
fromHigh: the upper bound of the value's current range
toLow: the lower bound of the value's target range
toHigh: the upper bound of the value's target range
Returns
The mapped value.
So, you know fromLow (11), fromHigh (21), toLow (255), and toHigh (0). If you know the value to be mapped, which surely you do, it isn't rocket science to figure out how to use the map function - math challenged or not.
yeah, thanks.... not really what i was looking for. I was looking for a function, like:
f(x) = blah blah blah...
i was able to get one:
Output = -25.5(Input) + 535.5
but thanks, i wish the first guy had mentioned that.
Well i thought that would have ended it, but NO. im doing some troubleshooting and made a simple analogRead sketch to see what my real range is on the receivers two pins:
int receiverPin1 = A0; //Ch1 Horizontal
int receiverPin2 = A1; //Ch2 Vertical
int sensorInput1 = 0; //variable for receiverPin1 HORIZONTAL
int sensorInput2 = 0; //variable for receiverPin2 VERTICAL
void setup() {
Serial.begin(9600);
}
void loop(){
sensorInput1 = analogRead(receiverPin1);
sensorInput2 = analogRead(receiverPin2);
Serial.println(sensorInput1);
Serial.println(sensorInput2);
delay(1000);
}
i then get numbers like:
20
0
20
0
20
0
when i do nothing, then i will move the control stick up and get:
669 (this is horizontal, so why the change?)
0
20
0
20
0
20
671 (<- that is what was expected)
20
0
670
0
20
0
20
0
19
671
20
0
669
0
its the same when i move it in any direction, 20 and 0 then an average of 670 in random places... im not quite sure what to make of this. cause when i broke out the trusty volt meter and measured the signal voltage it was .15 volts in the middle(no movement) .2 volts in the up and right position and .1 volts in the down and left position. im confused cause when i (re)calculated what that would be on a 0-1023 scale i got a range of 20-40, (.1/5=x/1023) and (.2/5=x/1023). NOT 670 and whatever. please help me with this conundrum.
Your going to have to draw a picture/schematic showing what you have wired to the Arduino. Do it soon, before you destroy the Arduino.
This is the transmitter and receiver that i am using, I'll get a pic of the wiring diagram soon.
Her is the wiring diagram, I don't see why this would fry the Uno....
DThrushArduinoNonsense 1.tiff (258 KB)
The documentation I saw on that receiver showed servos connected directly to the receiver. If that is indeed how the receiver works, the servo pins should be connected to digital pins, and read using pulseIn.
YES, that looks like it will work, thanks for the help.
Well, got my hopes up.... the code works great, but for some reason its not working on the wheelchair. I have double checked all my connection and code and have everything right.... so it must be the wheelchairs micro controller. I am feeding it voltage that is exactly the same as it would be getting from the joystick....I don't see what the problem is. PLEASE HELP!!
So i have this old power wheelchair sitting around
I googled "old power wheelchair". 42 million hits. A few too many...
Perhaps you could help narrow down the search a little.
PLEASE HELP!!
We might be a bunch of grumpy old men, but we ain't deaf.
I think your receiver is giving you a PWM output, analog in time, not analog in voltage. You need to read it into the Arduino with a timer not with an A/D.
Alrighty then, I didn't know that typing in all caps affected your ears, good to know.
its a Dynamic, pt # DC50DL01 s/no Eo5272039
the micro controller number is QSM 60291TB 24/05/05
yeah, your a bit late, already fixed that, the code is good. Im just not sure why it wont work on the wheelchairs micro controller. thanks for the input though, i hope you can help with this issue.
its a Dynamic, pt # DC50DL01 s/no Eo5272039
the micro controller number is QSM 60291TB 24/05/05
Well, I'll flip through my "old power wheelchair" catalogs when I get home, and see if I can find anything.
Won't take long, since I don't have any. You got a link to something we can read?
Maybe you could use your amazing googling powers to find something. If I could find something to read i don't think i would be talking to you, because i have looked and found nothing. Perhaps there is someone out there with actual knowledge of these thing who can actually help me?