Main Site Documentation

Simple Motion Sensing program


#1

Still very new to all this, and after a couple of weeks I’ve made little headway due to silly debug issues and other projects pulling me away.

So here’s the easiest question I can come up with…what can I do to make the sample program for the PIR motion detector work?

I plugged in the following sample code, from: https://www.ghielectronics.com/docs/88/pir-module

But I get errors when trying to compile.

Attached the errors I’m getting below. (yes this is simple programming stuff, but I need to start somewhere and I don’t know who else to ask)

For bonus credit - I have the Tunes module plugged into port 3 and want to play any kind of sound when motion is detected.

Thanks in advance - I feel silly asking such as simple problem considering all of my other technical accomplishments…but hey, I have no shame anymore. I need to start putting some projects together.


#2

@ verbosewater - Take a look at the tutorials, the should give you a reasonable foundation to build on.
https://www.ghielectronics.com/docs/37/netmf-and-gadgeteer-tutorial-index

What you need to do is start a new gadgeteer project, you should then get a designer which shows you a mainboard, if the mainboard is not the mainboard you are using the you can drag the correct mainboard from the toolbox which by default can be found on the left of the designer. Once the mainboard is there, yo can find the motion sensors module n the toolbox and drag that to the design surface, you can then link the module to the mainboard by either right clicking and selecting the option to auto connect the components or you can explicitly drag a link from the module to the board. You will see the supported mainboard sockets turn green when explicitly linking the module.

Doing the above will ensure that your project includes all the relavnt libraries to be able to use the module.

Just to help you get a basic understanding of the problem, here is a simplified explanation.

The error says that you are either missing an assembly reference or a using directive. In .NET and .NETMF assemblies are containers for code, typically .exe and .dll files. So to use the code in an assembly you first need to reference the assembly in your project, once you have the assembly reference you can access the data types exposed by that assembly.

To avoid naming conflicts, data types in assemblies are contained in namespaces, so when you want to use a data type you need to know what namespace and assembly it is in. A namespace is really just a dotted prefix to the name of the type, you can avoid repeating the namespace everything by including a using directive near the top of your source file which basically tells the compiler to search the namespace for any types it cannot match in the code. The can be multiple using directive and the compiler will search them all.

Assemblies can contain multiple data types in multiple namespaces and a namespace can span multiple assemblies.


#3

Thanks taylorza for the quick response.

I did go through the tutorial and did everything exactly as it said. I’m using a Cerberus board, so I created a brand new project (NETMF) and it asked what board, so I put in Cerberus. Then I added in the motion sensor tot the diagram and connected them up appropriately.
Then I dropped in the code, and that was my result. I know this is basic stuff (and I’ve actually programmed before) so I’m at a loss why nothing was auto-generated to fix that.
This was a brand new install of VS2010, as well as NETMF. Again, I followed everything in the beginning stuff to the T.
In a different project I was using the Hydra board, and I when I stepped through the debug part, after it went through the ProgramStarted method, it bombed out and a prompt came up and said the Source code was missing or changed. ??? I searched the forum but couldn’t find anyone talking about that error…but I digress, I’m just trying to do the simplest of things and it isn’t working. I’ve done a few Arduino projects - which is harder than this in my opinion - and have been successful. I have a LOT of modules I’ve bought from GHI within the last few weeks and haven’t made a single thing work yet.

I’m starting to think it’s the laptop I’m using - and the actual VS install that is hosing me up. Especially after reading what you just said…this stuff should just work. Do you think that may be my issue? (I’ve tried a total of 5 different projects - and none of them have worked due to very strange errors…which I’m too tired to even talk about right now).


#4

@ verbosewater - I can understand your frustration, but I assure you that this stuff typically just works. Generally if you have any problems it would be with the specific intricacies relating to particular module. So don’t give up hope…

Now I have not been using VS2010 for quite a while now, once VS2012 support was introduced I moved over. So, I would not/cannot rule out that there might be a problem relating VS2010 tooling.

I believe there are a few members that are still using VS2010 so maybe they can chime in here.

What might be a good idea is if you can post your project code in a zip file so that I or someone else can take a look and see if there is anything obvious that is missing.


#5

@ verbosewater - Hi, can you please show us the contents of your >Program.generated.cs< (in > Program.gadgeteer <) and the > using < directives of your program?

and anaother idea:
comment out the line where you define the eventhandler
then write the line new
after you typed
motion_Sensor.Motion_Sensed +=
Visual Studio should show you what you have to take. Type two times Tab and you should have all what you need.

Kind regards Roland


#6

I have 3 pir sensors to RMA, I think there is a bug somewhere.


#7

@ taylorza and RoSchmi:

Finally getting somewhere! The idea of commenting it out and doing the fixed my first roadblock. So what I gather from that experience - is do NOT copy/paste because it doesn’t always create the handler correctly. Thanks!

Onto the next roadblock. I ran and deployed the code to the board, and put in a break point where the Motion sensed event fires. In here I wanted to play a simple note. That didn’t work - but I’m not too concerned with that right now. My problem is that after i gets done with that method, I get the attached screen-right in the middle of debugging. !?!?! This has happened a few times on occasion and I’m baffled. This is a new project with nothing complicated going on.

Any help?

(and on the VS2010 note - I’d prefer to stick with it since we will be using that where I work for migrating everything over from 2005. VS2005 is what I’m used to…but there’s nothing set in stone as far as I’m concerned!)


#8

I’m attaching the screen I get when I click on ‘cancel’ on that first screen. This just made me aware of what may be wrong…the file locations are wrong. But how do I fix this?


#9

Okay…when I have the board powered via the 4AA module - it seems to work just fine. ??

If it’s powered via the USB cable, the motion sensing method seems to keep tripping every second no matter what. I remember reading something about that when scouring the forums for my other problems. Not sure if that’s a known issue or not.

@ njbuch Perhaps that’s why you are returning them?

…update, just saw andre.m’s post. Thanks for that! Things are starting to make more sense. Think I’m finally over the first learning curve hump.


#10

Hmm never tried the motion sensors with batteries. Needless to say, they should work either way.


#11

I’ll hook up a meter to it when I get back into town. It works perfectly via the 4AA module though - and right now that’s all I’m concerned with.

Thanks for the info and I’ll let you know what I find.