Digispark keyboard (only 2 keys) emulation

hi all.

I have a cnc machine project going on that runs off mach3mill and i need to add a remote to it,

its a simple 2 button (start and stop) and wanted to program up a digispark board that will emulate itself as a 2 key keyboard as i can hotkey commands within mach3mill so keystrokes.

but im a little stumped as to where to begin. i looked at the digikeyboard but the example isnt exactly clear as to how to go about it.

the digispark board would be plugged into the laptop obviously.

Can you show us exactly what you have? Is the only means of communicating with the CNC machine through the Mach3Mill software?

Post the code.

This

#include "DigiKeyboard.h"

// Define pins for buttons
const int button1 = 0; // Button 1 on P0
const int button2 = 1; // Button 2 on P1

void setup() {
  pinMode(button1, INPUT_PULLUP);
  pinMode(button2, INPUT_PULLUP);
}

void loop() {
  DigiKeyboard.update();
  
  // Button 1: Ctrl + C (Copy)
  if (digitalRead(button1) == LOW) {
    DigiKeyboard.sendKeyStroke(KEY_C, MOD_CONTROL_LEFT);
    // Debounce and wait
    DigiKeyboard.delay(500); 
  }

  // Button 2: Win + R (Run)
  if (digitalRead(button2) == LOW) {
    DigiKeyboard.sendKeyStroke(KEY_R, MOD_GUI_LEFT);
    // Debounce and wait
    DigiKeyboard.delay(500); 
  }
}

looks simple enough. I've always found uploading to be a PITA, so haven't used digispark since long enough so it may be easier now.

Othe Arduino boads were always easier to use, but that's what the code looks hike.

a7

as far as showing you i got nothing right now as i didnt know where to start.

i entered your code and hit verify and got this

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\ryder\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\ryder\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\ryder\Documents\Arduino\libraries -fqbn=ATTinyCore:avr:attinyx5micr:LTO=enable,TimerClockSource=default,sketchclock=165pll,bod=disable,millis=enabled,burnmode=upgrade,resetpin=reset -ide-version=10819 -build-path C:\Users\ryder\AppData\Local\Temp\arduino_build_81485 -warnings=all -build-cache C:\Users\ryder\AppData\Local\Temp\arduino_cache_330414 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\ryder\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\ryder\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.micronucleus.path=C:\Users\ryder\Documents\ArduinoData\packages\ATTinyCore\tools\micronucleus\2.5-azd1b -prefs=runtime.tools.micronucleus-2.5-azd1b.path=C:\Users\ryder\Documents\ArduinoData\packages\ATTinyCore\tools\micronucleus\2.5-azd1b -prefs=runtime.tools.avrdude.path=C:\Users\ryder\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino18 -prefs=runtime.tools.avrdude-6.3.0-arduino18.path=C:\Users\ryder\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino18 -verbose C:\Users\ryder\AppData\Local\Temp\arduino_modified_sketch_548065\Keyboard.ino
C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\ryder\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\ryder\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.57.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\ryder\Documents\Arduino\libraries -fqbn=ATTinyCore:avr:attinyx5micr:LTO=enable,TimerClockSource=default,sketchclock=165pll,bod=disable,millis=enabled,burnmode=upgrade,resetpin=reset -ide-version=10819 -build-path C:\Users\ryder\AppData\Local\Temp\arduino_build_81485 -warnings=all -build-cache C:\Users\ryder\AppData\Local\Temp\arduino_cache_330414 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Users\ryder\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Users\ryder\Documents\ArduinoData\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7 -prefs=runtime.tools.micronucleus.path=C:\Users\ryder\Documents\ArduinoData\packages\ATTinyCore\tools\micronucleus\2.5-azd1b -prefs=runtime.tools.micronucleus-2.5-azd1b.path=C:\Users\ryder\Documents\ArduinoData\packages\ATTinyCore\tools\micronucleus\2.5-azd1b -prefs=runtime.tools.avrdude.path=C:\Users\ryder\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino18 -prefs=runtime.tools.avrdude-6.3.0-arduino18.path=C:\Users\ryder\Documents\ArduinoData\packages\arduino\tools\avrdude\6.3.0-arduino18 -verbose C:\Users\ryder\AppData\Local\Temp\arduino_modified_sketch_548065\Keyboard.ino
Using board 'attinyx5micr' from platform in folder: C:\Users\ryder\Documents\ArduinoData\packages\ATTinyCore\hardware\avr\1.5.2
Using core 'tiny' from platform in folder: C:\Users\ryder\Documents\ArduinoData\packages\ATTinyCore\hardware\avr\1.5.2
Detecting libraries used...
"C:\\Users\\ryder\\Documents\\ArduinoData\\packages\\arduino\\tools\\avr-gcc\\7.3.0-atmel3.6.1-arduino7/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=attiny85 -DF_CPU=16500000L -DCLOCK_SOURCE=6 -DARDUINO=10819 -DARDUINO_AVR_ATTINYX5 -DARDUINO_ARCH_AVR -DNEOPIXELPORT=PORTB -DHASUSB -DBOOTTUNED165 "-IC:\\Users\\ryder\\Documents\\ArduinoData\\packages\\ATTinyCore\\hardware\\avr\\1.5.2\\cores\\tiny" "-IC:\\Users\\ryder\\Documents\\ArduinoData\\packages\\ATTinyCore\\hardware\\avr\\1.5.2\\variants\\tinyX5" "C:\\Users\\ryder\\AppData\\Local\\Temp\\arduino_build_81485\\sketch\\Keyboard.ino.cpp" -o nul
Alternatives for DigiKeyboard.h: []Keyboard:1:10: fatal error: DigiKeyboard.h: No such file or directory

