Teensy 2.0 for reading PWM Inputs -> Pheonix 2.0 code

Hey everyone, it’s been ages.

I bought a teensy 2.0 about 2 weeks ago and starting to learn arduino code which seems pretty easy actually, I’m a bit surprised.

Currently I have the Turnigy 9x transmitter with open source code on it called ER9X which allows you to do loads of things and the 8 channel receiver that comes with the kit and its less then 100 bucks! I still have my t7c transmitter I’m going to use for a quad copter I’m building.

Currently I wrote some simple code that reads 8 digital input pins on the teensy and outputs them to a serial string in the following format
1465,1479,1465,1588,1968,969,971,1467

Now this is where I’m a bit foggy,
What’s the best method to allow the Basic micro to read data from the Arduino with the smallest amount of effort?

What I know which isn’t very much about the subject is parse a serial string and lop off the values it needs and stores them in variables for when the phoenix code needs them…

Thanks,
–Aaron

Probably something like:
serin mypin, mybaud, [dec channel1, dec channel2, dec channel3, dec channel4, dec channel5, dec channel6, dec channel7, dec channel8]

could also do it in a loop reading one number at a time… May also want to put in some form of timeout to handle cases where things get screwed up… May also want some form of verifications…

Personally if I am connecting two processors to each other I would forget going to ascii, but instead, simply output binary data. Assuming a word for each value. You could output high byte, low byte, for each value… (or low byte, high byte) and then you could simply read the values in on the BAP. But you either have to verify that they ouput/input the bytes in the same order or write your code to force it…

Kurt

Thanks Kurt, I’ll stick with the first method! Its more my speed for now :slight_smile:

there is going to be way too much crap piled on top of the phoenix… Since you had ported the Phoenix code to Arduino I wouldn’t mind trying that later with the Teensy2.0 as the beast controlling it all, is that fast enough?

They need a 32mhz Teensy! :slight_smile:

Either way since I’m using the code with lookup tables “2.0 Phoenix code” the CPU isnt as hammered as it was with the 1.3 code… IE plenty of room for my slop to go in without affecting its walking ability.

Good Afternoon/Morning

In the little amount of spare time I have I created some code for a teensy 2.0 that reads 8 RC channels and outputs this exact string
1465,1479,1465,1588,1968,969,971,1467

This is from a FrSky d8r-II Plus -> 8 wires going into a Teensy 2.0
The 9th wire is actually a serial output from softwareserial.h which gives me a sudo serial port.

This project I have consumes 9 pins 24 total, 1 is consumed by the LED, and the thing is about the size of US 50 cent coin… Very neat!

pastebin.com/xL2tF1QT
since I don’t comment my code, I’ll roughly explain what some of the options do,

The code outputs the serial string to the console and over pin 9 at the same time, this is just to test, it only needs to go over pin 9.

Since the Bab28 has a hardware uart on pins 14/15 I’m going to use that up.

The question I have is the following,

Looking at the samples in the Basic Micro manual what would I need to do to process a serial string that’s
8 values of the RC channels 1465,1479,1465,1588,1968,969,971,1467 … should I add on some special characters at the beginning and or end so that I maintain sync?

Since I have never done anything with having a BAP read a serial string and … really do something with it I’m not sure where to get started. Since the output from the teensy is going to be read by the bap28 is it just going to be a long nasty string that stores each value into its own variable?

Is my idea stupid and I should be doing it a different way? I just dont know, I need some smarties … cough probably Kurt to tell me what he would do :slight_smile:

OR

Scrap the whole idea of using the Bap and just use a 2nd teensy2.0 for the main 2.1 phoenix code he wrote… or start with one and move to the other… I’m all ears!

Thanks,
–Aaron

Aaron,

It ALWAYS outputs the same exact string 1465,1479,1465,1588,1968,969,971,1467? :>)

Sync characters are good, as is a checksum. I’d make it mimic the PS2 message! Well, I guess the numbers are int, not bytes. But you get the idea.

Nice Work!

Alan KM6VV

Don’t have time or energy, typing on iPad.

You can use hserin to do conversions, like:

Hserin dec pwm1, dec pwm2…]

The basic will see the non numbers as delimineters,…

Kurt

Alan, Kurt,

Good deal! I didn’t know if it was really that easy.

haha and Alan, no the values of the items in the string change!@ that would be goofy if it didnt!!

However now that I can use the teensy 2.0 I might see how to interface a gyro to it. The idea would be to get the teensy to output the same values as a RC receiver outputs and work with that 1000-2000 decimal number so all the math is easy to work with… down the road…

someone help me not spend money and build a brat… hobby king servos!@ they are so tempting… its troublesome…

–Aaron

Hi Aaron,

Yeah, I couldn’t resist a joke!

Interface in an R/C hobby (tail) Gyro? That could certainly work. Do you have to give the Gyro a PWM signal in order for it to work?

Or maybe you mean the IC parts? SparkFun has a number of accelerometer and gyro boards:

sparkfun.com/tutorials/167

I’m going with the 9DOF Razor IMU

sparkfun.com/products/9623

Alan KM6VV

Its an 2 or 3 axis gyro 2 or3 axis Accelerometer… and No I will not have to use a PWM pin. what has to happen is… lots of math.

You sample the gyro/accel pin at initial turn on or “when the device is flat not moving” then constantly loop though sampling that pin via “Adin” or something to that and comparing it with your initial capture values and there you have the difference. when it moved quickly a high value when its static a zero value.

OK, you’re using the IC gyros and accelerometers.

I’d look at the code for the 9DOF IMU I mentioned, and then convert the output(s) (serial or PWM?) you desire.

Indeed! There is a lot of math to implement “sensor fusion”; that’s the purpose of the uP on the IMU.

I don’t have the computations all together yet, but I’m seeing some ways…

You might also consider this:

store.diydrones.com/APM_2_0_Kit_p/br-ardupilotmega-03.htm

Alan KM6VV

www.multiwii.com

Yeah honestly you dont need any of those boards those boards are just an arduino atmegaXYZ chip with the sensors tied to a pin on the chip… Its no different then an off the shelf arduino with a attachable device gryo/accell on the side.

My neighbor is pretty flipping smart and was telling me you need a kalman filter to do the gyro/accel stuff…

Honestly i would just try my idea first and poke around with it, then figure out how to do it the right way later! more fun.