Main Site Documentation

No events firing


#1

I have not delved into this in detail yet, and I should, but before I do, I wonder if anyone else might be able to spot something stupid I’m doing.

I just got my spider, and fired it up. Installed everything OK, no errors, including updating firmware. Spider switches are all back to ‘off’.

I tried the sample camera app, but no luck. Then I started paring things down, and trying different devices. I simply cannot get any of the events to fire. Take the following code (I included both the program and the gadgeteer generated code for clarity)…

If I press the joystick, nothing happens. If I press the button, the LED lights when the button is down an goes out when the button is released. Breakpoints in the event handlers never trigger and and debug messages in the event handlers never generate anything.

I [italic]must[/italic] be doing something stupid but I just can’t figure out what it is!

[Edit - I’ve tried with and without the “while(true)” - that was just in the last iteration.]

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerCamera
{
    public partial class Program
    {
        void ProgramStarted()
        {
            /******************************************************************************************
            Access modules defined in the designer by typing their name:                            
            
            e.g.  button
                  camera1

            Initialize event handlers here.
            e.g. button.ButtonPressed += new GTM.MSR.Button.ButtonEventHandler(button_ButtonPressed);             
            ***************************************************************************************** */

            // Do one-time tasks here
            Debug.Print("Program Started");

            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);

            joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);

            while (true)
            {
                if (button.IsPressed)
                    button.TurnLEDOn();
                else
                    button.TurnLEDOff();
            }
        
        }

        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            if (button.IsLedOn)
                button.TurnLEDOff();
            else
                button.TurnLEDOn();
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            if (button.IsLedOn)
                button.TurnLEDOff();
            else
                button.TurnLEDOn();
        }
    }
}

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by the Gadgeteer Designer.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerCamera
{
    public partial class Program : Gadgeteer.Program
    {
        // GTM.Module defintions
		Gadgeteer.Modules.GHIElectronics.Button button;
		Gadgeteer.Modules.GHIElectronics.Joystick joystick;

		public static void Main()
        {
			//Important to initialize the Mainboard first
            Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();			

            Program program = new Program();
			program.InitializeModules();
            program.ProgramStarted();
            program.Run(); // Starts Dispatcher
        }

        private void InitializeModules()
        {   
			// Initialize GTM.Modules and event handlers here.		
			joystick = new GTM.GHIElectronics.Joystick(10);
		
			button = new GTM.GHIElectronics.Button(11);

        }
    }
}


#2

If you look at the generated code, you will see that it expects a return from the ProgramStarted() and then it calls the Program.Run() method.

The ProgramStarted() method is not mean to be used as one of the threads of the program. It should only be used for initialization type stuff.

I find your code a bit confusing at first look. Instead of trying to decode your intent, I suggest you start with one function at a time and build up the program.

First, register the button pressed event, and see if your button pressed routine is called. Then do the same with the joystick button. Then you can start adding the manipulation of the button LED.


#3

Yes - I ran into this a couple of days ago -
you must leave ProgramStarted before events fire!

So - you’ll need to reorganize the code a bit - get rid of loop at end of ProgramStarted.

maybe use a timer or another event handler in place of the loop.


#4

Thanks. I’m not trying to accomplish anything - I just could not get the camera app in the intro to work - it never saw the button press.

I’ve pared everything down to the minimum. Even bypassed the designer - I added the button reference manually, did the simplest possible code, as below. With a breakpoint on the throw in the button pressed handler … nothing. No breakpoints ever trigger.

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;

namespace GadgeteerApp1
{
    public partial class Program
    {
        void ProgramStarted()
        {
            /******************************************************************************************
            Access modules defined in the designer by typing their name:                            
            
            e.g.  button
                  camera1

            Initialize event handlers here.
            e.g. button.ButtonPressed += new GTM.MSR.Button.ButtonEventHandler(button_ButtonPressed);             
            ***************************************************************************************** */

            // Do one-time tasks here
            Debug.Print("Program Started");
            GTM.GHIElectronics.Button button = new GTM.GHIElectronics.Button(11);

            button.ButtonPressed += new GTM.GHIElectronics.Button.ButtonEventHandler(button_ButtonPressed);
        }

        void button_ButtonPressed(GTM.GHIElectronics.Button sender, GTM.GHIElectronics.Button.ButtonState state)
        {
            throw new NotImplementedException();
        }
    }
}


#5

I don’t really know enough about the virtual machine to be sure - but your latest is unlawful code :slight_smile:

The variable “button” should be an instance variable - it could get disposed the way the code is currently written (although, I would expect garbage collection to take a good long while in this case).

