Student_AJ
Posts: 8
Joined: Thu Apr 04, 2019 12:35 am

School Project Help

Thu Apr 04, 2019 12:47 am

Hi,

I am a high school student and it is the first time I had ever worked with Raspberry Pi. My team and I were planning on using a MIDI Keyboard to unlock a PC, and we have no clue on to where to start. We did some research and figured out using the Raspberry Pi will be a plausible method for accomplishing this. Here's what we system engineered so far...
1. Use Akai LPK25 Keyboard to send midi messages (or binary) to the Raspberry Pi
2. Raspberry Pi will run a program in Python (the best programming language for us I believe) to convert these midi messages to text
3. Either text will be printed on to the logon screen or the PC automatically unlocks itself
Or we have the RPi check to see if the musical notes are correct no matter the velocity and RPi will run a program unlocking the PC immediately.

We initially came up with this idea of innovation to help people with memory loss of distinct passwords. Music is easier to remember and hard to forget so we incorporated that as our project for the semester.

All help will be greatly appreciated! Please ask any questions that will clear up any information that does not seem clear.

Andyroo
Posts: 3299
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: School Project Help

Thu Apr 04, 2019 2:49 am

How about using the Pi zero in USB mode to create a HID (human interface device) that unlocks the PC?
Need Pi spray - these things are breeding in my house...

mattmiller
Posts: 2061
Joined: Thu Feb 05, 2015 11:25 pm

Re: School Project Help

Thu Apr 04, 2019 6:22 am

I played with midi a while ago - this thread might give you some pointers to getting started

viewtopic.php?p=1275176

User avatar
rpdom
Posts: 14425
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: School Project Help

Thu Apr 04, 2019 6:41 am

Andyroo wrote:
Thu Apr 04, 2019 2:49 am
How about using the Pi zero in USB mode to create a HID (human interface device) that unlocks the PC?
Then how would you connect the (USB) MIDI keyboard to the Pi?

It could be done with two Pi zeroes, back to back, connected via wireless, bluetooth, serial or even just a simple GPIO signal to say "Unlock".
One would handle the MIDI keyboard, the other could act as the HID.

incognitum
Posts: 277
Joined: Tue Oct 30, 2018 3:34 pm

Re: School Project Help

Thu Apr 04, 2019 10:36 am

Or use a single Pi, let it communicate with the Akai using USB, and with PC through Bluetooth.
There has been prior success letting a Pi pretend it is a Bluetooth keyboard: https://github.com/mlabviet/BL_keyboard_RPI

ejolson
Posts: 3039
Joined: Tue Mar 18, 2014 11:47 am

Re: School Project Help

Fri Apr 12, 2019 1:58 am

rpdom wrote:
Thu Apr 04, 2019 6:41 am
Andyroo wrote:
Thu Apr 04, 2019 2:49 am
How about using the Pi zero in USB mode to create a HID (human interface device) that unlocks the PC?
Then how would you connect the (USB) MIDI keyboard to the Pi?

It could be done with two Pi zeroes, back to back, connected via wireless, bluetooth, serial or even just a simple GPIO signal to say "Unlock".
One would handle the MIDI keyboard, the other could act as the HID.
I thought midi was a fairly simple low speed serial connection. Could the keyboard be connected through appropriate level converters to the serial UART on the GPIO connector?

User avatar
rpdom
Posts: 14425
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: School Project Help

Fri Apr 12, 2019 4:04 am

ejolson wrote:
Fri Apr 12, 2019 1:58 am
I thought midi was a fairly simple low speed serial connection. Could the keyboard be connected through appropriate level converters to the serial UART on the GPIO connector?
Not directly. You would need an interface circuit. Fortunately it wouldn't be that complicated to make one. MIDI is based on a current loop running from 5V via a 220 Ohm resistor. The input should be used to drive an opto-isolator so that the Pi is completely isolated from the keyboard's power circuits. The output (probably not needed in this case) would need a buffer to drive the 5V signal through the resistor. The speed could be an issue as it is an unusual 31250 bps.

User avatar
B.Goode
Posts: 7859
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: School Project Help

Fri Apr 12, 2019 11:23 am

My team and I were planning on using a MIDI Keyboard to unlock a PC, and we have no clue on to where to start. We did some research and figured out using the Raspberry Pi will be a plausible method for accomplishing this.

There is a recent blog post on the Raspberry Pi Foundation website that might provide some inspiration: https://www.raspberrypi.org/blog/midi-c ... pberry-pi/


