Jump to content
Sign in to follow this  
gatesphere

Parallax PIR sensor and LaunchPad - help?

Recommended Posts

Hello all. I've come to you for some help.

 

I picked up a Parallax PIR sensor from RadioShack today, and have not been able to get it to work nicely with my LaunchPad...

 

Before you ask, I have tested the sensor with various equipment, and also with an Arduino. It works fine to blink an LED on the Arduino. When powered by the LaunchPad's 3V3, it works as well, as discovered by an oscilloscope. But for some reason, the LaunchPad just cannot see the signals being generated by it. What am I doing wrong?

 

Here's my code, a simple program which should turn on LED1 when the PIR senses motion, and turn it off when there is none:

(assumes a Parallax PIR sensor connected in the following manner: OUT => P1.5 (input), + => P1.4 (output, high), - => P1.3 (output, low)... done this way to not need a breadboard and jumpers)

#include 

void main() {
 P1DIR = BIT0 + BIT3 + BIT4;
 P1OUT = BIT4;

 for (; {
   switch (P1IN & BIT5) {
     case BIT5:
       P1OUT |= BIT0;
       break;
     default:
       P1OUT &= ~BIT0;
   }
 }
}

 

Any help?

 

EDIT: Information and datasheet available here: http://www.parallax.com/Store/Microcont ... roductName

 

EDIT2: Solution found! Check my blog: http://blog.suspended-chord.info/?c=11

Share this post


Link to post
Share on other sites

Okay, new guy here, and I've only used interrupts to sense port changes. disclaimer> :D

 

Isn't "P1IN & BIT5" going to give you a binary result (i.e.: 1 or 0, high or low)? You compare it against BIT5 (b00010000), which, to me, would never be true.

 

me:

 

-Doc

Share this post


Link to post
Share on other sites

Yup, MSP430 Family User Guide p8-3 (p359 of pdf):

8.2.1 Input Register PxIN

Each bit in each PxIN register reflects the value of the input signal at the corresponding I/O pin when the pin is configured as I/O function.

Bit = 0: The input is low

Bit = 1: The input is high

So:

switch (P1IN & BIT5)

Is going to return 0 or 1.

 

Changing to:

...
  switch (P1IN & BIT5) {
     case 1:
       P1OUT |= BIT0;
       break;
...

Should work.

 

BTW: Why not connect to pins 1 and 14 for power?

 

-Doc

Share this post


Link to post
Share on other sites

I think the reason my code isn't working is because I forgot to kill the WDT... *facepalm* Man, I'm stupid sometimes :P

 

Anyways, I'll test and see if it works then.

 

But to answer your question, GeekDoc, using (P1IN & BIT5) will return either 0b00000000 or 0b00100000, depending on whether BIT5 of P1IN is 0 or 1. The reason for this is that & is a bitwise operator, and will return the value of the operation bit by bit. So, for example, say P1IN = 0b01101001, and let's say FLUFFY = 0b00011101. P1IN & FLUFFY will therefore return 0b00001001, as bits 0 and 3 are 1 in both P1IN and FLUFFY.

 

Oh, and the reason for the pin assignments is so that I can plug the module directly into the female headers I've soldered to the LaunchPad, instead of having to break out the breadboard and jumpers. It's just a matter of convenience.

 

Anyways, off to kill the WDT and test again. We'll see if it works now :P

 

EDIT: Nope, still doesn't work. Any suggestions still?

Share this post


Link to post
Share on other sites

gatesphere,

 

I haven't really looked into your problem too much, but I have a quick suggestion. If the basics don't work, make it even more basic. Try simplifying your code, use an if statement and not a switch. It's worth a try at the very least. One thing to watch out for, is that switch statements are not as efficient as if statements when only 2 cases are expected, when going to assembly things can get messy.

 

Also, Doc, are you thinking of the '&&'? I still get them mixed up sometimes, the difference between the & and the && for the MSP430. I always like to do it like this: if (P1IN & BIT5 == BIT5), I'm fairly sure that its just as efficient as any other way of writing the code, it all comes down to 2 asm commands regardless. The logic OR, and then the jump command.

 

Best of luck gatesphere.

 

NJC

_________________________

http://msp430launchpad.com

Share this post


Link to post
Share on other sites

Nope, that doesn't work either. In fact, no matter which GPIO I attach it to, it's not receiving any info. But it is clearly working, as I have an LED attached to the signal line which goes on when motion is detected. I have no idea what's going on here.

Share this post


Link to post
Share on other sites
@gatesphere, @NJC:

Dang! I'm still getting used to this bitwise stuff!

 

Hahaha, it's okay.

 

Here's one way to think of it: Bitwise operators operate BITwise. BIT FOR BIT. So, bitwise OR'ing two chars (8 bits each) will result in the logical equivalent of 8 OR operations between 0s and 1s. For example, 0b01101000 | 0b11100011

 

Basically, it'll be (MSB first):

0 | 1 = 1
1 | 1 = 1
1 | 1 = 1
0 | 0 = 0
1 | 0 = 1
0 | 0 = 0
0 | 1 = 1
0 | 1 = 1
        = 11101011

 

So yeah, just think of it one bit at a time, then combine.

 

My PIR is still not working with the LaunchPad, though... anyone have any idea what's going on?

Share this post


Link to post
Share on other sites

Ok, some additional research shows that while hooked up to an Arduino's 5V, the output pin only pulses at ~3V for high. Similar results when powered from the LaunchPad's 3V3, where it shows ~1V7. So, my guess is that the MSP430G2231 isn't sensitive enough for that voltage to be called high. So now my question is... is there a way to step up that voltage without too many expensive parts? I have very little experience with electronics outside of the LaunchPad and Arduino tinkerings, so I'm asking for someone with EE experience to help. Any ideas?

Share this post


Link to post
Share on other sites

The only other stab I have is maybe it needs a pull-down resistor if you don't have one? You mentioned you were doing this without a breadboard, so I know from experience how hard it is to get a pull-down/up resistor in there along with the lead from the switch/sensor. (BTW: I recommend joe's mini proto/breadboard shield. I have one.)

 

I do know how to do the bitwise operations; I just don't instinctively think that way, which trips me up. With all these smart people here, I'll learn!

 

-Doc

Share this post


Link to post
Share on other sites

According to John H. Davies' book MSP430 Microcontroller Basics "The precise input voltages Vin that correspond to logical 0 and 1

depend on the technology but typical values for CMOS are

 

Share this post


Link to post
Share on other sites

I'm sure you have, but have you tried giving P1.5 a high signal manually? If that works, we're not missing anything in the code, so it'd have to be in the sensor. But you said that the sensor checked out fine on the oscilloscope (was that at 3v?), so it must be in the code... :roll:

 

At this point (if it were my project), I'd probably put the whole thing in a box (maybe with a cat) and say it was both working and not working...

:lol:

 

Best of luck, and please tell us when you figure it out.

 

-Doc

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...