Adafruit is open, safely ... and shipping all orders at this time! Read more!
0

AFSoftSerial on Analog Pins
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

AFSoftSerial on Analog Pins

by torchris on Sat Jan 31, 2009 11:50 pm

I am trying to us the AFSoftSerial library (which rocks, BTW) with the analog pins on my Arduino in digital mode (in other words, addressing them as pins 14-19). When I try to set them up they don't seem to work. Here are the first two lines of my sketch:

#include <AFSoftSerial.h>

AFSoftSerial rfidSerial = AFSoftSerial(14,15);

When I set it to AFSoftSerial(2,3) it works fine, but I really would prefer to use pins 14 & 15 because of the way my project is set up.

Is there something I need to do in setup to initialize these pins?

thanks!

torchris
 
Posts: 4
Joined: Sat Jan 31, 2009 11:45 pm

Re: AFSoftSerial on Analog Pins

by sandorcourane on Sun Feb 01, 2009 3:38 pm

Read the fifth post in this thread - I haven't tried it yet, but another forum member has modified the library to do just that.

sandorcourane
 
Posts: 9
Joined: Sat Dec 06, 2008 6:25 pm

Re: AFSoftSerial on Analog Pins

by mtbf0 on Sun Feb 01, 2009 3:48 pm

here's your problem, right here...
Code: Select all | TOGGLE FULL SIZE
   if (_receivePin < 8) {
     // a PIND pin, PCINT16-23
     PCMSK2 |= _BV(_receivePin);
     PCICR |= _BV(2);
  } else if (_receivePin <= 13) {
    // a PINB pin, PCINT0-5
    PCICR |= _BV(0);   
    PCMSK0 |= _BV(_receivePin-8);
  }
this comes from AFSoftSerial.begin. you can see that it lacks code for the case in which _recievePin is greater than 13. and there may be other omissions in the library that my cursory examination failed to uncover.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: AFSoftSerial on Analog Pins

by mtbf0 on Sun Feb 01, 2009 4:22 pm

this ought to fix it. add this after the interrupt handler for SIG_PIN_CHANGE2
Code: Select all | TOGGLE FULL SIZE
SIGNAL(SIG_PIN_CHANGE1)
{
  if (_receivePin > 13) {
    recv();
  }
}
and replace the code in the previous post with this
Code: Select all | TOGGLE FULL SIZE
   if (_receivePin < 8) {
     // a PIND pin, PCINT16-23
     PCMSK2 |= _BV(_receivePin);
     PCICR |= _BV(2);
  } else if (_receivePin <= 13) {
    // a PINB pin, PCINT0-5
    PCICR |= _BV(0);   
    PCMSK0 |= _BV(_receivePin-8);
  } else {
    // a PINC pin, PCINT8-14
    PCICR |= _BV(PCIE1);
    PCMSK1 |= _BV(receivePin - 13);
  }
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: AFSoftSerial on Analog Pins

by torchris on Sun Feb 01, 2009 6:44 pm

Hello folks,

Thanks for the suggestions. I modified AFSoftSerial.cpp as suggested, but that doesn't seem to have done the trick. I have never modified any of the library files before. Is there a special step to get them to compile or do they do that when you hit the compile/upload button?

thanks,

torchris

torchris
 
Posts: 4
Joined: Sat Jan 31, 2009 11:45 pm

Re: AFSoftSerial on Analog Pins

by mtbf0 on Sun Feb 01, 2009 8:01 pm

well, for one thing, quit taking advice from strangers. especially me. that said, this ought to fix it...
Code: Select all | TOGGLE FULL SIZE
   if (_receivePin < 8) {
     // a PIND pin, PCINT16-23
     PCMSK2 |= _BV(_receivePin);
     PCICR |= _BV(2);
  } else if (_receivePin <= 13) {
    // a PINB pin, PCINT0-5
    PCICR |= _BV(0);   
    PCMSK0 |= _BV(_receivePin-8);
  } else {
    // a PINC pin, PCINT8-14
    PCICR |= _BV(PCIE1);
    PCMSK1 |= _BV(receivePin - 14);
  }
sorry. they don't call me mtbf0 for nothing.
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: AFSoftSerial on Analog Pins

by torchris on Sun Feb 01, 2009 9:37 pm

At least they don't call you "/dev/null"!

I'm afraid that didn't do the trick either. When I check the arduino\arduino-001\hardware\libraries\AFSoftSerial directory the "AFSoftSerial.o" file hasn't changed dates. Doesn't that mean the new cpp file isn't compiling?

Thanks for the help!

torchris
 
Posts: 4
Joined: Sat Jan 31, 2009 11:45 pm

Re: AFSoftSerial on Analog Pins

by mtbf0 on Sun Feb 01, 2009 11:17 pm

mv AFSoftSerial.o /dev/null
"i want to lead a dissipate existence, play scratchy records and enjoy my decline" - iggy pop, i need more
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Re: AFSoftSerial on Analog Pins

by torchris on Mon Feb 02, 2009 10:17 am

Ah! A small but necessary step! However, now when I start up the Arduino IDE I got:

AFSoftSerial.cpp: In member function 'void AFSoftSerial::begin(long int)':
AFSoftSerial.cpp:166: error: 'receivePin' was not declared in this scope

So I had to make a very small correction of adding a "_" before the last "receivePin", so the final code looks like:

Code: Select all | TOGGLE FULL SIZE
   if (_receivePin < 8) {
     // a PIND pin, PCINT16-23
     PCMSK2 |= _BV(_receivePin);
     PCICR |= _BV(2);
  } else if (_receivePin <= 13) {
    // a PINB pin, PCINT0-5
    PCICR |= _BV(0);   
    PCMSK0 |= _BV(_receivePin-8);
  } else {
    // a PINC pin, PCINT8-14
    PCICR |= _BV(PCIE1);
    PCMSK1 |= _BV(_receivePin - 14);
  }


So, once I deleted the old object file and made the tiny change, it works perfectly!!!

Thanks very much for your help!

regards,

Torchris

torchris
 
Posts: 4
Joined: Sat Jan 31, 2009 11:45 pm

Please be positive and constructive with your questions and comments.