Button Issue

Hi all,

I received my unit yesterday and got things setup this afternoon with the SDK. I installed all the software and updated the firmware at the end of the SDK installation. I am attempting the “Getting Started with FEZ Spider” Camera application.

The issue is the button modules dont seem to register when i click them. I have tried both buttons that came with my kit. I have tried at least 10 different cables and I have adjusted the buttons to try sockets 4, 8 and 11. I got it to take about 3 pictures using the buttons but it took around 40-50 presses of the button for each of those allthough now I cannot get it to work at all. I did add the Debug.print(“Button Pressed”); line and it never displays when i press the button, well except for the one time it did work and I got a picture.

To test I installed the joystick and used the “joystick pressed” and that allows the application to function as expected with a picture taken after each press.

Due to the joystick working I think i have the code right, I can post the code if that would help but I think something else may be amiss.

Any thoughts on what my issue may be?

Thanks
Randy Towns

Can you please show your code that uses the button? Only button please.

Welcome to the community

We can turn on the LED on button module to make sure it is connected

+1. I have the same issue. Tried 2 different buttons, 4 different cables and 2 different slots (changing the program each time to register the correct slot). It has triggered perhaps once or twice in the course of 30 to 40 tests.

Also, I had to put a couple of delays in the ProgramStarted() method or mainboard thinks the camera is missing.

I got the camera to work without a button by using the timer class and event handler.

Like I suggested earlier, can you please show us the code you used and what socket you have the button plugged into?

We want to try to repro on our end.

…and welcome to the community.

Thanks Gus,

I copied the code directly from the “Getting started”

From Program.cs:


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

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

From Program.generated.cs:


namespace GadgeteerApp3
{
    public partial class Program : Gadgeteer.Program
    {
        // GTM.Module defintions
		Gadgeteer.Modules.GHIElectronics.Display_T35 display;
		Gadgeteer.Modules.GHIElectronics.UsbClientDP usbClient;
		Gadgeteer.Modules.GHIElectronics.Button button;
		Gadgeteer.Modules.GHIElectronics.Camera camera;
		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.		
			usbClient = new GTM.GHIElectronics.UsbClientDP(1);
		
			camera = new GTM.GHIElectronics.Camera(3);
		
			button = new GTM.GHIElectronics.Button(4);
		
			joystick = new GTM.GHIElectronics.Joystick(9);
		
			display = new GTM.GHIElectronics.Display_T35(14, 13, 12, 10);

        }
    }
}

Please let me know if you need something additional.

thanks
Randy Towns

I am able to toggle the button LED from the time handler just prior to taking the picture.

Show the complete code please. I still do not know what socket you have used and so I can’t try it here :slight_smile:

ok, ok :slight_smile:


       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);             
            ***************************************************************************************** */


            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
            camera.PictureCaptured +=new Camera.PictureCapturedEventHandler(camera_PictureCaptured);
            Debug.Print("Program Started");
            timer.Tick += new GT.Timer.TickEventHandler(timer_Tick);
            timer.Stop();
            display.SimpleGraphics.Clear();
            timer.Start();  //changed to turn the time on by default.



 
        }

        void timer_Tick(GT.Timer timer)
        {
            Debug.Print("Taking Picture");
            camera.TakePicture();
            button.ToggleLED();  //  this works
        }


        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            if (button.IsLedOn)
                timer.Stop();
            else
                timer.Start();

            button.ToggleLED();
        }
        

Edit: added code tag by admin

I updated my message above with the code.

Sorry I am a bit new at this so let me know if you need something additional.

Thanks for your help

Randy Towns

Keep it simple, start with printing a debug message from a button input instead of using timers. Dat is about to test some code he used to test it just now.

BTW, please use code tags so your code is readable. I edited your post.

I never got to the point with timers. It looks like the other person with the problem Markdev was experimenting with that in his code.

Thanks
Randy Towns

This is my code and it works fine. Can you please make new project and test with only button module?


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 Gadgeteer_Start
{
    public partial class Program
    {
        void ProgramStarted()
        {
            button.TurnLEDOn();
            button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
            Debug.Print("Program Started");
        }

        void button_ButtonPressed(Button sender, Button.ButtonState state)
        {
            Debug.Print("Hello I am a button!");
        }
    }
}

Thanks for taking a look.

Probably best to focus on rjtowns code since this is closer to the example code. I just shared my modification to show to take picture, display picture and toggle button LED could work from the timer event handler instead of the button pressed event.

I also added debug.print to the button handler and it does not get fired.

Just so we can get to finding out the answer. Did you make new project and use socket 4 for the button then you use the code provided by Dat and still no message is printed on output window?

I mean you see “Program Started” at beginning but you do not see “Hello I am a button!” when you press a button?

I got it to fire once (after about 5 presses - sometimes holding the button down for a while). Then nothing after that. both rapid, slow, hold down anything and no further messages…

Hope this helps!

And to answer your question - yes I am using slot 4. I see Program Started. I saw on “hello I am a button”. Then no further events

Is a harder press causing it to fire?

Hi Gus,

I just tried a new project and I used the code from Dat.

The buttons LED does come on. It does not show “Hello i am a button” when the button is pressed.

I tried both my buttons.

The buttons do have a lot of play in them, on the few times it did work it seemed i may have pushed the button at a weird angle but I cannot reproduce a putton press reliably. Well actually i havent been able to get a button press to work since I started this thread. Not sure why It worked those few times. I have tried pressing harder on the button with no luck.

Thanks
rt

no - I tried wiggling the button, firmly pressing it down, holding it and momentary presses.

Thigs that seem to be repeatable:
: first after 5 to 10 presses
: rapidly pressing the button, I can now get it to fire several times but not anywhere near every time (once every 5 or 6 rapid presses and very intermittent)

Update. I did get the “Hello I am a button!” Message after clicking the button numorus times in many directions and force. Havent found a consistent method to make it work.

It seems that rapidly pressing the button many times results in a press eventually. Allthough for me I am still needing to press 30+ times rapidly to get one “Hello i am a button!”

Markdav may be better a pressing the button than i am ;D