I don’t think that really explains why you’re not seeing the event though. Perplexing…


#6

Oh - one more thing…

Try using port 4 or 8 rather than 11 - I was having trouble with 11 yesterday with an LED - it might be a generic problem and not just me :^)

Of course, I AM assuming you’ve checked your hardware setup and tried a couple of different cables, just in case…


#7

That was the ultras-pared-down version. The same thing happens if I make the same program with the designer. Just the spider, plus the button plugged into socket 11 (I’ve tried other sockets).

I’ve put the designer-based app in a public location. It would be great if someone else could try it for me.

https://skydrive.live.com/redir.aspx?cid=764a0b5ca1d11eb3&resid=764A0B5CA1D11EB3!293

GadgeteerApp1 is the no-designer version
GadgeteerApp2 is the designer created version

Phil


#8

@ HHoover - thanks.

Yep, I’ve tried both buttons and lots of sockets. I’ve also tried other peripherals … the joystick being the obvious first one (as it has a button). I just never seem to be able to get any events to fire off.

I [italic]MUST[/italic] be doing something dumb, but I have no idea what. It’s not like I’ve never done this before. I just came back from a business trip where I built a Panda-II based device that connects to a wagering terminal and watches for various conditions, then connects to a paging service to make remote notifications when something goes wrong. I have a bunch of devices on order to deploy a number of these, and I’ve done other projects.

I’m not trying to say I’m a genius, just that I’m feeling really stupid that I can’t make this work! :o :-[

Phil


#9

#10

can’t access the skydrive, but some typing will do…

using the generated version, I did one like yours, and get a press event each time…

Which is not really helping you much…


            Debug.Print("Program Started");

            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            Debug.Print("press");
        }


#11

Thanks. Yeah, I give up, at least for now. I’ll try some other peripherals and see what I can get.

On the spider, all switches are off, right?


#12

And yes - we all know how that feels… been there…

So - curiosity here - or more likely a board issue -
When I have the button on 11, and I replace ButtonPressed with:


        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            Debug.Print("press");
            if (button.IsLedOn)
            {
                button.TurnLEDOff();
            }
            else
            {
                button.TurnLEDOn();
            }
        }

The LED does not come on ever, - switch to port 4, and LED works!

time to pull out the voltmeter…


#13

Yes - all switches off.


#14

OK, it’s not me, but the plot thickens.

I added the joystick, per the code below. The joystick [italic]always[/italic] creates an event, but only on port 9, never on port 10.

I’ve done some more button testing. If I press the button hundreds of times, sometimes long, sometimes short, then every now and then (maybe 1 in 50 presses) the button will fire an event.

So, the button issue could be the known incorrect capacitor value causing issues with the glitch filtering, but the behaviour is wrong for that. I would expect that if that was the issue, pressing and holding the button for a long time would reliably cause it to activate. Time to drag the 'scope and logic analyser out, I guess!

[hint … circuit diagrams would help! I’ve got the gadgeteer standards somewhere…]

I have no idea why I couldn’t get the joystick to work before - I thought I tried it on both ports 9 and 10, but maybe I only tried 10. All very ‘flaky’, not like GHI at all!

Phil

        void ProgramStarted()
        {
            
            // Do one-time tasks here
            Debug.Print("Program Started");

            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
            joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);

            button.TurnLEDOn();
        }

        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            Debug.Print("press");
            button.ToggleLED();
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            Debug.Print("press");
            if (button.IsLedOn)
            {
                button.TurnLEDOff();
            }
            else
            {
                button.TurnLEDOn();
            }
        }
    }
}


#15

@ hhoover - do both buttons behave the same on port 11? (I’m assuming you bought the kit, of course).

If you add “button.TurnLEDOn();” to the ProgramStarted method, does the LED come on when the app starts?

I suspect your case is hardware (and I think mine is too, now), but that might be worth a quick test.

Phil.


#16

I only tried one of the switches -
however - I noticed with some further testing that the LED is ON - just very very dim… is that the case for you too?
same for ports 9, 10 and 11

–Hugh


#17

No, I don’t see the dim LEDs. I think that must be your hardware. LEDs are OK on all the ports.

The only weird port behaviour I have is the Joystick, which only works on port 9.

All my switches/LEDs work the same on all ports, the switches just work very rarely and very randomly. I’m convinced now that this is the time constant capacitor.


#18

Curious - and a bit disappointing… I was hoping it would be consistent between our boards…

I DO get timing inconsistencies on port 14 - on the rest, the button presses seem pretty consistent.


#19

Please see this http://tinyclr.com/forum/21/4373/