(If you can get the RPi to respond to a midi input and turn on a light, it can't be that different to operate a lock instead... ?)

Student_AJ
Posts: 8
Joined: Thu Apr 04, 2019 12:35 am

Re: School Project Help

Thu Apr 18, 2019 7:57 pm

mattmiller wrote:
Thu Apr 04, 2019 6:22 am
I played with midi a while ago - this thread might give you some pointers to getting started

viewtopic.php?p=1275176
hi mattmiller,

the project you did is similar to ours. however, I am running into trouble in code where it states: "print pygame.midi.get_device_info(x)."
the terminal highlights "pygame" and says it is invalid syntax.

thanks for the help,

AJ

gordon77
Posts: 3999
Joined: Sun Aug 05, 2012 3:12 pm

Re: School Project Help

Thu Apr 18, 2019 8:34 pm

If using python3 do you just need some brackets...

print (pygame.midi.get_device_info(x))

mattmiller
Posts: 2061
Joined: Thu Feb 05, 2015 11:25 pm

Re: School Project Help

Thu Apr 18, 2019 8:52 pm

As @gordon77 points out - I used Python 2 - hopefully it's just the print's that need translating

hippy
Posts: 5344
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: School Project Help

Thu Apr 18, 2019 9:08 pm

rpdom wrote:
Fri Apr 12, 2019 4:04 am
ejolson wrote:
Fri Apr 12, 2019 1:58 am
I thought midi was a fairly simple low speed serial connection. Could the keyboard be connected through appropriate level converters to the serial UART on the GPIO connector?
Not directly. You would need an interface circuit. Fortunately it wouldn't be that complicated to make one. MIDI is based on a current loop running from 5V via a 220 Ohm resistor. The input should be used to drive an opto-isolator so that the Pi is completely isolated from the keyboard's power circuits. The output (probably not needed in this case) would need a buffer to drive the 5V signal through the resistor. The speed could be an issue as it is an unusual 31250 bps.
When a MIDI keyboard has a 5-pin DIN MIDI Out then it is usually trivial to connect that direct to a digital input even if that input won't be compliant with the MIDI specification.

If it's an active output, giving 0V and 5V, just a current limiting resistor will usually work with most micros but for the Pi a resistor ladder to drop 5V to 3V3 would be required. If it's an open collector output then a pull-up tot 3V3 will be required.

As you note, a specification compliant interface would simply be an opto-isolator so not difficult or costly to design or add.

Unfortunately the Akai LPK25 doesn't appear to have a 5-PIN DIN MIDI Out so would require a MIDI USB to 5-Pin DIN adapter, or be connected via USB.
Last edited by hippy on Thu Apr 18, 2019 9:08 pm, edited 1 time in total.

Student_AJ
Posts: 8
Joined: Thu Apr 04, 2019 12:35 am

Re: School Project Help

Thu Apr 18, 2019 9:08 pm

mattmiller wrote:
Thu Apr 18, 2019 8:52 pm
As @gordon77 points out - I used Python 2 - hopefully it's just the print's that need translating
thanks @gordon77, it works. But another error shows up at the operation "<>". I'm having difficulty finding what that means online.

mattmiller
Posts: 2061
Joined: Thu Feb 05, 2015 11:25 pm

Re: School Project Help

Thu Apr 18, 2019 9:10 pm

<> means not equal to

I don't program in Python 3 but try replacing with != and see if that works

Student_AJ
Posts: 8
Joined: Thu Apr 04, 2019 12:35 am

Re: School Project Help

Thu Apr 18, 2019 9:11 pm

hippy wrote:
Thu Apr 18, 2019 9:08 pm
rpdom wrote:
Fri Apr 12, 2019 4:04 am
ejolson wrote:
Fri Apr 12, 2019 1:58 am
I thought midi was a fairly simple low speed serial connection. Could the keyboard be connected through appropriate level converters to the serial UART on the GPIO connector?
Not directly. You would need an interface circuit. Fortunately it wouldn't be that complicated to make one. MIDI is based on a current loop running from 5V via a 220 Ohm resistor. The input should be used to drive an opto-isolator so that the Pi is completely isolated from the keyboard's power circuits. The output (probably not needed in this case) would need a buffer to drive the 5V signal through the resistor. The speed could be an issue as it is an unusual 31250 bps.
When a MIDI keyboard has a 5-pin DIN MIDI Out then it is usually trivial to connect that direct to a digital input even if that input won't be compliant with the MIDI specification.

If it's an active output, giving 0V and 5V, just a current limiting resistor will usually work with most micros but for the Pi a resistor ladder to drop 5V to 3V3 would be required. If it's an open collector output then a pull-up tot 3V3 will be required.

As you note, a specification compliant interface would simply be an opto-isolator so not difficult or costly to design or add.

Unfortunately the Akai LPK25 doesn't appear to have a 5-PIN DIN MIDI Out so would require a MIDI USB to 5-Pin DIN adapter, or be connected via USB.
currently im using usb to connect my akai lpk25 to the rpi3b+, will that be an issue? or do i need the 5-pin din adapter?

Student_AJ
Posts: 8
Joined: Thu Apr 04, 2019 12:35 am

Re: School Project Help

Thu Apr 18, 2019 9:15 pm

mattmiller wrote:
Thu Apr 18, 2019 9:10 pm
<> means not equal to

I don't program in Python 3 but try replacing with != and see if that works
thanks so much @mattmiller, the code works great and recognizes my midi keyboard.

I appreciate everyone's efforts in helping my group finish our projects!

AJ

hippy
Posts: 5344
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: School Project Help

Thu Apr 18, 2019 9:27 pm

Student_AJ wrote:
Thu Apr 18, 2019 9:11 pm
currently im using usb to connect my akai lpk25 to the rpi3b+, will that be an issue? or do i need the 5-pin din adapter?
No that's absolutely fine.

The 3B+ cannot connect to the PC as a USB device/gadget so you might as well use the USB to connect to the keyboard as you are doing.

Student_AJ
Posts: 8
Joined: Thu Apr 04, 2019 12:35 am

Re: School Project Help

Thu Apr 18, 2019 9:30 pm

so i attempted the code, it works, thanks to you all especially @mattmiller. but, i don't know where to go one from here. how is the raspberry pi supposed to unlock my laptop once it says "password accepted".

appreciate all help!

sushant_ocv
Posts: 15
Joined: Mon May 20, 2019 8:14 am

Re: School Project Help

Fri May 31, 2019 5:26 am

Andyroo wrote:
Thu Apr 04, 2019 2:49 am
How about using the Pi zero in USB mode to create a HID (human interface device) that unlocks the PC?
Yes, this suggestion could could be useful here.

sushant_ocv
Posts: 15
Joined: Mon May 20, 2019 8:14 am

Re: School Project Help

Fri May 31, 2019 5:26 am

I like this idea to create Pi zero in USB mode.

Return to “General programming discussion”