0

I have been experimenting with rpi in the last few days and made a simple user interface circuit, it contains a button and few LED's attached on top of rpi as you can see below.

It works fine but the blue LED connected to pin GPIO5 (physical pin 29) is always on (during and after boot) and it output 2.4V, why is it doing that and how can i disable it?

I have Ubuntu 14.04.4 LTS installed on it.

enter image description here

Edit:

gpio readall output:

 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 | ALT0 | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 | ALT0 | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI | ALT0 | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO | ALT0 | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK | ALT0 | 0 | 23 || 24 | 1 | ALT0 | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | ALT0 | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+

Also I just noticed that without connecting the circuit the reading is 3.15V instead of 2.4V.

Edit:

Schematics:

enter image description here

The LED's are red, blue, green and yellow in order from top to bottom. I put the capacitors in series by mistake, I meant to put them in parallel to get 220uF, it looked like too much work to desolder and resolder them so I left them as they are.

Source code:

#include <stdio.h>
#include <netdb.h>
#include <unistd.h>
#include <wiringPi.h>
#include "gpio.h"

#define PIN_INTERNET 7 /* GPIO4  */
#define PIN_BTN 2      /* GPIO27 */
#define PIN_BOOT 3     /* GPIO22 */
#define PIN_WOL 21     /* GPIO5  */
#define PIN_STATE 22   /* GPIO6  */
#define PIN_ERROR 25   /* GPIO26 */

int state = 0;
int disabled = 0;
int prevBtnState = HIGH;
long internetLastChecked = 0;

int isConnected()
{
    char *hostname = "google.com";
    return gethostbyname (hostname) != NULL;
}

void setup()
{
    pinMode (PIN_BOOT, OUTPUT);
    pinMode (PIN_INTERNET, OUTPUT);
    pinMode (PIN_WOL, OUTPUT);
    pinMode (PIN_STATE, INPUT);
    pullUpDnControl (PIN_STATE, PUD_UP);
    pinMode (PIN_BTN, INPUT);
    pullUpDnControl (PIN_BTN, PUD_UP);
    pinMode (PIN_ERROR, OUTPUT);

    /* Switch Green LED on to indicate successful boot up */
    digitalWrite (PIN_BOOT, HIGH);
    /* Switch Yellow LED on if internet connection available */
    digitalWrite (PIN_INTERNET, isConnected());
    digitalWrite (PIN_WOL, LOW);
    digitalWrite (PIN_ERROR, LOW);

    internetLastChecked = millis();
    state = 1;
}

void deactivate()
{
    digitalWrite (PIN_BOOT, LOW);
    digitalWrite (PIN_INTERNET, LOW);
    digitalWrite (PIN_WOL, LOW);
    digitalWrite (PIN_ERROR, LOW);
    disabled = 1;
}

void reactivate()
{
    digitalWrite (PIN_BOOT, HIGH);
    digitalWrite (PIN_INTERNET, isConnected());
    disabled = 0;
}

void reset()
{
    onError();
    digitalWrite (PIN_BOOT, LOW);
    digitalWrite (PIN_INTERNET, LOW);
    digitalWrite (PIN_WOL, LOW);
    digitalWrite (PIN_ERROR, LOW);
    pinMode (PIN_BOOT, INPUT);
    pinMode (PIN_INTERNET, INPUT);
    pinMode (PIN_WOL, INPUT);
    pinMode (PIN_ERROR, INPUT);
    pinMode (PIN_STATE, INPUT);
    pinMode (PIN_BTN, INPUT);
    state = 0;
}

int isBoardAttached()
{
    return digitalRead (PIN_STATE) == LOW;
}

int isBoardReady()
{
    return state && !disabled;
}

void onCommand()
{
    int i;
    if (!isBoardReady()) return;
    for (i = 0; i < 6; i++)
    {
        digitalWrite (PIN_WOL, HIGH);
        delay (100);
        digitalWrite (PIN_WOL, LOW);
        delay (100);
    }
}

void onError()
{
    int i;
    if (!isBoardReady()) return;
    for (i = 0; i < 3; i++)
    {
        digitalWrite (PIN_ERROR, HIGH);
        delay (200);
        digitalWrite (PIN_ERROR, LOW);
        delay (200);
    }
}

void onFatalError()
{
    if (isBoardReady()) digitalWrite (PIN_ERROR, HIGH);
}

void *gpioHandler (void *arg)
{
    int t = *((int *) arg);
    int btnState, connected;

    while (!quit)
    {
        if (!isBoardAttached())
        {
            printf ("Board is not connected ...\n");
            if (state == 1) reset();
            delay (10 * 1000);
            continue;
        }
        if (state == 0)
        {
            setup();
            printf ("Board is connected.\n");
            onCommand();
        }
        /* Disable/Enable board depending on btn state */
        if ((btnState = digitalRead (PIN_BTN)) == LOW && prevBtnState == HIGH)
        {
            disabled ? reactivate() : deactivate();
            printf ("Powering %s...\n", (disabled ? "off" : "on"));
        }
        prevBtnState = btnState;
        /* If board is deactivated wait until reactivated */
        if (disabled)
        {
            delay (t);
            continue;
        }
        /* Check internet connection every 1 second */
        if (millis() - internetLastChecked > 5000)
        {
            connected = isConnected();
            digitalWrite (PIN_INTERNET, connected);
            internetLastChecked = millis();
        }
        delay (t);
    }
    reset();
    pthread_exit (NULL);
}

int initGPIO()
{
    return wiringPiSetup();
}

The gpioHandler function is a thread handler which is created using pthread_create in the main file.

8
  • You're going to need to add a lot of detail to your question for anyone to have a chance in hell of answering. What's the circuit? Have you manipulated any of the GPIO pins? Is there a script running?
    – Jacobm001
    Jun 1, 2016 at 23:06
  • I can add the schematics of the circuit and the script but I don't think it would be helpful because it also happens when the circuit is not attached to the board and before I run the script. That pin is always on.
    – razzak
    Jun 1, 2016 at 23:12
  • @razzak run gpio readall and post into your question. PS I always wince when I see pictures of people poking multimeter leads inside things - this is a great way to short stuff.
    – Milliways
    Jun 2, 2016 at 0:18
  • @Milliways I don't usually poke around with the meter like this unless I'm too lazy :D. I posted the gpio readall command output, looks like it's set as a pull-up pin?
    – razzak
    Jun 2, 2016 at 0:47
  • @razzak In which case 2.4V seems normal.
    – Milliways
    Jun 2, 2016 at 0:52

1 Answer 1

1

Your code won't run - you don't even have a main() and never call wiringPiSetup.

I can't figure out what your circuit is even trying to achieve.

You have to make up your mind whether you are asking a question about gpio pins or how to write a threaded program (which doesn't belong on this site).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.