Pages: [1]   Go Down
Author Topic: only 1V on output  (Read 652 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I wasn't  sure if this is hardware or software error. The problem is that on digital output of my atmega1284 i only have 1V when it's set to HIGH. I only have this problem with this code
Code:
int tlac=digitalRead(12);
int naraz=digitalRead(5);

void rovno(){
 digitalWrite(3, HIGH);
 digitalWrite(4, LOW);
 digitalWrite(6, LOW);
 digitalWrite(7, HIGH);
 Serial.println(5);
 delay(10);
}

void vzad(){
 digitalWrite(3, LOW);
 digitalWrite(4, HIGH);
 digitalWrite(6, HIGH);
 digitalWrite(7, LOW);
}

void vlavo(){
 digitalWrite(3, HIGH);
 digitalWrite(4, LOW);
 digitalWrite(6, LOW);
 digitalWrite(7, LOW);
 Serial.println(4);
 delay(10);
}

void vpravo(){
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(6, LOW);
 digitalWrite(7, HIGH);
 Serial.println(6);
 delay(10);
}

void stoj(){
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(6, LOW);
 digitalWrite(7, LOW);
}

void vlavo90(){
 digitalWrite(3, HIGH);
 digitalWrite(4, LOW);
 digitalWrite(6, HIGH);
 digitalWrite(7, LOW);
 Serial.println(3);
 delay(10);
 delay(10);
}

void vpravo90(){
  digitalWrite(3,LOW);
  digitalWrite(4,HIGH);
  digitalWrite(6,LOW);
  digitalWrite(7,HIGH);
  Serial.println(7);
  delay(10);
}

void kalibracia(){
 
}

void prekazka(){
  int s1=digitalRead(15);
  int s2=digitalRead(16);
  int s3=digitalRead(17);
  int s4=digitalRead(18);
  int s5=digitalRead(19);
  int s6=digitalRead(20);
  int s7=digitalRead(21);
  int s8=digitalRead(22);
  int s9=digitalRead(23);
  vlavo90();
  delay(275);
  while (s1==1 || s2==1 || s3==1 || s4==1 || s5==1 || s6==1 || s7==1 || s8==1 || s9==1){
    float volts = analogRead(A0)*0.0048828125;
    float distance = 13*pow(volts, -0.9);
    if (distance < 6) {
      vlavo();
      prekazka();
    }
    if (distance > 6 && distance < 11) {
      rovno();
      prekazka();
    }
    if (distance > 11) {
      vpravo();
      prekazka();
    }
  }
}
 
void rovinka(){
  int s6a=analogRead(A2);
  int s4a=analogRead(A1);
  analogWrite(3,255);
  analogWrite(6,255);
}
 
void vlavomimo(){
  int s1=digitalRead(15);
  int s2=digitalRead(16);
  int s3=digitalRead(17);
  int s4=digitalRead(18);
  int s5=digitalRead(19);
  int s6=digitalRead(20);
  int s7=digitalRead(21);
  int s8=digitalRead(22);
  int s9=digitalRead(23);
  while (s2==0 || s3==0 || s4==0 || s5==0 || s6==0 || s7==0 || s8==0 || s9==0){
  vlavo();
  delay(10);
  rovno();
  }
}

void vpravomimo(){
  int s1=digitalRead(15);
  int s2=digitalRead(16);
  int s3=digitalRead(17);
  int s4=digitalRead(18);
  int s5=digitalRead(19);
  int s6=digitalRead(20);
  int s7=digitalRead(21);
  int s8=digitalRead(22);
  int s9=digitalRead(23);
  while (s2==0 || s3==0 || s4==0 || s5==0 || s6==0 || s7==0 || s8==0 || s1==0){
  vpravo();
  delay(10);
  rovno();
  }
}

void setup(){
  while (millis() == 5000) {
    if (tlac == HIGH) kalibracia();
  }
  Serial.begin(9600);
}



void loop() {
  int s1=digitalRead(15);
  int s2=digitalRead(16);
  int s3=digitalRead(17);
  int s4=digitalRead(18);
  int s5=digitalRead(19);
  int s6=digitalRead(20);
  int s7=digitalRead(21);
  int s8=digitalRead(22);
  int s9=digitalRead(23);
 //if (naraz==HIGH) prekazka();
 if (s5==0) rovno(); //0 cierna, 1 biela
 else { if (s4==0) vlavo();
 else { if (s6==0) vpravo();
 else { if (s3==0) vlavo();
 else { if (s7==0) vpravo();
 else { if (s2==0) vlavo90();
 else { if (s8==0) vpravo90();
 else { if (s1==0) vlavomimo();
 else { if (s9==0) vpravomimo();
}}}}}}}}}

The problem is with voids rovno, vlavo ,vpravo, vpravo90 and vlavo90. all of them are for digital pins 3,4,6,7. when i messure them with multimeter i get 1V however when there is only rovno() in void loop it is working fine. i appreciate your help.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27144
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

Where do you have the equivalent of this? It's usually in void setup():

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
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.

Queens, New York
Online Online
Faraday Member
**
Karma: 101
Posts: 3651
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe because they are switching too fast to get a proper voltage reading. Also your missing some pinModes for those stepper pins. "hint", They go somewhere in setup().

Edit: Just saw CrossRoads post, looks like were both on the same track.
« Last Edit: March 18, 2013, 07:45:19 am by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where do you have the equivalent of this? It's usually in void setup():

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

thanks that was problem. I forgot something so basic  smiley-roll-sweat
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27144
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

It happens. You're not the first, nor will you be the last smiley-wink
I once spent a couple hours trying to get the status light to do what I wanted - eventually realized that I also had SPI transfers going on which taken over control of D13 (SCK). Slap in the head for that one!
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.

Westbrook, CT
Offline Offline
Full Member
***
Karma: 2
Posts: 139
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to add the pinMode() function in the setup. By defualt, if you are not going to pinMode() it, the pin would output a small voltage on its HIGH instead of 5Volts.
« Last Edit: March 18, 2013, 10:05:56 am by mixania » Logged

Arduino Uno R3
Mac OSX Lion


Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 627
Posts: 34246
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have to add the pinMode() function in the setup. By defualt, if you are not going to pinMode() it, the pin would output a small voltage on its HIGH instead of 5Volts.
No if you don't define a pin as an output then it is an input. Then when you switch it high and low all you are doing is turning the pull up resistor on or off. As this is about 30K then any load will appear to reduce the output voltage.
Logged

Pages: [1]   Go Up
Jump to: