Pages: [1] 2 3 4   Go Down
Author Topic: Is it possible to use the digital OUTs as INs? [SOLVED]  (Read 3199 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?



Final answers:
1. http://arduino.cc/forum/index.php/topic,125731.msg946047.html#msg946047
2. http://arduino.cc/forum/index.php/topic,125731.msg946400.html#msg946400
« Last Edit: October 06, 2012, 07:42:35 am by MDTech-us_MAN » Logged

Maxwell D.

Owner and Webmaster of www.MDTech.us

Offline Offline
Newbie
*
Karma: 1
Posts: 35
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are asking if they could be used as inputs and outputs, then yes all you have to do is say if it is an input or output in the void setup, here is more http://arduino.cc/en/Reference/Setup
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As jonathanped said, they can be used for either input or output.  You have to call the pinMode function

So to make digital pin 10 an input
pinMode(10, INPUT);

To set it for output
pinMode(10, OUTPUT);

One thing to add though is that it doesn't have to happen in the setup function but almost always that is where you want to set it.   It can be set anywhere at anytime and you can even change the mode in the same program.  This is rare however and the only time I can think when one does this is with the PING sensor which requires you to send and receive a signal on the same pin.

Hope that doesn't add to the confusion.  smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, how do I print "0" or "1" if the button on pin 53 is pressed and the other number if not.
Logged

Maxwell D.

Owner and Webmaster of www.MDTech.us

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3350
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, how do I print "0" or "1" if the button on pin 53 is pressed and the other number if not.

Have you looked at any of the examples that come with the Arduino software?
Logged

Offline Offline
Edison Member
*
Karma: 29
Posts: 2345
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you tried a felt / marker type pen?


"Ok, how do I print "0" or "1" if the button on pin 53"

pin 53? if (digitalRead(53)==true)
 {
    Serial.println("Pin 53 is true");
 //sort of, is it printlin or writeln, i can never remember unless front of the IDE.
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

it IS println I'm currently testing that...
Logged

Maxwell D.

Owner and Webmaster of www.MDTech.us

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (digitalRead(53)==true)
 {
    Serial.println("Pin 53 is true");
 //sort of, is it printlin or writeln, i can never remember unless front of the IDE.
}
The digitalRead() function returns HIGH or LOW, not true or false. If you are going to do an explicit compare, as you should, then use the right thing on the other side of the equality operator.
Logged

Wiscon
Offline Offline
Newbie
*
Karma: 1
Posts: 22
Admin whatisacnc.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?

First choose the programming language you want to use for building an interface (GUI).
Second you set the I/O as either "high" or "low" to receive and send data, so if you wanted to use I/O Number 9 to turn a servo motor either right or left you can do it pretty easily.

Here is some VB.NET 2010 code for the computer side, AKA your GUI.

All you need are two buttons...

Imports System.IO
Imports System.IO.Ports
Imports System.Threading

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With SerialPort1
            SerialPort1.Close()
            SerialPort1.PortName = "com4" 'change com port to match your Arduino port
            SerialPort1.BaudRate = 9600
            SerialPort1.DataBits = 8
            SerialPort1.Parity = Parity.None
            SerialPort1.StopBits = StopBits.One
            SerialPort1.Handshake = Handshake.None
            SerialPort1.Encoding = System.Text.Encoding.Default 'very important!

        End With

    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        SerialPort1.Open()
        SerialPort1.Write("3")
        SerialPort1.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SerialPort1.Open()
        SerialPort1.Write("4")
        SerialPort1.Close()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        End
    End Sub


As you can see the "SerialPort1.Write("4")" and "SerialPort1.Write("3")"  under each button are the commands being sent to the Arduino threw USB in the form of a packet.
As you can imagine the sketch has the number 3 and 4 defined as I/O 9 and each one moves the motor 180 degrees from each other.

Hope this helps,

Rob
http://whatisacnc.com   
Logged

http://whatisacnc.com
The frustration of a CNC

Austin, TX
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6106
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?

First choose the programming language you want to use for building an interface (GUI).
...
Here is some VB.NET 2010 code for the computer side, AKA your GUI.
What on earth does this have to do with the original poster's question?
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

Wiscon
Offline Offline
Newbie
*
Karma: 1
Posts: 22
Admin whatisacnc.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?

First choose the programming language you want to use for building an interface (GUI).
...
Here is some VB.NET 2010 code for the computer side, AKA your GUI.
What on earth does this have to do with the original poster's question?

How does it not relate to the posters question?
I am saying yes you can "use the pins named "DIGITAL" as digital INs"
At least this is my take on it, maybe I am wrong?
Whats the problem?
Logged

http://whatisacnc.com
The frustration of a CNC

Offline Offline
Jr. Member
**
Karma: 2
Posts: 69
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How does it not relate to the posters question?
I am saying yes you can "use the pins named "DIGITAL" as digital INs"
At least this is my take on it, maybe I am wrong?
Whats the problem?

The original poster was asking if an Arduino sketch that can perform digital reads on the digital pins.   You stated you need a GUI front end and then proceeded to give him a Visual Basic program that talks over the serial port (and you left out the corresponding sketch to boot).
 
Discussing a GUI front end in VB it is about as far away from "is it possible to use the pins named "DIGITAL" as digital INs" as one can get.

Not trying to be a jerk about it but your post is a bit off topic.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello ALL,

How is it possible to use the pins named "DIGITAL" as digital INs?

First choose the programming language you want to use for building an interface (GUI).
...
Here is some VB.NET 2010 code for the computer side, AKA your GUI.
What on earth does this have to do with the original poster's question?

How does it not relate to the posters question?
I am saying yes you can "use the pins named "DIGITAL" as digital INs"
At least this is my take on it, maybe I am wrong?
Whats the problem?

YES, Thanks for the VB code! (I would need it later any way), but, I need the -> ARDUINO <- code now.

I need to accurately print the current state of the button (1 if pressed, 0 if not). If I use:
Code:
Serial.println(digitalRead(53));
I get a VERY in accurate result (takes time to switch from 0 to 1 (first a couple 1s here and there then more and more and finally everything is 1)).
Is the a better way?!

Setup code:
Code:
Serial.begin(9600);
pinMode(53, INPUT);

Maxwell D.

EDIT: Now I get ALL 0s:
Code:
0
0
0
0
...
0
0
0

Entire code:
Code:
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(53, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(digitalRead(53));
}
« Last Edit: October 05, 2012, 01:12:13 pm by MDTech-us_MAN » Logged

Maxwell D.

Owner and Webmaster of www.MDTech.us

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 285
Posts: 25638
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How is the switch on pin 53 connected.
You're not using the built-in pull ups; what else have you got on that pin?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 515
Posts: 26261
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

internal pullups:
Code:
  Serial.begin(9600);
  pinMode(53, INPUT);// assumes switch closure connects pin to Gnd
digitalWrite (53, HIGH); 


// IDE 1.0.1 also supports:
pinMode(53, INPUT_PULLUP); // seperate digitalWrite not needed
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Pages: [1] 2 3 4   Go Up
Jump to: