0

I have a digispark that uses trinket keyboard library to send media keys back to the computer using a rotary encoder. I currently have it configured to send normal media keys but about 2 weeks ago i started needing to change binds on what the rotary encoder does so i needed a driver of some sort. i asked and i got answers that i can't use serial ports but i can use unused keys like f13+ keys so i use the f keys now to communicate to c# software (it listens on these f keys and as soon as they are pressed depending on the configuration it does what it needs to do).
I don't think that code is needed for this demonstration but if u need it i'll be happy to edit this.

So i made the software and now comes a problem of what happens when u plug in the device that doesn't have the driver. its useless, so i need a way for the digispark to find out if there is a software that can "reprogram" what the rotary encoder does and if there isn't use the default functions(the media keys).

Questions:

  1. How would i go about finding out if there is the needed driver on that computer where the digispark is plugged in

  2. Is there any way to add my program made in c# to the digispark, i got a usb headset and when i first plugged it in it installed its driver, so when i plug in my digispark can it load the program

Solutions that i think may work but i have no idea how to do them:

  1. using one of these unused keys as Boolean, when its held down lets say by the c# software can the digispark using the trinket or any other compatible Tiny85 library determine if that key is pressed down or not (this may interfere with other software so i don't think its perfect solution)

  2. If anyone here knows any library or custom firmware that allows the digispark(Tiny85) to communicate on serial ports that'd be pretty useful and would solve the whole question.

For the second problem: do i need any other hardware to do this as i only have a Tiny85 digispark and a rotary encoder with a breakout board

If you have a solution please provide me code or links where i may learn how to do this because as of now i have no idea how to do this, i know my way around c# but i'm a noob in arduino programming. I already asked this on stack overflow a week ago but didn't get any comments or answers. I'm sorry if this counts as a duplicate i'll remove the one on stack overflow if needed. thank you for understanding

  • A usb device can’t check if a key is pressed. What you might be able to check is the status of the capslock key. So my proposed solution would be. On powerup have the digispark send a F17-key press. Then have the c# respond by Turing the capslock on for e.g. 1 second. The digispark will check if the capslock was on for a brief moment, and if so, will know that the C# program is active. (Note that you need a slightly different solution if digispark is already connected before the pc is turned on) – Gerben May 21 '18 at 9:08
  • @Gerben Can it also be done with the scrool lock as i dont find myself using it very often and the problem where your pc isnt loaded can be fixed either by adding a delay on startup like 20 secs to allow the pc and program to start up, or put it in a loop and add a boolean to stop checking everytime it loops if it finds the software – SenaCarbtc May 21 '18 at 12:46
  • scrolllock would indeed be better. – Gerben May 21 '18 at 12:49
  • How big is your software installation package? – Majenko May 21 '18 at 15:01
  • And why are you so fixated on such an unsuitable MCU for complex USB work? – Majenko May 21 '18 at 15:02
1

How would i go about finding out if there is the needed driver on that computer where the digispark is plugged in

I can't think of any way to do that. That's like asking if a keyboard you plug into a USB port can tell if you have Photoshop installed or not.


Is there any way to add my program made in c# to the digispark ...

No. The Digispark is a tiny computer based on the Attiny85 which has 8k of program memory, some of which is dedicated to a bootloader which lets you upload new code.


Your project is far too ambitious for the level of hardware you are proposing to use. In fact this video which I watched the other day comes to mind:

https://www.youtube.com/watch?v=s7AXskSxxMk


From a comment:

the it refers to the digispark, when connected the digispark checks if the f17 key is pressed down and if it is that means my program is running in the background so use the functions that are compatible with the program

OK, so you want the host computer (not the Digispark) to pretend it is holding down F17, and then when the Digispark is plugged in it checks if F17 is down, and if so it knows that the desired program is running on the PC. Is that your idea?

The problem here is that the Digispark is a USB device (not a USB host). I suppose it would be possible to write a special device driver on the PC that, once the Digispark connects, would send some special code to say whether or not the program is running. However with the Digispark only having 8 KB of program memory, this extra code (on the Digispark) might be hard to fit in. Plus you would need to write your USB device driver. Plus the device driver would need to be able to query what programs are running.

I think a far simpler solution would be to have an On/Off button on the Digispark. If you plug it into a PC which has this special program running you press the button, then the Digispark sends the alternative commands to your C# program.

  • First of all i clearly stated that the digispark doesn't have serial so i use one of the unused keys, let's say f17 as a boolean. my c# program holds it down so when the digispark connects it should check if f17 is held down or not, if it's not it should default to volume control and if it is held down it should be f13 and f14 for the rotary encoder rotation(this is already done). i need a way to find if that key is pressed and act according to that. for the second thing ik the digispark doesn't have internal memory so that's why i asked what do i buy to get this functionality – SenaCarbtc May 21 '18 at 7:56
  • @SenaCarbtc There is absolutely no way for a USB device to query what software is installed on your computer - no matter what device you buy. It's just not physically possible. Only software installed in your computer can know what software is installed in your computer. – Majenko May 21 '18 at 14:58
  • @SenaCarbtc The only thing you could possibly do is send some custom message from the USB device that the software responds to, sending a message back. If that message never arrives you can assume the software either isn't installed or isn't running. – Majenko May 21 '18 at 15:00
  • I didn't mention "serial" in my answer. I am now uncertain if by Digispark you mean the device you plug into your computer, or some software running on the computer (like the IDE). when the digispark connects it should check if f17 is held down or not - what is "it" in that sentence? – Nick Gammon May 21 '18 at 22:01
  • @NickGammon the it refers to the digispark, when connected the digispark checks if the f17 key is pressed down and if it is that means my program is running in the background so use the functions that are compatible with the program, i already got an answer to use the scroll lock key but can this be done with the f17 as no program uses it – SenaCarbtc May 23 '18 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.