Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #93 #167

Merged
merged 12 commits into from
Sep 17, 2017
55 changes: 55 additions & 0 deletions API/Hardware_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,61 @@ If you're newer to hardware and these functions look like alphabet soup to you,

By default, all of the pins are pulled high if not specifically set.

### Pullup and Pulldown pins

Pins 2-7 on both Ports are available for pullup and pulldown.

The basic function of a pull-up resistor is to insure that given no other input, a circuit assumes a default value. The 'pullup' mode pulls the line high and the 'pulldown' mode pulls it low.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice description. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: "insure" -> "ensure"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, this is a lovely description. Can you add "pullup" and "pulldown" to the docs glossary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


### Usage
```js
// Invoke this method to set the pull mode. pullType can be - pullup, pulldown or none.
pin.pull(pullType, callback);
```

Example of the `pin.pull(mode)` command using a pushbutton. The code example given below turns on the Blue LED of the Tessel module when the pushbutton is pressed and turns off the Blue LED when the pushbutton is released.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should just say Example: to stay consistent with the other Usage documentation. Then link to Tutorial page after the example, i.e.:

[Learn more about using the Pullup / Pulldown API.](/Tutorials/pinpull.html)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


```js
var tessel= require('tessel'); // Import Tessel

var pin = tessel.port.A.pin[2]; // Select pin 2 on port A

var pullType = "pullup"; // Set the mode of `pin.pull to pullup`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to single quotes, 'pullup' instead of "pullup", to keep it consistent in the sample code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (This code now resides in Tutorials)


var led = tessel.led[3]; // Blue LED of Tessel

pin.pull(pullType,(error, buffer) => { // Pin 2 pulled high
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what the value of that buffer should be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're trying to check manually by making the circuit.


if (error){
throw error;
}
});

setInterval({
pin.read(function(error, number){

if (error) {
throw error;
}

// Pin 2 reads high when the pushbutton is not pressed since it is pulled up
console.log(number);
if (number == 1){
led.off();
}

// Pin 2 reads low when the pushbutton is pressed since its connection with ground gets complete
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest changing phrasing "gets complete" to "is completed"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (The code now resides in "Tutorials")

else{
led.on();
}

});

}, 500);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this setInterval and led example code is out of scope for the API documentation. Just showing:

var tessel= require('tessel'); // Import Tessel

var pin = tessel.port.A.pin[2]; // Select pin 2 on port A

pin.pull('pullup', (error, buffer) => { // Pin 2 pulled high
  if (error) {
    throw error;
  }
  console.log(buffer.toString()) // what should this be?
}

displays how pin.pull is called with all its arguments. The rest of the example code is great for the Tutorial page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks better for a basic code demonstration :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screenshot 2017-08-21 20 55 56

We are getting the output as shown above when we are trying to print the value of buffer.

```



### Digital pins

A digital pin is either high (on/3.3V) or low (off/0V). Any pin on both ports A and B, other than 3.3V and GND, can be used be used as a digital pin. All pins are pulled high to 3.3V by default.
Expand Down
49 changes: 49 additions & 0 deletions Tutorials/pinpull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Pull- Pins

Suppose a pin is configured as an input. If nothing is connected to the pin and the program tries to read the state of the pin, it would be in a 'floating' state i.e an unknown state. To prevent this, a pull-up or a pull-down state is defined. They are often used in the case of Buttons and Switches.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"pull-up" and "pullup" are both used in this PR, but it would be better to choose a standard. I think hyphenated is standard, but haven't researched this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed. Hyphenated is standard. Will edit it everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hyphenated is now used in the text as per wikipedia (https://en.wikipedia.org/wiki/Pull-up_resistor) but non-hyphenated is the default arg value in the firmware, so we can't change it in the text.


Pins 2-7 on both the Ports are available for interrupts.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...available for interrupts" – did you mean to say pull-up and pull-down instead of interrupts?


Take a look at the following circuit. The code example given below turns on the Blue LED of the Tessel module when the pushbutton is pressed and turns off the Blue LED when the pushbutton is released.

![Pin-Pull using Push buttons](http://i.imgur.com/OYJZ8Dp.jpg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Fritzing! 👏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! @mittalshravika at it :)


```js
var tessel= require('tessel'); // Import Tessel

var pin = tessel.port.A.pin[2]; // Select pin 2 on port A

var pullType = "pullup"; // Set the mode of `pin.pull to pullup`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"pullup" vs "pull-up" in comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"pullup" is the default arg value as defined in the t2-firmware code here : https://github.com/tessel/t2-firmware/blob/master/node/tessel-export.js#L737-L758

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backtick is in the wrong place, should end backtick quotes after pin.pull

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


var led = tessel.led[3]; // Blue LED of Tessel

pin.pull(pullType,(error, buffer) => { // Pin 2 pulled high

if (error){
throw error;
}
});

setInterval({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setInterval accepts a function as the first argument to be called at the interval of time set as the second argument. https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval#Example_1_Basic_syntax

To fix this:

setInterval(() => {
  ... // call pin.read
}, 500);

Copy link
Contributor Author

@brihijoshi brihijoshi Aug 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! :)

pin.read(function(error, number){

if (error) {
throw error;
}

// Pin 2 reads high when the pushbutton is not pressed since it is pulled up
console.log(number);
if (number == 1){
led.off();
}

// Pin 2 reads low when the pushbutton is pressed since its connection with ground gets complete
else{
led.on();
}

});

}, 500);
```
[More Information on Pull-up pins and resistors](https://learn.sparkfun.com/tutorials/pull-up-resistors)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Information should not be capitalized

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional, might be useful to mention that the link goes to Sparkfun or otherwise designate it as an external (non-Tessel) link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)