Adding LCD to Arduino Uno in DFU mode as HID joystick?

Hello all, so I have been working on a CNC machine for quite some time now. Recently I built a simple controller for the CNC software Mach3. All is working as far as that goes, but what I’m wanting to do is add a 4x16 lcd to the projects somehow.

What I’m thinking is i can hook the lcd to A4 and A5 of a separate arduino and have the code read serial data coming from the Arduino i have hooked to the controller.

But will that work? can i modify this code somehow to print data over serial to another arduino? i see something in this code about A4 and A5 being used as serial lines.
For instance, instead of pins 2 and 3 being buttons on the controller, can they be software serial pins? and add serial.print on each line like this?

controllerData.dpadUpOn = !digitalRead(6);
Serial.println("Jog Rate +");
#include "UnoJoy.h"

void setup(){
  setupPins();
  setupUnoJoy();
}

void loop(){
  // Always be getting fresh data
  dataForController_t controllerData = getControllerData();
  setControllerData(controllerData);
}

void setupPins(void){
  // Set all the digital pins as inputs
  // with the pull-up enabled, except for the 
  // two serial line pins
  for (int i = 2; i <= 12; i++){
    pinMode(i, INPUT);
    digitalWrite(i, HIGH);
  }
  pinMode(A4, INPUT);
  digitalWrite(A4, HIGH);
  pinMode(A5, INPUT);
  digitalWrite(A5, HIGH);
}

dataForController_t getControllerData(void){
  
  // Set up a place for our controller data
  //  Use the getBlankDataForController() function, since
  //  just declaring a fresh dataForController_t tends
  //  to get you one filled with junk from other, random
  //  values that were in those memory locations before
  dataForController_t controllerData = getBlankDataForController();
  // Since our buttons are all held high and
  //  pulled low when pressed, we use the "!"
  //  operator to invert the readings from the pins
  controllerData.triangleOn = !digitalRead(2);
  controllerData.circleOn = !digitalRead(3);
  controllerData.squareOn = !digitalRead(4);
  controllerData.crossOn = !digitalRead(5);
  controllerData.dpadUpOn = !digitalRead(6);
  controllerData.dpadDownOn = !digitalRead(7);
  controllerData.dpadLeftOn = !digitalRead(8);
  controllerData.dpadRightOn = !digitalRead(9);
  controllerData.l1On = !digitalRead(10);
  controllerData.r1On = !digitalRead(11);
  controllerData.selectOn = !digitalRead(12);
  controllerData.startOn = !digitalRead(A4);
  controllerData.homeOn = !digitalRead(A5);
  
  // Set the analog sticks
  //  Since analogRead(pin) returns a 10 bit value,
  //  we need to perform a bit shift operation to
  //  lose the 2 least significant bits and get an
  //  8 bit number that we can use  
  controllerData.leftStickX = analogRead(A0) >> 2;
  controllerData.leftStickY = analogRead(A1) >> 2;
  controllerData.rightStickX = analogRead(A2) >> 2;
  controllerData.rightStickY = analogRead(A3) >> 2;
  // And return the data!
  return controllerData;
}

Here is the quick answer: You cannot write serial data to pins A4 and A5 as they are already used for input from “startOn” and “homeOn”. You might want to investigate an Arduino mega to get some extra pins.

More detail, as I see it…

The normal serial pins (0, 1) are not used as the Unojoy writes to the serial (USB) using them.

This code sets up pins 2 to 12 as digital inputs and sets the internal pullup HIGH.

void setupPins(void){
  // Set all the digital pins as inputs
  // with the pull-up enabled, except for the 
  // two serial line pins
  for (int i = 2; i <= 12; i++){
    pinMode(i, INPUT);
    digitalWrite(i, HIGH);
  }

This code sets pins A4 and A5 (which are normally analog inputs) as digital inputs and sets the pullup HIGH:

 pinMode(A4, INPUT);
  digitalWrite(A4, HIGH);
  pinMode(A5, INPUT);
  digitalWrite(A5, HIGH);

Analog inputs A0, A1, A2 and A3 are used to read the analog data from the joystick.

Maybe you could use something like SoftwareSerial to write to a different Arduino. But you only have one pin left (13) so you will need to eliminate one button from your joystick to free up a pin and then rearrange some other buttons to work with the SoftwareSerial. And I have no idea if that will function after all that work!

It seems like Unojoy may work with the arduino mega – you would have lots of extra pins to drive an LCD without needing to communicate with another arduino.

i do have a mega, but i have plenty of $4 micros from ebay that i could use to drive the LCD and i can do away with a few buttons and use software serial i think. my project only requires abt half of the ones listed in that sketch