Package: pymikro
AboutPython module to control the Maschine Mikro MK3. It allows you to use this maschine not only to create music, but also to control a home automation or a robot or any other creative stuff.It uses directly the USB HID protocol, as a result there is no dependency on a product specific driver and it can run on any operating system. Furthermore, this gives you access to the full capabilities of this hardware which makes it even more fun to use.Usageimportpymikromaschine=pymikro.MaschineMikroMk3()# control LEDslState={'button':{'stop':{'val':1}},'strip':{1:{'val':3,'color':'blue'}},'pad':{1:{'val':3,'color':'purple'}}}maschine.setLights(lState)maschine.setLight('pad',6,3,'orange')maschine.setLight('strip',5,3,'green')maschine.setLight('button','notes',4)maschine.updLights()# control screenmaschine.setScreen("Hello World!\nIt's working")# get button and pad updateswhileTrue:cmd=maschine.readCmd()ifcmd:ifcmd['cmd']=='pad':print('Pad number{}pressed:{}'.format(cmd['pad_nb'],cmd['pad_val']))ifcmd['cmd']=='btn':print('Buttons pressed:{}'.format(cmd['btn_pressed']))SetupLinuxInstall the hid driversudo apt-get install libhidapi-hidraw0Install the packagepip3 install pymikroSet permissions for the devicecd /tmp
wget https://raw.githubusercontent.com/flokapi/pymikro/main/50-ni-maschine.rules
sudo cp 50-ni-maschine.rules /etc/udev/rules.d/Plug or re-plug the maschine mikro USB cable.WindowsInstall the hid driver:Donwload the latest version ofhidapi-win.zipfromhttps://github.com/libusb/hidapi/releasesExtract the zip file and copy thehidapi.dllcorresponding to your architecture toC:\Users\<Username>\AppData\Local\Programs\PythonInstall the packagepip3 install pymikroPlug or re-plug the maschine mikro USB cable.AboutSupported hardware featuresOverall, there is actually more feature than the manufacturer uses :)Pads:Set color (17 possible values) and intensityGet pressure valueInfo whether pressed, touched, or releasedButtons:get buttons being pressedset light brightnessEncoder:get value of the encoder (1 byte), and how much it movedwhether it's being touched (not pressed)Touch strip:get position of up to 2 fingersset color and brightness of each LEDScreen:set text with adjustable size, on 1 or 2 linesSupported operating systemsTested on Linux &  WindowsShould also work on OSX by installing the hid api. Seehttps://pypi.org/project/hid/APIConnectionimportpymikromaschine=pymikro.MaschineMikroMk3()maschine.showConnInfo()InputsLEDs:The state of the LEDs for the pads/touch strip/buttons is defined in a single data-structure which can be accessed and modified using thegetLightsandsetLightsmethods. The LEDs can also be set individually usingsetLight.To apply the changes,updLightsmust be called. Using a separate command allows to apply all the changes in a single write procedure (about 15ms) and increases the reactivity.Example:maschine.setLights({})# set empty dictionary to disable all LEDsmaschine.updLights()time.sleep(1)lState={'button':{'stop':{'val':1}# Button brighness value must be between 0},'strip':{1:{'val':4,'color':'blue'}# Touch Strip LED brightness value must be between 0 and 3},'pad':{1:{'val':3,'color':'purple'}# Pad brightness value must be between 0 and 3}}maschine.setLights(lState)maschine.setLight('pad',6,3,'orange')# pad nb 6, brightness 3.maschine.setLight('strip',5,3,'green')# strip led nb 5, brightness 3.maschine.setLight('button','notes',4)# button 'notes', brightness 4.maschine.updLights()ScreenExamplemaschine.setScreen("Hello",24)# Font size set to 24maschine.setScreen(f"Hello World!\nIt's working")# Printing text on both lines with '\n'.# Default font size is 14OutputsOutput commands can be read in a nonblocking way using thereadCmdmethod, which returns:Noneif no new command is availableA dictionary which content differs depending on thecmdkey value (btnorpad)Example:cmd = maschine.readCmd()PadsThe pad command is only sent when the state of a pad is being changed (pressed/touched/released). The pad command is sent for a single pad at the time.Example{'cmd':'pad','pad_nb':5,'pad_val':1360,# between 0 and 4095'touched':True,# finger in contact with the pad'pressed':False,# finger just pressed the pad (not 100% reliable)'released':False# finger just released the pad (not 100% reliable)}Buttons:The button command is only sent when the state of the buttons/touch strip/encoder changed (including button release). The command contains the full state of the button group.Example{'cmd':'btn','btn_pressed':['group','pattern','enter'],# currently pressed buttons'encoder_pos':10,# byte, cyclic value between 0 and 15'encoder_move':1,# encoded moved to the right (+1) or left (-1)'encoder_touched':True,# finger in contact with the encoder'strip_pos_1':123,# value of the strip if one finger touching'strip_pos_2':0# second value if another finger is on the strip}Alternativesmaschine-mikro-mk3-driverBuilt for Linux onlyMakes the Maschine Mikro available through a midi interfaceCoded in RustMidi modeWindows/OSX only (midi interface emulated by the driver)pressshiftandprojectto enter midi modeyou can usemidoor any other software to handle the midi commandslimited features/customization