Hi everyone!
I am trying to make a custom mouse. I will probably have to use a nano or a custom board for the final product, but for the prototype I am using a Mega 2560. I came across VUSB as a way to use an HDI interface rather than writing a program to translate serial to mouse movement, or using a Leonardo.
Here's a link to the library:
I am just using their example sketch to make sure that the code works and I have run into a series of error messages. I was able to solve all but two of them by adding a const before the problem variables in the .h files. (I'm using notepad ++ if it makes any difference).
These are the two error messages I can't figure out. Everything that I do to fix them causes a bunch of error messages.
In file included from C:\Users\jdcha\Documents\Arduino\libraries\UsbMouse-master\examples\UsbMouseDemo1\UsbMouseDemo1.ino:7:0:
C:\Users\jdcha\Documents\Arduino\libraries\UsbMouse-master/UsbMouse.h:30:39: error: variable 'usbDescriptorHidReport' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
PROGMEM char usbHidReportDescriptor[52] = { /* USB report descriptor, size must match usbconfig.h */
^
C:\Users\jdcha\Documents\Arduino\libraries\UsbMouse-master/UsbMouse.h:30:39: error: conflicting declaration 'char usbDescriptorHidReport [52]'
In file included from C:\Users\jdcha\Documents\Arduino\libraries\UsbMouse-master/UsbMouse.h:13:0,
from C:\Users\jdcha\Documents\Arduino\libraries\UsbMouse-master\examples\UsbMouseDemo1\UsbMouseDemo1.ino:7:
C:\Users\jdcha\Documents\Arduino\libraries\UsbMouse-master/usbdrv.h:491:12: note: previous declaration as 'const char usbDescriptorHidReport []'
const char usbDescriptorHidReport[];
^~~~~~~~~~~~~~~~~~~~~~
exit status 1
Error compiling for board Arduino Mega or Mega 2560.
Again, the only things that I have changed in the library code are the variable declarations that came up in previous messages.
I am trying to make a custom mouse. I will probably have to use a nano or a custom board for the final product, but for the prototype I am using a Mega 2560. I came across VUSB as a way to use an HDI interface rather than writing a program to translate serial to mouse movement, or using a Leonardo.
You actually want to connect such a device to your PC? I wouldn't do that, you might destroy your PC's USB ports. Use it only if you cannot afford a Leonardo or Micro, otherwise these boards are by far the better alternative!
The first compiler error is easily fixed if you do what the compiler suggests: make the type const. Back when the original code was developed the compiler was far more tolerant with type errors in the code.
The second error is in your sketch. As you didn't post it, we don't know why you declared the same variable twice.
I didn't post the code because it's just the example code from the library. It's at the bottom of the post if you want to look it over.
The first error message is the same as what I fixed with several other variables. I think the reason it isn't working here is because it's the same variable as the second error message.
The way I read that second error message is that the conflicting declaration is spread between two of the library files. It looks like the declaration is made in UsbMouse.h and in usbdrv.h. It isn't declared anywhere in the example sketch.
Using the Leonardo or micro would be nice, but I don't think I'll be able to fit them in the limited space with all of the other hardware. I'll have to look at the micro to be sure though. I'm planning on using an ftdi breakout board as a buffer between the USB port and the mouse. I've done a couple of other projects with that setup without any issue. At this point I just need to get the library working.
/*
UsbMouse
Library written (a lot of copy/paste) by Meir Michanie
based on UsbKeyboard and usbdrv mouse sample code.
*/
#include "UsbMouse.h"
#define LEFTBUTTON_PIN 12
#define MIDDLEBUTTON_PIN 11
#define RIGHTBUTTON_PIN 10
// If the timer isr is corrected
// to not take so long change this to 0.
#define BYPASS_TIMER_ISR 1
void setup() {
pinMode(LEFTBUTTON_PIN, INPUT);
digitalWrite(LEFTBUTTON_PIN, HIGH);
pinMode(MIDDLEBUTTON_PIN, INPUT);
digitalWrite(MIDDLEBUTTON_PIN, HIGH);
pinMode(RIGHTBUTTON_PIN, INPUT);
digitalWrite(RIGHTBUTTON_PIN, HIGH);
#if BYPASS_TIMER_ISR
// disable timer 0 overflow interrupt (used for millis)
TIMSK0 &= !(1 << TOIE0); // ++
#endif
UsbMouse.update();
}
void loop() {
demo2();
UsbMouse.update();
#if BYPASS_TIMER_ISR // check if timer isr fixed.
delayMs(20);
#else
delay(20);
#endif
}
void demo1(){
UsbMouse.move(random(10) -5,random(10) -5,0);
}
void demo2(){
UsbMouse.set_buttons(!digitalRead(LEFTBUTTON_PIN), !digitalRead(RIGHTBUTTON_PIN), !digitalRead(MIDDLEBUTTON_PIN));
}
#if BYPASS_TIMER_ISR
void delayMs(unsigned int ms) {
/*
*/
for (int i = 0; i < ms; i++) {
delayMicroseconds(1000);
}
}
//
#endif
Update: I did some research and I found that using a board like the Adafruit ItsyBitsy is more cost effective and will save space as opposed to my original idea. That particular board uses the same chips as the Leonardo, It's just much smaller. I also have the advantage of not having to debug a broken library.