Go Down

Topic: PinChangeInt within a custom library (Read 945 times) previous topic - next topic

fuzzball27

Howdy,
I'm working with PinChangeInt in my custom library, and I am curious how to use the attach interrupt function with a private function in my class? Here is my code:
.h:
Code: [Select]
#ifndef RXTX_H
#define RXTX_H
#include    "Arduino.h"

class RxTx
{
public:
    RxTx(byte ch1, byte ch2, byte ch3, byte ch4, byte bat);
    ...
private:
    void calcThrottle();
    void calcAileron();
    void calcElevator();
    void calcRudder();
};

#endif

.cpp:
Code: [Select]

#include    <Arduino.h>
#include    <RxTx.h>
#include    "/Applications/Arduino.app/Contents/Resources/Java/libraries/PinChangeInt/PinChangeInt.h"

...

byte throttle;
byte aileron;
byte elevator;
byte rudder;

...


RxTx::RxTx(byte ch1, byte ch2, byte ch3, byte ch4, byte bat)
{
    init();

    pinMode(ch1, INPUT);
    pinMode(ch2, INPUT);
    pinMode(ch3, INPUT);
    pinMode(ch4, INPUT);
    pinMode(bat, OUTPUT);
   
    digitalWrite(bat, LOW);
   
    throttle = ch3;
    aileron = ch1;
    elevator = ch2;
    rudder = ch4;
   
    //This is where I'm attaching the interrupts
    PCintPort::attachInterrupt(throttle, calcThrottle, CHANGE); // This doesn't work.
    PCintPort::attachInterrupt(aileron, calcAileron, CHANGE); //   It brings up an error that says
    PCintPort::attachInterrupt(elevator, calcElevator, CHANGE);// "No matching function for call to 'PCintPort::attachInterrupt
    PCintPort::attachInterrupt(rudder, calcRudder, CHANGE); //     (byte&, <unresolved overloaded runction type>, int)'"
}

...

//These are the private functions I am trying to attach

void RxTx::calcThrottle()...

void RxTx::calcAileron()...

void RxTx::calcElevator()...

void RxTx::calcRudder()...


As always, help is greatly appreciated! :)
fuzzball27 >>-->

pYro_65


fuzzball27

Thank you so much!
It's too bad there isn't a more convenient and conservative way, but it works!
fuzzball27 >>-->

DuaneB

Hi FuzzBall,

You might have seen that this is the sort of thing that I do all the time on my blog, here for instance -

http://rcarduino.blogspot.com/2012/04/how-to-read-multiple-rc-channels-draft.html

I have previously avoided writing a library because I didn't really see a need, but I have since taken a closer look at some of the existing libraries and while they are great for generic projects and they certainly work as demonstrated by the many people using the link above they are much bigger and slower than they need to be.

I am in the testing stages of a library which drops some of the flexibility to give a smaller, faster, more accurate RC Solution.

If you are at the bench stage of your project, let me know if you would be interested in doing some bench testing of the new library.

Duane B.

rcarduino.blogspot.com




fuzzball27

Hahaha this is perfect... XD

My library is actually based off of one of your blog posts I found some weeks ago. I absolutely loved the way you integrated interrupts and unsigned value types for time efficiency. I very much appreciate the time you've invested in your blog.


I am in the testing stages of a library which drops some of the flexibility to give a smaller, faster, more accurate RC Solution.

If you are at the bench stage of your project, let me know if you would be interested in doing some bench testing of the new library.


That sounds awesome. I would love to try it out.
fuzzball27 >>-->

DuaneB

#5
Aug 04, 2012, 04:38 pm Last Edit: Aug 04, 2012, 08:07 pm by DuaneB Reason: 1
Hi,
   Do you have some diodes and breadboard to prototype a very simple 'channel multiplexer' ?

   To make a small and fast library I wanted to read all channels through a single pin, as my receivers do not provide a raw output, I wanted to do this by routing all of the channels through diodes to INT0. The diodes are there to stop all of the channels that are low from sinking the channel which is high. This worked for Spectrum receivers, but not for Futaba.

The Spectrum receivers have a small gap between one channel pulse ending and the next starting, with Futaba, the change over is too fast for the Arduino to detect on a single pin.

The solution is very simple, route consecutive pulses to alternating pins, as a result I have a small and fast library that is able to read six RC Channels using just two pins. It also generates upto six output channels, in the next version I will provide upto 9 output channels.

Let me know if you are willing and ready to get your hands dirty and I will provide a link with more details.

Duane B

rcarduino.blogspot.com




fuzzball27

I'll need to buy more diodes (As of now I have 2 haha). I'm using a 4ch Tx with a 6ch Rx, but I'm assuming you're using interrupts for timing so that shouldn't cause any problems right?
fuzzball27 >>-->

DuaneB

Should be fine, do you have some high value resistors as well I am using two 1M resistors but you can probably use anything down to about 10K ?

I put up a short intro to the RCArduino multiplexer here - its crazy simple, just a diode for each channel and a large value resistor to dissipate the charge that gets trapped between the diodes and the input pin if it has nowhere to go, the resistor give it somewhere to go without upsetting anything else.

I need to update the picture to include the resistor, but the circuit is basically as simple as it gets -

http://rcarduino.blogspot.com/2012/08/multiplexing-rc-channels-with-arduino.html

I moved the first test system onto a strip board Arduino which is going in a car tomorrow - its running on the bench next to me at the moment - I don't want to say anything more about it or it will curse my road testing tomorrow.

What make and model are your transmitter and receiver so that I can include the channel order in the library documentation ?

Duane.

rcarduino.blogspot.com

fuzzball27

fuzzball27 >>-->

DuaneB

Hi,

That looks fine, really cheap too.

Let me know when you have your diodes and I will post a diagram for the multiplexer. Its best if you build the circuit on breadboard first to check the that the channel pulse order is the same as the order they are printed on the receiver.

Duane B

fuzzball27

It just occurred to me that the shield I'm using for my project prevents me from being able to use INT0 and INT1. I'll keep an eye on your blog though, I may end up doing another RC project!
Thank you for the help.
fuzzball27 >>-->

GreyGnome


Thank you so much!
It's too bad there isn't a more convenient and conservative way, but it works!

Well, 3 months later but anyway, for posterity:  Look at the ooPinChangeInt library.

Go Up