Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB Joystick Extender #1

Open
motorfiets opened this issue Dec 9, 2020 · 0 comments
Open

USB Joystick Extender #1

motorfiets opened this issue Dec 9, 2020 · 0 comments

Comments

@motorfiets
Copy link

motorfiets commented Dec 9, 2020

Curious if your USB extender code could work for a joystick? I am wanting to wirelessly extend two potentiometers (maybe more?) over 915mhz.

  • Feather connected to (2) analogRead sensors
    Transmitting the sensor data to
  • Feather connected to PC using the Joystick.h library.

I have the code working perfect for a single AnalogRead sensor but I would like to have multiple sensors to the TX feather.

My code currently below:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

`//master recieve

#include <Joystick.h>

#include <SPI.h>
#include <RH_RF69.h>
#define RF69_FREQ 915.0
#define RFM69_CS 8
#define RFM69_INT 7
#define RFM69_RST 4
#define LED 13

Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK, 0, 0,
// x y z rX rY rZ rudder thro acc brake steer
true, true, true, false, false, false, true, true, false, false, false);

int xAxis;
int yAxis;
int zAxis;
int rudder;

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

void setup()
{
Serial.begin(115200);
while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

pinMode(LED, OUTPUT);
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, LOW);

Serial.println("Feather RFM69 TX Test!");
Serial.println();

// manual reset
digitalWrite(RFM69_RST, HIGH);
delay(10);
digitalWrite(RFM69_RST, LOW);
delay(10);

if (!rf69.init()) {
Serial.println("RFM69 radio init failed");
while (1);
}
Serial.println("RFM69 radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
// No encryption
if (!rf69.setFrequency(RF69_FREQ)) {
Serial.println("setFrequency failed");
}

// If you are using a high power RF69 eg RFM69HW, you must set a Tx power with the
// ishighpowermodule flag set like this:
rf69.setTxPower(20, true); // range from 14-20 for power, 2nd arg must be true for 69HCW

// The encryption key has to be the same as the one in the server
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);

Serial.print("RFM69 radio @"); Serial.print((int)RF69_FREQ); Serial.println(" MHz");

Joystick.begin();

}

void loop() {

uint16_t data;
uint8_t datalen = sizeof(data);
if ( rf69.recv((uint8_t*)&data, &datalen)
&& datalen == sizeof(data))
{
// Have the data, so do something with it
rudder = data;

}

Joystick.setZAxis(rudder);
Serial.println(rudder);

}`

/////////////////////////////////////////////////////////////////////

`// master send

#include <SPI.h>
#include <RH_RF69.h>
#define RF69_FREQ 915.0
#define RFM69_CS 8
#define RFM69_INT 7
#define RFM69_RST 4
#define LED 13

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

int16_t packetnum = 0; // packet counter, we increment per xmission
int speaker = A5;

void setup()
{
Serial.begin(115200);
//while (!Serial) { delay(1); } // wait until serial console is open, remove if not tethered to computer

pinMode(LED, OUTPUT);
pinMode(RFM69_RST, OUTPUT);
digitalWrite(RFM69_RST, LOW);

Serial.println("Feather RFM69 TX Test!");
Serial.println();

// manual reset
digitalWrite(RFM69_RST, HIGH);
delay(10);
digitalWrite(RFM69_RST, LOW);
delay(10);

if (!rf69.init()) {
Serial.println("RFM69 radio init failed");
while (1);
}
Serial.println("RFM69 radio init OK!");
// Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
// No encryption
if (!rf69.setFrequency(RF69_FREQ)) {
Serial.println("setFrequency failed");
}

// If you are using a high power RF69 eg RFM69HW, you must set a Tx power with the
// ishighpowermodule flag set like this:
rf69.setTxPower(20, true); // range from 14-20 for power, 2nd arg must be true for 69HCW

// The encryption key has to be the same as the one in the server
uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
rf69.setEncryptionKey(key);

pinMode(LED, OUTPUT);

Serial.print("RFM69 radio @"); Serial.print((int)RF69_FREQ); Serial.println(" MHz");
}

void loop() {

uint16_t data = analogRead(A2);
Serial.println(data);
rf69.send((uint8_t*)&data, sizeof(data));
rf69.waitPacketSent();

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant