I have a Arduino Uno, and want to reprogram the usb serial converter chip with some stuff from LUFA.
Here's a link.
I want it to function as a keyboard/joystick. I am pretty sure this is possible.
I want to know if I need any additional hardware to program the chip,ETC.
And how could i restore the original program if something goes wrong?
BTW, I have a smd edition if that makes a difference,
Hi,
I've done a bit of reading on this subject because I too, want to get my arduino to make the computer think it is a joystick.
you can dig up a bit more information if you search for something like 'arduino Uno DFU mode' (if you haven't already done so). I'm sorry I couldn't be of more help... I'm a noob as well. (I've just ordered my first arduino)
I think you put it into dfu mode by connecting reset and ground headers on the iscp
Headers for the atmega (something) then use a avr compiler to download the .hex onto the chip
/* Arduino USB Joystick HID demo */
/* Author: Darran Hunt
* Released into the public domain.
*/
struct {
int8_t x;
int8_t y;
uint8_t buttons;
uint8_t rfu; /* reserved for future use */
} joyReport;
void setup();
void loop();
void setup()
{
Serial.begin(115200);
delay(200);
}
/* Move the joystick in a clockwise square every 5 seconds,
* and press button 1 then button 2.
*/
void loop()
{
int ind;
delay(5000);
joyReport.buttons = 0;
joyReport.x = 0;
joyReport.y = 0;
joyReport.rfu = 0;
/* Move the joystick in a clockwise direction */
joyReport.x = 100;
Serial.write((uint8_t *)&joyReport, 4);
delay(1000);
joyReport.x = 0;
joyReport.y = 100;
Serial.write((uint8_t *)&joyReport, 4);
delay(1000);
joyReport.x = -100;
joyReport.y = 0;
Serial.write((uint8_t *)&joyReport, 4);
delay(1000);
joyReport.x = 0;
joyReport.y = -100;
Serial.write((uint8_t *)&joyReport, 4);
delay(1000);
/* Send button 1 then button 2 */
joyReport.y = 0;
joyReport.buttons = 1;
Serial.write((uint8_t *)&joyReport, 4);
delay(1000);
joyReport.buttons = 2;
Serial.write((uint8_t *)&joyReport, 4);
delay(1000);
joyReport.buttons = 0;
Serial.write((uint8_t *)&joyReport, 4);
}
and this code for a Keyboard:
/* Arduino USB Keyboard HID demo
*
* Sends Volume up, hello world, and Volume Down to the host PC
*
*/
uint8_t buf[8] = { 0 }; /* Keyboard report buffer */
void setup();
void loop();
#define KEY_LEFT_CTRL 0x01
#define KEY_LEFT_SHIFT 0x02
#define KEY_RIGHT_CTRL 0x10
#define KEY_RIGHT_SHIFT 0x20
void setup()
{
Serial.begin(9600);
delay(200);
}
char *str = "+hello world-";
void loop()
{
char *chp = str;
delay(5000);
while (*chp) {
if ((*chp >= 'a') && (*chp <= 'z')) {
buf[2] = *chp - 'a' + 4;
} else if ((*chp >= 'A') && (*chp <= 'Z')) {
buf[0] = KEY_LEFT_SHIFT; /* Caps */
buf[2] = *chp - 'A' + 4;
} else {
switch (*chp) {
case ' ':
buf[2] = 0x2c; // Space
break;
case '+':
buf[2] = 128; // Volume up
break;
case '-':
buf[2] = 129; // Volume down
break;
default:
/* Character not handled. To do: add rest of chars from HUT1_11.pdf */
buf[2] = 0x37; // Period
break;
}
}
Serial.write(buf, 8); // Send keypress
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
chp++;
}
}
It seems I am right, you use serial write for sending data (probably becuase those are the pins connected to the Atmega8u2)
but the code uses several functions i am not familiar with.
Which functions are you unfamiliar with? Serial.write(buf, size) sends the first "size" bytes of the byte array "buf" out the serial port. So all you need to do is set the fields in joyReport (e.g. based on the current inputs from your joystick) and then use Serial.write() to send the report to the atmega8u2 which will in turn send it as a USB HID report to the PC.
Yes, if you have the serial monitor baudrate set (lower right hand corner) at a different value then the sketch Serial.begin(xxxx) value used in the sketch.
Yes the sketch is sending raw data via the serial port that will look like garbage on the serial monitor. Once you program the atmega8u2 with the HID joystick firmware it will convert that data into HID joystick reports.