I am currently using a UNO including a Waveshare LCD1602 RGB Module. When I plug it into the UNO on the 3.3V, ground, SDA and SCL pins it works absolutely fine. I try and plug it into the Leonardo and it goes to a blank screen and I can never get it to update.
Do you have any suggestions as to why that might be. I am using the base code on the Waveshare website therefore struggling to understand why it wont work.
Yes I have them plugged into the SDA and SCL pins correctly next to the AREF. There is the same layout on the UNO R3 therefore have just gone straight across from there
No the SDA and SCL lines along with the 3.3V and the Ground run directly into the display.
The 5V line runs into the switch and then there is a resistor between the ground and the switch and then also coming out of the switch is a line to the digital pin.
Full code is below
//Definitions
#include <Waveshare_LCD1602_RGB.h>
#include <Keyboard.h>
// this constant won't change:
//GREEN BUTTON
const int buttonG = 6; // the pin that the pushbutton is attached to
const int ledG = 12; // the pin that the LED is attached to
//BLUE BUTTON
const int buttonB = 5; // the pin that the pushbutton is attached to
const int ledB = 13; // the pin that the LED is attached to
//ESTOP
const int buttonE = 7; // the pin that the pushbutton is attached to
const int ledE = 11; // the pin that the LED is attached to
//SWITCH
const int buttonS1 = 3; // the pin that the pushbutton is attached to
const int buttonS2 = 4; // the pin that the LED is attached to
// Variables will change:
//GREEN BUTTON
int buttonGState = 0; // current state of the button
int lastButtonGState = 0; // previous state of the button
//BLUE BUTTON
int buttonBState = 0; // current state of the button
int lastButtonBState = 0; // previous state of the button
//ESTOP BUTTON
int buttonEState = 0; // current state of the button
int lastButtonEState = 0; // previous state of the button
//SWITCH 1
int buttonS1State = 0; // current state of the button
int lastButtonS1State = 0; // previous state of the button
//SWITCH 2
int buttonS2State = 0; // current state of the button
int lastButtonS2State = 0; // previous state of the button
//SCREEN
Waveshare_LCD1602_RGB lcd(16,2); //16 characters and 2 lines of show
int r,g,b,t=0;
void setup() {
// initialize the button pin as a input:
pinMode(buttonG, INPUT);
pinMode(buttonB, INPUT);
pinMode(buttonE, INPUT);
// initialize the LED as an output:
pinMode(ledG, OUTPUT);
pinMode(ledB, OUTPUT);
pinMode(ledE, OUTPUT);
//TURN LEDS ON
digitalWrite(ledG, LOW);
digitalWrite(ledB, LOW);
digitalWrite(ledE, LOW);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
//GREEN BUTTON
// read the pushbutton input pin:
buttonGState = digitalRead(buttonG);
// compare the buttonState to its previous state
if (buttonGState != lastButtonGState) {
// if the state has changed, increment the counter
if (buttonGState == LOW) {
// if the current state is HIGH then the button went from off to on:
Serial.println("M9051");
digitalWrite(ledG, HIGH);
delay (100);
digitalWrite(ledG, LOW);
delay (100);
digitalWrite(ledG, HIGH);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("GREEN OFF");
digitalWrite(ledG, LOW);
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonGState = buttonGState;
//GREEN BUTTON END
//BLUE BUTTON
// read the pushbutton input pin:
buttonBState = digitalRead(buttonB);
// compare the buttonState to its previous state
if (buttonBState != lastButtonBState) {
// if the state has changed, increment the counter
if (buttonBState == HIGH) {
// if the current state is HIGH then the button went from off to on:
Serial.println("M9052");
digitalWrite(ledB, HIGH);
delay (100);
digitalWrite(ledB, LOW);
delay (100);
digitalWrite(ledB, HIGH);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("BLUE OFF");
digitalWrite(ledB, LOW);
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonBState = buttonBState;
//BLUE BUTTON END
//ESTOP BUTTON
// read the pushbutton input pin:
buttonEState = digitalRead(buttonE);
// read the pushbutton input pin:
buttonS1State = digitalRead(buttonS1);
// if the state has changed, increment the counter
if (buttonS1State == HIGH) {
// compare the buttonState to its previous state
if (buttonEState != lastButtonEState) {
// if the state has changed, increment the counter
if (buttonEState == LOW) {
// if the current state is HIGH then the button went from off to on:
Serial.println("M9053");
digitalWrite(ledE, HIGH);
delay (100);
digitalWrite(ledE, LOW);
delay (100);
digitalWrite(ledE, HIGH);
} else {
// if the current state is LOW then the button went from on to off:
Serial.println("ESTOP OFF");
digitalWrite(ledE, LOW);
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state, for next time through the loop
lastButtonEState = buttonEState;
//ESTOP BUTTON END
}
}