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


hello all, have been working on cnc machine quite time now. built simple controller cnc software mach3. working far goes, i'm wanting add 4x16 lcd projects somehow.

what i'm thinking can hook lcd a4 , a5 of separate arduino , have code read serial data coming arduino have hooked controller.

but work? can modify code somehow print data on serial arduino? see in code a4 , a5 being used serial lines.
for instance, instead of pins 2 , 3 being buttons on controller, can software serial pins? , add serial.print on each line this?
code: [select]
controllerdata.dpadupon = !digitalread(6);
serial.println("jog rate +");


code: [select]
#include "unojoy.h"

void setup(){
  setuppins();
  setupunojoy();
}

void loop(){
  // getting fresh data
  dataforcontroller_t controllerdata = getcontrollerdata();
  setcontrollerdata(controllerdata);
}

void setuppins(void){
  // set digital pins inputs
  // pull-up enabled, except
  // 2 serial line pins
  (int = 2; <= 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 place our controller data
  //  use getblankdataforcontroller() function, since
  //  declaring fresh dataforcontroller_t tends
  //  1 filled junk other, random
  //  values in memory locations before
  dataforcontroller_t controllerdata = getblankdataforcontroller();
  // since our buttons held high and
  //  pulled low when pressed, use "!"
  //  operator invert readings 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 analog sticks
  //  since analogread(pin) returns 10 bit value,
  //  need perform bit shift operation to
  //  lose 2 least significant bits , an
  //  8 bit number can use 
  controllerdata.leftstickx = analogread(a0) >> 2;
  controllerdata.leftsticky = analogread(a1) >> 2;
  controllerdata.rightstickx = analogread(a2) >> 2;
  controllerdata.rightsticky = analogread(a3) >> 2;
  // , return data!
  return controllerdata;
}

here quick answer:  cannot write serial data pins a4 , a5 used input "starton" , "homeon".  might want investigate arduino mega pins.

more detail, see it...

the normal serial pins (0, 1) not used unojoy writes serial (usb) using them.

this code sets pins 2 12 digital inputs , sets internal pullup high.
code: [select]
void setuppins(void){
  // set digital pins inputs
  // pull-up enabled, except
  // 2 serial line pins
  (int = 2; <= 12; i++){
    pinmode(i, input);
    digitalwrite(i, high);
  }


this code sets pins a4 , a5 (which analog inputs) digital inputs , sets pullup high:
code: [select]
pinmode(a4, input);
  digitalwrite(a4, high);
  pinmode(a5, input);
  digitalwrite(a5, high);



analog inputs a0, a1, a2 , a3 used read analog data joystick.

maybe use softwareserial to write different arduino.  have 1 pin left (13) need eliminate 1 button joystick free pin , rearrange other buttons work softwareserial.  , have no idea if function after work!

it seems unojoy may work arduino mega -- have lots of pins drive lcd without needing communicate arduino.


Arduino Forum > Using Arduino > Displays > Adding LCD to Arduino Uno in DFU mode as HID joystick?


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code