I read a similar post regarding the use of OLED and QWIIC Joystick. I am not sure if the issue is exactly the same.
I first started with Sparkfun Blackboard (with QWIIC), Grove Shield, and DYI .96" OLED
Updates all the Libraries. I2C scanner did not show any conflicts.
I had no problems with the working as a team.
I then added the QWIIC Joystick. That is when the problems started.
I can successfully accomplish a very limited use of the Joystick. 3 Arrays for each color (RGB) elements 0-3 works but if I add any additional elements The code begins to break down -for example I may get one joystick movement (vertical) but no horizontal.
//** CODE FOLLOWS
Edited by moderator to add code tags.
//Using gitHub library
//The following code is working as of: 10/09/2020:1601
//
/***************************************************************************/
/*
* Changed the display to #define SSD1306_128_64 in Adafruit_SSD1306.h Library
* After initializing the display, the above sketch then draws a pixel at each extreme of the display by using drawPixel() to place a pixel in each corner of the screen. The first parameter passed to drawPixel() is the screen X coordinate and the second parameter is the screen Y coordinate.
Screen dimensions are 128 by 64 pixels and pixel coordinates start at 0, 0 for the top left pixel. This means that the X coordinates for the screen are from 0 to 127 (not 1 to 128) left to right; and Y coordinates are from 0 to 63 (not 1 to 64) top to bottom.
As can be seen in the sketch and on the display, the corner pixels are at the following coordinates:
Top left pixel – x = 0, y = 0.
Top right pixel – x = 127, y = 0.
Bottom left pixel – x = 0, y = 63.
Bottom right pixel – x = 127, y = 63.
xMap = map(joystick.getHorizontal(), 0,1023, 0, 7);
yMap = map(joystick.getVertical(),0,1023,7,0);
Position of Joystick:
Longside toward me, power light Right hand side
(7,7) (7,4) (7,0) |s
|h
|o
(3,7) (3,4) (3,0) |r
|t
|
(0,7) (0,4) (0,0) |s
Long side---------------------------|
*/
#include <Wire.h>
#include "RGBdriver.h"
//#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "SparkFun_Qwiic_Joystick_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_joystick
JOYSTICK joystick; //Create instance of this object
// OLED display TWI address
#define OLED_ADDR 0x3C
//I2C scanner double checked addresses;
//I2C device found at address 0x20 - joystick
//I2C device found at address 0x3C - OLED
// reset pin not used on 4-pin OLED module
Adafruit_SSD1306 display(-1); // -1 = no reset pin
// 128 x 64 pixel display
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
#define CLK 5 //0 2 pins definitions for the driver
#define DIO 6 //1 /3
RGBdriver Driver(CLK,DIO);
int k = 16;
int ixCurrent;
int iyCurrent;
int ixOld;
int iyOld;
int iButtonCur;
int iButtonOld;
int indxArray = 0;
bool bButton;
String cString, cColor; //Conversion for Display
int xMap, yMap;
int xValue = 0;
int yValue = 0;
int iRed, iBlue, iGreen;
String sColors[4] = {"ORANGE", "LIGHT BROWN", "HARVEST GOLD", "BLUE"}; // 0, 1, 2, 3
int aRed[4] = {255, 196, 230, 0}; //Orange. Light Brown, Harvest GOld, Blue
int aGreen[4] = {165, 98, 153, 0}; //Orange. Light Brown, Harvest GOld, Blue
int aBlue[4] = {0, 16, 0, 255}; //Orange. Light Brown, Harvest GOld, Blue
//If I increase the arrays to 8 no values are displayed on the OLED 10/10/2020:0952
void setup()
{
Driver.begin(); // begin
//Serial.begin(9600);
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
// initialize and clear display
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
display.clearDisplay();
display.display();
delay(500);
if(joystick.begin() == false) //This must be here
{
Serial.println("Joystick does not appear to be connected. Please check wiring. Freezing...");
while(1);
}
} // End setup
void loop()
{ //use the values of the joyStick to change the RGB Strip LEDs
//int xMap, yMap, xValue, yValue;
//int iRed, iBlue, iGreen;
//String sColors(4) = {"ORANGE", "LIGHT BROWN", "HARVEST GOLD", "BLUE"}; // 0, 1, 2, 3
//int cRed(4) = {255, 196, 230, 0}; //Orange. Light Brown, Harvest GOld, Blue
//int cGreen(4) = {165, 98, 153, 0}; //Orange. Light Brown, Harvest GOld, Blue
//int cBlue(4) = {0, 16, 0, 255}; //Orange. Light Brown, Harvest GOld, Blue
xValue = joystick.getHorizontal();
//delay(500);
xMap = map(joystick.getHorizontal(),0,1023, 0, 7); //Now works 10/10/20:1718
delay(700);
yValue = joystick.getVertical(); //having problems
yMap = map(joystick.getVertical(),0,1023,7,0);
//if (yValu > 1000) {
delay(500);
bButton = joystick.checkButton();
delay(500);
// }
if (bButton) {
display.setCursor(0,56);
display.print("T"); //Then do something
display.display();
delay(700);
indxArray = 0;
iRed = aRed[indxArray];
iBlue = aBlue[indxArray];
iGreen = aGreen[indxArray];
cColor = sColors[indxArray];
changeLEDcolor(iRed, iGreen, iBlue, xMap, yMap, cColor);
indxArray = indxArray + 1;
}
else {
xyJoystick(xMap, yMap, " ");
}
// if (indxArray > 3) { //As soon as I put this in one of the x-y values disappears
// indxArray = 0; // As steup above, the xMap value disappears
// }
delay(500);
// xValue = analogRead(joyX); NOPE
//xMap = map(joystick.getHorizontal(), 0,1023, 0, 7); NOPE
// for(i = 0;i < 256;i ++)
// for(i = 255;i > 0;i --)
// unsigned int i;
// unsigned int j;
} // End Main LOOP
void changeLEDcolor(int iR, int iG, int iB, int iX, int iY, String sT)
{ //(int RED, GREEN, BLUE)
//
String sX, sY, sPrntX, sPrntY;
sX = String(iX);
sY = String(iY);
sPrntX = "X= " + sX; //joystick Horizontal value
sPrntY = "Y= " + sY; //joystick Vertical value
//Get Joystick values
//Default values: X: 508508 Y: 518 Button: 1
//https://rgbcolorcode.com/color/FFAA00
//Amber: rgb(255,126,0)
//Light Brown: rgb(196,98,16)
//Jarvest Gold rgb(230, 153,0)
//Carrot Orange: rgb(255,140,25)
//Pastel Orange: rgb(255,195,77)
//Saffron: rgb(255,187,51)
//Chrome Yellow: rgb(255,170,0)
//RGB setting example (Chrome Yellow): rgb(255,170,0)
//But, stripdriver format: G R B
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,16);
display.print(sT);
// delay(600);
display.setCursor(0,36);
display.print(sPrntX);
// display.display();
// delay(600);
display.setCursor(0,46);
display.print(sPrntY);
// delay(600);
display.display();
delay(700);
Driver.begin(); // begin
Driver.SetColor(iG,iR,iB); //GREEN. First node data. SetColor(R,G,B)
Driver.end();
delay(5000);
display.clearDisplay();
delay(500);
}
void xyJoystick(int iX, int iY, String sT)
{
//
String sX, sY, sPrntX, sPrntY;
sX = String(iX);
sY = String(iY);
sPrntX = "X= " + sX; //joystick Horizontal value
sPrntY = "Y= " + sY; //joystick Vertical value
//Get Joystick values
//Default values: X: 508508 Y: 518 Button: 1
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,36);
display.print(sPrntX);
// display.display();
// delay(600);
display.setCursor(0,46);
display.print(sPrntY);
// delay(600);
display.display();
delay(5000);
display.clearDisplay();;
}
void headerOLED() {
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print("COLORS!");
display.display();
delay(1000); ///Somehow the timing was messed up. Added more delay
}