0

I am building a small project that uses a pair of 8x8 LED matrix (driven by the MAX7219), a pair of SG90 servos, a HC-SR04 ultrasonic sensor, a 16x2 LCD (Hitachi HD44780 driver), some push buttons and all controlled with the Arduino Uno. All the components are powered using another usb port on my pc.

When I tried intergrating all the compenents, I noticed the LED matrix does not light up at all. I've decided to combine serveral basic code samples to test their interaction with eachother, where i noticed the use of pinMode to declare my pins for the push buttons will cause the LED matrix to stop working. Removing the section using // will get the led matrix(s) to work again.

Does anyone have any experience with this issue and can explain to me what causes this conflict? I've tried going through the LedControl documentation on the arduino page and I still could not understand what causes this issue.

/*

test build for debug

log:

LED Matrix : test code added, no issues
LCD Display: test code added, no issues
Sensor: test code added, serial clashed with LED Matrix. Working with disabled serial, Main build still not resolved.
Servo: test code added, no issues
Buttons: test code added, LED Matrix no longer light up. issue appears to be at the (pinMode) section when declaring buttons as inputs.


*/

//buttons

#include <Button.h>


const int positiveButtonPin = A1;
 int positiveButtonState = LOW;

const int negativeButtonPin = A2;
 int negativeButtonState = LOW;


// servo library setup
#include <Servo.h>
Servo servo1;
Servo servo2;


// lcd setup
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//led matrix library setup
#include "LedControl.h"
LedControl lc=LedControl(2,1,0,2);  // Pins: DIN,CLK,CS, # of Display connected
unsigned long delayTime=200;  // Delay between Frames

// sensor setup
const int trigPin = 6;
const int echoPin = 5;
long duration;
int distance;


// led matrix arrays (test with 2 formats)

byte invader1a[] = {0x7C,0x7C,0x60,0x7C,0x7C,0x60,0x7C,0x7C};

byte invader1b[] = {0x78,0x7C,0x66,0x66,0x66,0x66,0x7C,0x78};

byte invader2a[] =
{
  B00100100, // First frame of invader #2
  B00100100,
  B01111110,
  B11011011,
  B11111111,
  B11111111,
  B10100101,
  B00100100
};

byte invader2b[] =
{
  B00100100, // Second frame of invader #2
  B10100101,
  B11111111,
  B11011011,
  B11111111,
  B01111110,
  B00100100,
  B01000010
};



void setup() {
  // put your setup code here, to run once:


//button setup
{
//  pinMode(positiveButtonState, INPUT);                    //         <----------------- THIS CAUSES ISSUE WITH LED MATRIX
//  pinMode(negativeButtonState, INPUT);
}

// servo setup
  servo1.attach(4);
  servo2.attach(3);



//sensor serial test code       
// sensor setup
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
//  Serial.begin(9600);                                         //     <----------------- THIS CAUSES ISSUE WITH LED MATRIX, DISABLED

    //led matrix setup
  lc.shutdown(0,false);  // Wake up displays
  lc.shutdown(1,false);
  lc.setIntensity(0,2);  // Set intensity levels
  lc.setIntensity(1,2);
  lc.clearDisplay(0);  // Clear Displays
  lc.clearDisplay(1);


    //lcd hello world code
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");


}


//  Creating array strings

void sinvader1a()
{
  for (int i = 0; i < 8; i++)  
  {
    lc.setRow(0,i,invader1a[i]);
  }
}

void sinvader1b()
{
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0,i,invader1b[i]);
  }
}

void sinvader2a()
{
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(1,i,invader2a[i]);
  }
}

void sinvader2b()
{
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(1,i,invader2b[i]);
  }
}



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

//servo test code
    // servo attach
    servo1.attach(4);
    servo2.attach(3);


     servo1.write (120);  // change angle here below. adjust until it looks like it's looking at user
  servo2.write (90);
  delay(250);
  servo1.write (90);
  servo2.write (120);
  delay(250);
// servo detach to reduce noise
servo1.detach();
servo2.detach();


// led matrix test code
    sinvader1a();
    delay(delayTime);
    sinvader2a();
    delay(delayTime);

    sinvader1b();
    delay(delayTime);
    sinvader2b();
    delay(delayTime);

    //lcd hello world code 
    // set the cursor to column 0, line 1
      // (note: line 1 is the second row, since counting begins with 0):
      lcd.setCursor(0, 1);
      // print the number of seconds since reset:
      lcd.print(millis() / 1000);

//sensor test code
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance= duration*0.034/2;


// no longer useful due to disabled serial
/*
if (distance<1000){
Serial.print("Distance: ");
Serial.println(distance);}
else {}
*/

}
  • please reduce your code to the minimal amount of code that still exhibits the undesired behaviour. – jsotola May 28 '18 at 16:41
  • 1. Consider the basic USB port is only required to supply 500mA. It should be expected that a computer, to protect its self, would reduce the USB voltage if this current limit was violated. 2. All Arduino libraries are not compatible with one another. Unless the library author was kind enough / thorough enough to document what hardware is used, the only way to tell is to look at the library source code. – st2000 May 28 '18 at 18:16
  • You also did not specify which Arduino you were using. – st2000 May 28 '18 at 18:27
1

It appears you are attempting to use the hardware UART for both talking to your MAX7221 or MAX7219:

LedControl lc=LedControl(2,1,0,2);

And for talking to, maybe, the SDK's serial monitor:

Serial.begin(9600);

There is only 1 UART on the Atmel processor used on an Arduino Uno. Consider using a larger Arduino / processor where there are more UARTs on the processor. Be aware that it may be necessary to re-write the library to use the alternative hardware on larger processors.

Also, there is an error in your code and it is causing you to think about it incorrectly:

The lines:

pinMode(positiveButtonState, INPUT);
pinMode(negativeButtonState, INPUT);

...interfere with the LED matrix because they are changing pin zero from a UART Receive to a GPIO Receive. Likely you meant to type:

pinMode(positiveButtonPin, INPUT);
pinMode(negativeButtonPin, INPUT);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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