Digital I/O cannot work after integration

Hi,

I have a project which involves Arduino Uno, Annikken Andee and Adafruit motor shield. I am including a blinking LED into my project. To test the LED, i tried using the blinking LED programme in the Arduino library and it works fine. However, when i integrate the blinking LED programme into my main project programme, the digital I/O pins just wont react accordingly. I am suspecting that there is a clash of pins in the modules. Below is a part of my code.

#define LED 8 // define the pin of LED

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  
  AFMS.begin();
  motorR->setSpeed(127);
  motorL->setSpeed(127);

  Andee.begin();
  Andee.clear();
  setInitialData(); // Define object types and their appearance

  pinMode(LED, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

The blink example uses the LED on pin 13. Your code uses pin 8. Did you put a separate LED and resistor on pin 8?

Pete

I have tried using every digital I/O pins and connect the LED accordingly, but it would not work. Yes, the connection i have set is a simple LED with a resistor.

To add on, even if i did not configure the digital I/O pins i the setup loop and did not include the I/O pins in my main programme, some of the digital I/O pins give a constant HIGH output and LOW output.

Does anyone know what are the possible reasons for this?

Thank you for the help.

Change this line:

#define LED 8

to this:

#define LED LED_BUILTIN

Does the built in LED blink as it should?

BTW. The code you posted can't have been ALL of the code. Post it all.

Pete

Hi,
Are you connecting the LED the correct way round?

Check by connecting the LED and resistor between gnd and 5V.

Can you post links to your two shields please?
In particular WHICH Annikenn shield.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

Tom... :slight_smile:

To Pete:

Does the built in LED blink as it should?

It does not work as well. It gives the same result.

Apparently, i did some further troubleshooting and find out the fault lies in my setInitialData() in the setup. The initialising of the setInitialData() somehow "freezes" all of the digital I/O pins. The LED blinking works without the setInitialData() setup code.

My full code is quite long, hence i will just post my setInitialData() setup code which causes the problem.

void setup() {
 
  pinMode(LED, OUTPUT);

  Andee.begin();
  Andee.clear();
  setInitialData(); // Define object types and their appearance

void setInitialData() {
  UGVbutton1.setId(0);
  UGVbutton1.setType(BUTTON_IN);
  UGVbutton1.setLocation(0, 0, HALF);
  UGVbutton1.setTitle("UGV 1");
  UGVbutton1.setColor(LIGHT_SALMON);
  UGVbutton1.setTextColor(BLACK);
  UGVbutton1.requireAck(true);

  UGVbutton2.setId(1);
  UGVbutton2.setType(BUTTON_IN);
  UGVbutton2.setLocation(0, 1, HALF);
  UGVbutton2.setTitle("UGV 2");
  UGVbutton2.setColor(LIGHT_SALMON);
  UGVbutton2.setTextColor(BLACK);
  UGVbutton2.requireAck(true);

  tableButton1.setId(2);
  tableButton1.setType(BUTTON_IN);
  tableButton1.setLocation(2, 0, ONE_QUART);
  tableButton1.setTitle("Table 1");
  tableButton1.setColor(THEME_YELLOW);
  tableButton1.setTextColor(BLACK);
  tableButton1.requireAck(true);

  tableButton2.setId(3);
  tableButton2.setType(BUTTON_IN);
  tableButton2.setLocation(2, 1, ONE_QUART);
  tableButton2.setTitle("Table 2");
  tableButton2.setColor(THEME_YELLOW);
  tableButton2.setTextColor(BLACK);
  tableButton2.requireAck(true);

  tableButton3.setId(4);
  tableButton3.setType(BUTTON_IN);
  tableButton3.setLocation(2, 2, ONE_QUART);
  tableButton3.setTitle("Table 3");
  tableButton3.setColor(THEME_YELLOW);
  tableButton3.setTextColor(BLACK);
  tableButton3.requireAck(true);

  tableButton4.setId(5);
  tableButton4.setType(BUTTON_IN);
  tableButton4.setLocation(2, 3, ONE_QUART);
  tableButton4.setTitle("Table 4");
  tableButton4.setColor(THEME_YELLOW);
  tableButton4.setTextColor(BLACK);
  tableButton4.requireAck(true);

  tableButton5.setId(9);
  tableButton5.setType(BUTTON_IN);
  tableButton5.setLocation(2, 4, ONE_QUART);
  tableButton5.setTitle("Table 5");
  tableButton5.setColor(THEME_YELLOW);
  tableButton5.setTextColor(BLACK);
  tableButton5.requireAck(true);

  tableButton6.setId(10);
  tableButton6.setType(BUTTON_IN);
  tableButton6.setLocation(2, 5, ONE_QUART);
  tableButton6.setTitle("Table 6");
  tableButton6.setColor(THEME_YELLOW);
  tableButton6.setTextColor(BLACK);
  tableButton6.requireAck(true);

  tableButton7.setId(11);
  tableButton7.setType(BUTTON_IN);
  tableButton7.setLocation(2, 6, ONE_QUART);
  tableButton7.setTitle("Table 7");
  tableButton7.setColor(THEME_YELLOW);
  tableButton7.setTextColor(BLACK);
  tableButton7.requireAck(true);

  tableButton8.setId(12);
  tableButton8.setType(BUTTON_IN);
  tableButton8.setLocation(2, 7, ONE_QUART);
  tableButton8.setTitle("Table 8");
  tableButton8.setColor(THEME_YELLOW);
  tableButton8.setTextColor(BLACK);
  tableButton8.requireAck(true);

  tableButton9.setId(13);
  tableButton9.setType(BUTTON_IN);
  tableButton9.setLocation(2, 8, ONE_QUART);
  tableButton9.setTitle("Table 9");
  tableButton9.setColor(THEME_YELLOW);
  tableButton9.setTextColor(BLACK);
  tableButton9.requireAck(true);

  tableButton10.setId(14);
  tableButton10.setType(BUTTON_IN);
  tableButton10.setLocation(2, 9, ONE_QUART);
  tableButton10.setTitle("Table 10");
  tableButton10.setColor(THEME_YELLOW);
  tableButton10.setTextColor(BLACK);
  tableButton10.requireAck(true);

  sendButton.setId(6);
  sendButton.setType(BUTTON_IN);
  sendButton.setLocation(3, 0, HALF);
  sendButton.setTitle("Send");
  sendButton.setColor(THEME_GREY);
  sendButton.setTextColor(BLACK);
  sendButton.requireAck(true);

  returnButton.setId(7);
  returnButton.setType(BUTTON_IN);
  returnButton.setLocation(3, 1, HALF);
  returnButton.setTitle("Return");
  returnButton.setColor(THEME_GREY);
  returnButton.setTextColor(BLACK);
  returnButton.requireAck(true);

  locationStatus1.setId(8);
  locationStatus1.setType(DATA_OUT);
  locationStatus1.setLocation(1, 0, HALF);
  locationStatus1.setTitle("Location Status 1");
  locationStatus1.setData("Home");
  locationStatus1.setTextColor(BLACK);

  locationStatus2.setId(17);
  locationStatus2.setType(DATA_OUT);
  locationStatus2.setLocation(1, 1, HALF);
  locationStatus2.setTitle("Location Status 2");
  locationStatus2.setData("Home");
  locationStatus2.setTextColor(BLACK);
}

To Tom:
I am quite sure that there is no problem with my hardware. The problem lies with the setup code above which i have posted.

These are the products that i am using:
Adafruit Motor Shield v2.3 : Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit [v2.3] : ID 1438 : $19.95 : Adafruit Industries, Unique & fun DIY electronics and kits
Annikken Andee 2015 (android ver) : http://www.annikken.com/store/products/

I seem to found out the problem. It is the sequence of my programme. Previously, i place the blinking LED code at the start of the void loop(). When i change the coding to the end of the void loop() after my whole chunk of programme, it works. But i still don't understand why it does not work when i place it at the start of the void loop().

My programme is like this:

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps

  AFMS.begin();
  motorR->setSpeed(127);
  motorL->setSpeed(127);

  pinMode(LED, OUTPUT);

  Andee.begin();
  Andee.clear();
  setInitialData(); // Define object types and their appearance
}

void setInitialData()
{
  UGVbutton1.setId(0);
  UGVbutton1.setType(BUTTON_IN);
  UGVbutton1.setLocation(0, 0, HALF);
  UGVbutton1.setTitle("UGV 1");
  UGVbutton1.setColor(LIGHT_SALMON);
  UGVbutton1.setTextColor(BLACK);
  UGVbutton1.requireAck(true);

  UGVbutton2.setId(1);
  UGVbutton2.setType(BUTTON_IN);
  UGVbutton2.setLocation(0, 1, HALF);
  UGVbutton2.setTitle("UGV 2");
  UGVbutton2.setColor(LIGHT_SALMON);
  UGVbutton2.setTextColor(BLACK);
  UGVbutton2.requireAck(true);

  tableButton1.setId(2);
  tableButton1.setType(BUTTON_IN);
  tableButton1.setLocation(2, 0, ONE_QUART);
  tableButton1.setTitle("Table 1");
  tableButton1.setColor(THEME_YELLOW);
  tableButton1.setTextColor(BLACK);
  tableButton1.requireAck(true);

  tableButton2.setId(3);
  tableButton2.setType(BUTTON_IN);
  tableButton2.setLocation(2, 1, ONE_QUART);
  tableButton2.setTitle("Table 2");
  tableButton2.setColor(THEME_YELLOW);
  tableButton2.setTextColor(BLACK);
  tableButton2.requireAck(true);

  tableButton3.setId(4);
  tableButton3.setType(BUTTON_IN);
  tableButton3.setLocation(2, 2, ONE_QUART);
  tableButton3.setTitle("Table 3");
  tableButton3.setColor(THEME_YELLOW);
  tableButton3.setTextColor(BLACK);
  tableButton3.requireAck(true);

  tableButton4.setId(5);
  tableButton4.setType(BUTTON_IN);
  tableButton4.setLocation(2, 3, ONE_QUART);
  tableButton4.setTitle("Table 4");
  tableButton4.setColor(THEME_YELLOW);
  tableButton4.setTextColor(BLACK);
  tableButton4.requireAck(true);

  tableButton5.setId(9);
  tableButton5.setType(BUTTON_IN);
  tableButton5.setLocation(2, 4, ONE_QUART);
  tableButton5.setTitle("Table 5");
  tableButton5.setColor(THEME_YELLOW);
  tableButton5.setTextColor(BLACK);
  tableButton5.requireAck(true);

  tableButton6.setId(10);
  tableButton6.setType(BUTTON_IN);
  tableButton6.setLocation(2, 5, ONE_QUART);
  tableButton6.setTitle("Table 6");
  tableButton6.setColor(THEME_YELLOW);
  tableButton6.setTextColor(BLACK);
  tableButton6.requireAck(true);

  tableButton7.setId(11);
  tableButton7.setType(BUTTON_IN);
  tableButton7.setLocation(2, 6, ONE_QUART);
  tableButton7.setTitle("Table 7");
  tableButton7.setColor(THEME_YELLOW);
  tableButton7.setTextColor(BLACK);
  tableButton7.requireAck(true);

  tableButton8.setId(12);
  tableButton8.setType(BUTTON_IN);
  tableButton8.setLocation(2, 7, ONE_QUART);
  tableButton8.setTitle("Table 8");
  tableButton8.setColor(THEME_YELLOW);
  tableButton8.setTextColor(BLACK);
  tableButton8.requireAck(true);

  tableButton9.setId(13);
  tableButton9.setType(BUTTON_IN);
  tableButton9.setLocation(2, 8, ONE_QUART);
  tableButton9.setTitle("Table 9");
  tableButton9.setColor(THEME_YELLOW);
  tableButton9.setTextColor(BLACK);
  tableButton9.requireAck(true);

  tableButton10.setId(14);
  tableButton10.setType(BUTTON_IN);
  tableButton10.setLocation(2, 9, ONE_QUART);
  tableButton10.setTitle("Table 10");
  tableButton10.setColor(THEME_YELLOW);
  tableButton10.setTextColor(BLACK);
  tableButton10.requireAck(true);

  sendButton.setId(6);
  sendButton.setType(BUTTON_IN);
  sendButton.setLocation(3, 0, HALF);
  sendButton.setTitle("Send");
  sendButton.setColor(THEME_GREY);
  sendButton.setTextColor(BLACK);
  sendButton.requireAck(true);

  returnButton.setId(7);
  returnButton.setType(BUTTON_IN);
  returnButton.setLocation(3, 1, HALF);
  returnButton.setTitle("Return");
  returnButton.setColor(THEME_GREY);
  returnButton.setTextColor(BLACK);
  returnButton.requireAck(true);

  locationStatus1.setId(8);
  locationStatus1.setType(DATA_OUT);
  locationStatus1.setLocation(1, 0, HALF);
  locationStatus1.setTitle("Location Status 1");
  locationStatus1.setData("Home");
  locationStatus1.setTextColor(BLACK);

  locationStatus2.setId(17);
  locationStatus2.setType(DATA_OUT);
  locationStatus2.setLocation(1, 1, HALF);
  locationStatus2.setTitle("Location Status 2");
  locationStatus2.setData("Home");
  locationStatus2.setTextColor(BLACK);
}

void loop() {

  digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second


  if (UGVbutton1.isPressed())
  {
    UGVbutton1.ack();

    UGVbutton1.setColor(THEME_RED_DARK);
    UGVbutton2.setColor(LIGHT_SALMON);

    UGVSelect = 1;}



...............
...............
.................
................


  }

By right the LED light should still blink right, when i code it at the start of the main loop?

Have you notices something? All the things you have found are in bits of the code that you have not posted so no one but you has a chance of finding these.

[irony]
this is why we are happy to only look at part of your code and tell you what you have screwed up in the parts we can't see.
[/irony]