microsoft / pxt-maker

MakeCode target for "Maker" boards (beta)
https://maker.makecode.com/
Other
120 stars 82 forks source link

RedBoard Turbo w/ Buttons #193

Open bboyho opened 5 years ago

bboyho commented 5 years ago

Describe the bug There seems to be no internal pull-up resistor for a button press leaving any button floating as shown in the simulator. I'm not sure if we would need to include an image of a pull-up resistor in the simulator just like the LED's current limiting resistor for those that happen to use a button/switch?

To Reproduce When attaching a momentary push button on any I/O pin, the pin is floating.

  1. Drag the logic > if then code block in to the forever.
  2. Drag and set button D8 is pressed into the if's condition statement.
  3. Drag and set pin > digital write pin LED to HIGH as the result.
  4. Drag and set pin > digital write pin LED to LOW under the else's result.

This can be fixed with a physical pull-up resistor to the 3.3V pin or setting the pin as an internal pull-up code block (i.e. set pull pin ____ to up). That might be more work than necessary since it depends on the setup. It will probably just need an example for documentation instead of having it in the simulator?

Expected behavior Pushing a button should turn on the built-in LED on pin 13. When the button is not pressed, the LED should remain off.

Screenshots https://makecode.com/_FiU3hK5AADCW

Desktop (please complete the following information):

pelikhan commented 5 years ago

This "set pull pin up" happens implicitely when using the pin as a button.

In https://github.com/Microsoft/pxt-maker/blob/master/libs/sparkfun-samd21-dev-breakout/device.d.ts#L181, the button is configured as active low / pull up. And in the button constructor (https://github.com/lancaster-university/codal-core/blob/master/source/drivers/Button.cpp#L55 ), the pull is set on the pin.

Are you observing an incorrect behavior on hardware?

bboyho commented 5 years ago

Yeah, I am observing a different behavior. If the button is not being pressed down, the pin is floating. It just needs an internal pullup resistor in the setup function =>https://makecode.com/_d9L8hHDdHTHJ .

The wiring diagram in the simulator seemed misleading if the internal pullup resistor was not included. Seems more like a minor detail.

pelikhan commented 5 years ago

Ok i see now the confusion. When using "button D2 is pressed", we automatically set the pull up on the pin. However we use pin digital read, we don't set any pull. The simulator should reflect that.

pelikhan commented 5 years ago

So "button D8 is pressed" set the pull up, "pin D8 digital read" does not set any pull.

bboyho commented 5 years ago

To clarify, the first example using D8 did not have an internal pull-up resistor in the setup so the button read was floating. The wiring diagram in the simulator seemed misleading if the internal pullup resistor was not included.

The second example using D2 utilized the internal pull-up resistor in the setup so the button read worked as expected. The simulator was fine since we were using an internal pull-up resistor.

pelikhan commented 5 years ago

“button D8 is pressed” does set the pull up on D8 (it should at least. I’ll check with a scope.

Get Outlook for iOShttps://aka.ms/o0ukef


From: bboyho notifications@github.com Sent: Friday, March 1, 2019 12:55:34 PM To: Microsoft/pxt-maker Cc: Peli de Halleux; Assign Subject: Re: [Microsoft/pxt-maker] RedBoard Turbo w/ Buttons (#193)

To clarify, the first example using D8 did not have an internal pull-up resistor in the setup so the button read was floating. The wiring diagram in the simulator seemed misleading if the internal pullup resistor was not included.

The second example using D2 utilized the internal pull-up resistor in the setup so the button read worked as expected. The simulator was fine since we were using an internal pull-up resistor.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHubhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMicrosoft%2Fpxt-maker%2Fissues%2F193%23issuecomment-468808603&data=02%7C01%7Cjhalleux%40microsoft.com%7C0bd1b38ec70345105f0008d69e88403d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636870705377276810&sdata=N2pNM1%2BR%2BaVOnpvpmgIY59fe%2B%2Fe6sps%2F%2F2sqIV1%2FDT8%3D&reserved=0, or mute the threadhttps://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAD-4KfMmlKwv52V-oRE6Y6RFqWpWvmOyks5vSZPGgaJpZM4bWWb3&data=02%7C01%7Cjhalleux%40microsoft.com%7C0bd1b38ec70345105f0008d69e88403d%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636870705377433065&sdata=FWTk4dM%2FEVuntn4RS6pKmfjpOJMiJcyH89qat4uJWAs%3D&reserved=0.