ResolveLibrary(DigiKeyboard.h)

  -> candidates: []~~~~~~~

compilation terminated.
exit status 1
DigiKeyboard.h: No such file or directory



i do however have this library set

#include <DigiKeyboardUK.h>
#include <oddebug.h>
#include <osccal.h>
#include <osctune.h>
#include <scancode-ascii-table.h>
#include <usbconfig-prototype.h>
#include <usbconfig.h>
#include <usbdrv.h>
#include <usbportability.h>

That's not nothing. Where did you get them? I don't even know how to make a list of the libraries I habe!

Try again after installing the missing library.

a7

i found it while doing some google searching before posting on here.

where would one locate the library required to install?

If you have google over there, add Arduino to any search, like

installing an arduino library

and get results like

https://docs.arduino.cc/software/ide-v1/tutorials/installing-libraries/

HTH

a7

yes however when i check in the library manager i get only belgian or french keyboards when searching for “digikeyboard”

as for the other options i dont know where to download the zip for the library mentioned, or the web address to enter it into the other screen where it will download it itself.

okay i got the libary, when verifying your code i get these errors

In file included from C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:13:0,
                 from C:\Users\ryder\AppData\Local\Temp\arduino_modified_sketch_419351\Keyboard.ino:1:
c:\users\ryder\documents\arduinodata\packages\arduino\tools\avr-gcc\7.3.0-atmel3.6.1-arduino7\avr\include\avr\delay.h:36:2: warning: #warning "This file has been moved to <util/delay.h>." [-Wcpp]
 #warning "This file has been moved to <util/delay.h>."
  ^~~~~~~
In file included from C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:16:0,
                 from C:\Users\ryder\AppData\Local\Temp\arduino_modified_sketch_419351\Keyboard.ino:1:
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/usbdrv.h:479:26: error: variable 'usbDescriptorDevice' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 char usbDescriptorDevice[];
                          ^
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/usbdrv.h:485:33: error: variable 'usbDescriptorConfiguration' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 char usbDescriptorConfiguration[];
                                 ^
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/usbdrv.h:491:29: error: variable 'usbDescriptorHidReport' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 char usbDescriptorHidReport[];
                             ^
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/usbdrv.h:497:27: error: variable 'usbDescriptorString0' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 char usbDescriptorString0[];
                           ^
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/usbdrv.h:503:31: error: variable 'usbDescriptorStringVendor' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 int usbDescriptorStringVendor[];
                               ^
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/usbdrv.h:509:31: error: variable 'usbDescriptorStringDevice' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 int usbDescriptorStringDevice[];
                               ^
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/usbdrv.h:515:37: error: variable 'usbDescriptorStringSerialNumber' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 int usbDescriptorStringSerialNumber[];
                                     ^
In file included from C:\Users\ryder\AppData\Local\Temp\arduino_modified_sketch_419351\Keyboard.ino:1:0:
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:40:73: error: variable 'usbDescriptorHidReport' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
 PROGMEM char usbHidReportDescriptor[USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH] = { /* USB report descriptor */
                                                                         ^
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:59:1: error: narrowing conversion of '161' from 'int' to 'char' inside { } [-Wnarrowing]
 };
 ^
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:59:1: error: narrowing conversion of '224' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:59:1: error: narrowing conversion of '231' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:59:1: error: narrowing conversion of '149' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:59:1: error: narrowing conversion of '129' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:59:1: error: narrowing conversion of '149' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:59:1: error: narrowing conversion of '129' from 'int' to 'char' inside { } [-Wnarrowing]
C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard/DigiKeyboard.h:59:1: error: narrowing conversion of '192' from 'int' to 'char' inside { } [-Wnarrowing]
Using library DigisparkKeyboard in folder: C:\Users\ryder\Documents\Arduino\libraries\DigisparkKeyboard (legacy)
exit status 1
Error compiling for board ATtiny85 (Micronucleus / DigiSpark).

Please, show the picture of the board you have planned to use.

its a digispark with attiny85 chip

i use these all the time on other projects but never came across these errors before. then again i’ve never used one for usb keyboard application lol

I have also worked with this board. Now, kindly explain you project. Where do you want to connect the 2-key and with which device you want to communicate with these2-key?

i’ll explain from the main post the requirements again,

2 momentary buttons will be connected, likely pin 0 and 1 and ground. the board will be plugged into a usb extension cable and connected to a laptop running mach3mill.

the chip needs to pickup the button presses and relay that to the laptop as keyboard key strokes

You need an application at the PC side that will sense the closing position of a key with the ATtiny85. Also, you need firmware at the ATtiny85 side to sense the closing position of a key and relay that status to PC via USB Port. Do you have these applications ready or you are trying to make them?

the idea is that the digispark can be plugged into the pc, recognised as a usb keyboard and the buttons are the keyboard keys as i only require 2 “keys” im trying to avoid additional software on the laptop and keep it built into the digispark

Have you Googled to get help? I See from this link Google Search what Google can offer you? There is a lot of works involved which if done with patience, the project can be realized.

You need additional software at PC side to catch the key stroke going to PC and then send it to your traget Device via another USB Port.

um……ive done this so far, if you look back up through the thread, the arduino ide is returning errors im not familiar with when trying to verify

Connect two UNOs with PC. Read a character from the InputBox of IDE1 of UNO-1 and then send it to the OutputBox of IDE2 of UNO2. You can't do it directly. You need a 3rd Software for your PC that will work as a Mediator.

i thought the whole point of the keyboard library was to prevent the need for third party software and make it plug and play?

Solve the exercise of post #18 and then apply it in your ATtiny85 project.

You can connect your 2-key ATtiny85 using a TTL/USB converter with PC. Get a Mediator Software for you PC to read key strokes from ATtiny85 and then send them to your target device.