1
\$\begingroup\$

Recently I tried making an XBOX controller adapter for my PC as per these instructions. As I have very little electrical knowledge, immediately I ran into problems.

Connected everything as shown and using the code provided, nothing works, it doesn't turn on.

While using my own code, it works (somewhat):

int sync_pin = 2;
int data_pin = 3;
int clock_pin = 4;

int led_cmd[10] = {0,0,1,0,0,0,0,1,0,0};
int anim_cmd[10] = {0,0,1,0,0,0,0,1,0,1};
int sync_cmd[10] = {0,0,0,0,0,0,0,1,0,0};

void setup()
{                
    Serial.begin(9600);
    Serial.write("Initializing..");
    Init();
    SendData(anim_cmd, 7000);
}

void loop()
{

}

void SendData(int data[], int delay_ms)
{
    pinMode(data_pin, OUTPUT);
    digitalWrite(data_pin, LOW);

    int prev = 1;

    for (int i = 0; i < 10; i++)
{
        while (prev == digitalRead(clock_pin)) { }

        prev = digitalRead(clock_pin);
        digitalWrite(data_pin, byte(data[i]));

        while (prev == digitalRead(clock_pin)) { }

        prev = digitalRead(clock_pin);
    }

    digitalWrite(data_pin, HIGH);
    pinMode(data_pin, INPUT);
    delay(delay_ms);
}

void Init()
{
    pinMode(data_pin, INPUT);
    pinMode(clock_pin, INPUT);
    digitalWrite(clock_pin, HIGH); // SOMEHOW IT NEVER WORKS WITHOUT THIS LINE!!!

    SendData(led_cmd, 0);
    delay(50);
}

It turns on not every time. It syncs - at times.

The biggest problem is that whenever I touch the RF module or Arduino, or even when I wave my hand near it, the whole thing goes nuts. It starts blinking, turning on or off, and the Arduino restarts.

As I've mentioned, I'm new to electronics, so I've probably connected something wrong. All I did was directly connect the RF module to the pins on the Arduino. No resistors or diodes. Nothing. One thing I could think of was to shield the wires with some foil. :)

So if I didn't yet destroy my equipment, maybe somebody knows what could be done.

\$\endgroup\$
1
\$\begingroup\$

Okay, so I've found out what the problem was all along. As I've said, I connected everything directly. Because of that, the Arduino pins will sometimes start picking up electrical noises and change state as described in tutorial about digital pins

This also means however, that pins configured as pinMode(pin, INPUT) with nothing connected to them, or with wires connected to them that are not connected to other circuits, will report seemingly random changes in pin state, picking up electrical noise from the environment, or capacitively coupling the state of a nearby pin.

Thus adding a pullup resistor to each data pin resolved the problem.

| improve this answer | |
\$\endgroup\$

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