Advice needed for taking input from 53 LDRs..

Jeremy Leach

Senior Member
I wonder if a Phase Locked Loop circuit could directly pick up the tone you whistle, assuming the tone is pretty pure? Would be an interesting experiment. It might be a long shot though. 'If' it worked then it could possibly be some fairly simply circuitry directly connected to a PICAXE.
 

moorea21

Senior Member
YES, for test purpose. I can use #7, but is it a partial or full screen copy ?
I think I reduced it by 50%

Try this one instead. It's a full screen (1920 x 1200) screenshot.

Also, if following my instructions in previous post caused the overtone analyzer screen to go blank, move the green vertical line (that show where it will play from) slightly with the mouse, the 'trace' as I call it will come back.
 

Attachments

moorea21

Senior Member
Phase locked loop: for some reason thats caught my attention, although I can't remember what a phase locked loop is. Looking that up now.

Edit: Yes, I like the sound of that, as a side project to this one. I think whistling like singing produces a lot of overtones, some of which are quite prominent ( I beleive overtone analyzer uses this sort of property to its advantage) so I don't know how good it would be at determining the fundamental frequency, but it sounds like it would be cheap and possibly straightforward to experiment with. Thanks Jeremy.

A processor could tell an IC (phase locked loop IC) to generate each of the 53 target frequencies in turn, maybe 20 times a second, although that would mean the lower frequencies might not be present for enough cycles to get a reliable match. The lowest frequency I would need to find would be 196Hz; 1/53 of 1/20th of a second would be considerably less than 1 cycle at 196Hz.
 
Last edited:

BESQUEUT

Senior Member
New code sent.
Now scan only Abcissa column
By default, color is your blue
Send data to serial if opened (not tested)
Violin2.jpg
Not that precision=0 does not work with screen copy.
Look like jpeg compression change the color. The distance for founded line is 1, not zero.
 

premelec

Senior Member
@moorea21 - If I've got it right you want to practice a violin without using a bow... given the many electric stringed instruments which put out electrical sound it would seem there is a way to pick up the string vibration... perhaps with IC accelerometers or the more trad microphone... the vibration is there even when not bowed; it's at a very much lower mechanical level so you'd expect to hear case noises as well as the string... If I've got your intent right I wonder if you have just tried an amplified microphone pick up...
 

moorea21

Senior Member
It's not so much about playing without a bow.

My design involves pressing a string onto a fret to close a switch, triggering the pwm to play the appropriate frequency for that note. Its the pwm's output piezo that does the vibrating, not the string.

The essence of the whole project is 'if I can whistle it, I can play it', which is acheived by picking up the frequency of me whistling into a microphone plugged into my pc with 'Overtone Analyzer', which shows a blue line on screen to indicate the pitch of the received note(s.) This line is then picked up by Besqueut's VB exe, which sends data unique to each frequency to the picaxe, which quantises this and outputs to the array of 120 led's on the 'violin' (term used loosely here...) fingerboard. Only the led(s) corresponding to that note light up.

So in that way I get to see where the note I'm whistling is on the fingerboard. If I then press the string onto the fret closest to the lit led (see 3rd paragraph), I will hear that note playing through the pwn as a feeble buzz (at the moment; will work on that.)

Really , the only 2 instruments I can play are the violin and my own voice/whistling. It just struck me that it would be great to have the same 'fluency' with the violin as I have with my own vocalisations. This is my attempt at achieving this. It's a way of getting a 'feel' for where the notes are, and playing/composing by ear. When I know the song well enough (muscle memory), I'll pick up the real violin and I'll already know where all the notes are, so to speak.

I think I've done a poor job of explaining this before. Hopefully this explanation is an improvement.
 
Last edited:

slimplynth

Senior Member
I read this thread yesterday and was fascinated, completely lost but interested because i feel your plight. I have what I know to be mild cerebral palsy from a birth injury.. my left hand is only good for anything requiring a really strong grip.. anything requiring agility is a losing streak.. left foot is limp to the point i want to cut it off myself some days.. but i know people far worse off than I.. I just have to pay German Engineers a lot of money for hidden/carbon fibre leg braces..

Guitar is my favourite but dexterity fails me so the idea of whistling.. i can completely understand in terms of practise time.. thinking about your proposed solution.. i just wonder what happens when you press a fret on a string connected to a picaxe Touch input.. (Just re-read/searched the thread.. AllyCat suggested this earlier.. the 28X2 has enough Touch inputs.)

Fascinating project, hope you get it sorted.
 

moorea21

Senior Member
Besqueut:-

Outstanding work on the VB program. I've ran the exe loads of times now, and I can say confidently that set as it was when you sent it to me, it is 100% accurate at determining the vertical distance to the first pixel of target colour. I played it an animation of overtone analyzer's screen which I made in photoshop. Set to run at 30fps, the exe missed a lot of notes (each was set to be on screen for only 1 frame, ie .033 seconds.) But this is faster than the fastest 'grace notes' that I can play anyway. Resetting the frame rate to 20 fps produced a correct reading every time, no missed notes. It does lag behind by an average of about 0.1 seconds though (0.07 to 0.16 seconds.)

If it was possible to halve the lag to an average of about 0.04 seconds (ish) then , assuming there was minimal lag in the serial connection, picaxe code, and the lighting of the LED's (unlikely I know; but the leds seem to be instantaneous, so that's something.) it would be more than satisfactory ( a lot more). Even if not, it would be perfectly useable, but maybe would take a bit more getting used to when trying to play fast.

What are the chances of there being next to no lag in the serial connection and picaxe code? I dont know what to expect from it.

In order to take the load off the little picaxe, it would probably be good to quantise the '1st pixel of target colour' data into its 53 notes in VB rather than in the picaxe?

Can the exe as it is be made twice as fast? I think from what I can see in looking at form1 in notepad, it takes a screenshot of the whole screen, not just the 'slice?' Could the timer object be set for a shorter duration? (assuming there is one, as I said Visual Studio wouldnt open it. I couldnt get it to open in visual studio to look at the rest of it.

No problem if not, it works 99% straight out of the box.

The other thing it does is warn of an unhandled exception (arithmetic operation resulting in overflow); I attached it if its any help. It seems to carry on working while the dialogue box asking 'do you want to quit' (or something) is still on screen. If I opt to carry on, it works fine too, but the exception happens again shortly after. It happens regardless of whether there is any of the target colour on screen, btw.

Overall, very happy with it. Thanks!
 

Attachments

moorea21

Senior Member
Of course I could possibly halve the exe's response time by reducing my screen resolution to 600 x 800 temporarily?

I'll test that tomorrow if I get the chance.
 
Last edited:

moorea21

Senior Member
Thankyou slimplynth, I'm glad you understand! I should really do a schematic of the circuit and post it here, its turned out that it works very well.
 

slimplynth

Senior Member
You should share, you'll be helping yourself and others too.. ( a few exceptions spring to mind) I always found the people on this forum to be beyond helpful. (what happened to Boris, Dippy, Eclectic.. ) i don't see these names anymore... that is a sadness... if you don't miss these names, you should.. they brought life to this forum (Hippy, you'll likely be still in touch with them, if you are.. send my best).
 

moorea21

Senior Member
I'll do that, when it's all up and running. Probably I'll put a schematic on here before that anyway.

Probably the biggest hurdle will be building the physical instrument thing itself, but when thats done, I intend to post it as a complete project.

Totally agree about this forum, probably the best one I've ever used, certainly the best electronics one. Some forums are truly awful (terrible interface, ignorant rude ill informed posters and no moderation to speak of...) - this is at the opposite end of the scale.
 

BESQUEUT

Senior Member
Of course I could possibly halve the exe's response time by reducing my screen resolution to 600 x 800 temporarily?
I'll test that tomorrow if I get the chance.
No need for that.
No time this WE, but I will have some Monday or Tuesday. WIll try improvements as suggested. Writing results on the screen is often time consuming, but it is for debug purpose, and not needed in fact.
Will also test the serial output.
Did you manage to run V.Studio ?
 

moorea21

Senior Member
Did you manage to run V.Studio ?
I tried it, it wouldnt open your project. Wrong .NET framwork; link to download it took me to MSN...

Should be possible to get it to work, although HD space is quite tight now. When I get it working, I'll probably tinker with it myself a bit.

Have a good week anyway.
 

moorea21

Senior Member
No need. It turns out that when visual studio installs (including .NET Framework 4.6.1 and SDK) it doesnt bother with the targetting pack for .NET Framework 4.6.1. Found and installed, so I now have working VS.
 

moorea21

Senior Member
A bit of extra information;

On my 1920 x 1200 screen, each note takes up 20 px of height. The first one starts at x = 79, the last one ends at x = 1139. So thats 53 note values to quantise.

Note number (1 to 53, 1 being the lowest) will equal 53 - (Y - 79 / 20) where Y = the value of Y returned from the exe. Will try getting that to write note number to the screen tomorrow, along with setting the timer interval to 20, although as you said the lag probably mostly comes from writing the debug data. Just want to see if it falls over really...!
 
Last edited:

moorea21

Senior Member
And yet more, in case it helps:-

This is what I think may work, it involves the VB app calculating the values for the MAX7219 addresses before sending that data via serial to the picaxe, which will provide the clk and load signals needed to drive the data onto the max7219. Minimum load on the picaxe.

This is not thoroughly checked, my use of parentheses may not be any good, it's been a long day, and many long days since I did maths at school.

Is this likely to be faster or slower than getting the VB app to look up the values to send from a lookup table, having first found the correct note by quantising Y?

Data package for MAX7219 is this format:-

xxxx 0111 0100 0000
4 unused bits, 4 address bits, 8 data bits

I've attached a .txt file of note numbers vs address/data bits.

In order to arrive at 12 bits for the MAX7219 from 'Y', these calculations need to be performed (pseudocode version):-

1) noteNum = 53 - (Y - 79 / 20) 'detailed previously
2) address = (noteNum - c) / 8 + 1
3) data = 2 ^ (c - 1) '2 to the power of

Where c is the 1st integer you can do sum 2 with, without ending up with a 'remainder'. So maybe this is a good way of acheiving this:-

For i = 1 to 8
If noteNum - i // 8 = 0 then c = i: break 'If remainder((noteNum - i) / 8 +1) = 0 then c = i
Next

address = (53 - (Y - 79 / 20) - c) / 8 + 1
data = 2 ^ (c - 1)

Then, to shift the address bits to the left of the data bytes, multiply it by 256 and 'AND' it with the 2 data bytes (I think)

So that for instance, if Y = 700, (noteNum = 31), c turns out to be 7, address is 0100, data is 0100 0000, and the final data string (12 bits of it anyway) will be

0100 0100 0000

which would be the 31st led in my array.

Is a look up table in VB likely to be faster?
 

Attachments

BESQUEUT

Senior Member
New version :
Violin3.jpg
- Copy only one pixel column from screen,
- chose file for output
- chose refresh rate
- chose to output : on screen, on file, on serial
- chose to not use timer, but direct looping
==> frame rate = 50 frames/s :
Code:
09:30:40.94 168 49
09:30:40.96 168 49
09:30:40.97 168 49
09:30:40.99 168 49
09:30:41.01 168 49
09:30:41.02 168 49
09:30:41.04 168 49
09:30:41.06 168 49
09:30:41.07 168 49
09:30:41.09 168 49
09:30:41.11 168 49
09:30:41.12 168 49
09:30:41.14 168 49
09:30:41.16 168 49
09:30:41.17 168 49
09:30:41.19 168 49
09:30:41.21 168 49
09:30:41.22 168 49
09:30:41.24 168 49
09:30:41.26 168 49
09:30:41.27 168 49
09:30:41.29 168 49
09:30:41.31 168 49
09:30:41.32 168 49
09:30:41.34 168 49
09:30:41.36 168 49
09:30:41.37 168 49
09:30:41.39 168 49
09:30:41.41 168 49
09:30:41.42 168 49
09:30:41.44 168 49
09:30:41.46 168 49
09:30:41.47 168 49
09:30:41.49 168 49
09:30:41.51 168 49
09:30:41.52 168 49
09:30:41.54 168 49
09:30:41.56 168 49
09:30:41.57 168 49
09:30:41.59 168 49
09:30:41.61 168 49
09:30:41.62 168 49
09:30:41.64 168 49
09:30:41.66 168 49
09:30:41.67 168 49
09:30:41.69 168 49
09:30:41.71 168 49
09:30:41.72 168 49
09:30:41.74 168 49
09:30:41.76 168 49
09:30:41.77 168 49
09:30:41.79 168 49
09:30:41.81 168 49
09:30:41.82 168 49
09:30:41.84 168 49
09:30:41.86 168 49
09:30:41.87 168 49
09:30:41.89 168 49
09:30:41.91 168 49
09:30:41.92 168 49
09:30:41.94 168 49
09:30:41.96 168 49
09:30:41.97 168 49
09:30:41.99 168 49
09:30:42.01 168 49
09:30:42.02 168 49
09:30:42.04 168 49
 

moorea21

Senior Member
That is super fast. I set frames/ sec to 100, still runs.
If I tick 'no timer' I get 'Not Responding', higher processor load and sluggish response to input like the tickbox etc.
If this line:

For Y = 0 To screenshot.Size.Height / 2 - 1

was changed to just

For Y = 0 To screenshot.Size.Height

would it still work as well?

Also, I'll add 'N' to the list of variables to print to screen, so line 102 becomes

Me.Text = "Y=" & Y & " N=" & N

Unfortunataely I can't test these so far, as I just can't find a 'Run' button on VS... duh! Where is it? Assuming one exists... I googled this, the first 5 results didnt work for me.

Did my last post on here make any sense?

Good to see it can work so fast, much respect to you for that, and to VB, which I will now no longer refer to as 'slow'...

AS ever, very grateful for the time and thought you are putting into helping me.
 

BESQUEUT

Senior Member
That is super fast. I set frames/ sec to 100, still runs.
If I tick 'no timer' I get 'Not Responding', higher processor load and sluggish response to input like the tickbox etc.
Use this option only with out to file.
To stop it, keep clicking to the "no timer" button.
It will take 500 loops to react. You can down this to 50.
Code:
                If I > 50 Then
                    System.Windows.Forms.Application.DoEvents()
                    I = 0
                End If
If this line:
For Y = 0 To screenshot.Size.Height / 2 - 1

was changed to just

For Y = 0 To screenshot.Size.Height-1

would it still work as well?.
OUPS : was a test, but forget to remove it... You are quasi-true !
But there are screenshot.Size.Height pixels starting from zero to screenshot.Size.Height -1
It will work better !
Unfortunataely I can't test these so far, as I just can't find a 'Run' button on VS... duh! Where is it? Assuming one exists... I googled this, the first 5 results didnt work for me.
Demarrer.jpg
This is a French VS, but symbol is same.
You can also use F5 key.
You can also run ...\Violin\Violin\bin\Debug\violin.exe
Did my last post on here make any sense?
YES, but IMHO it's better to send only one byte, and use EEPROM on the Picaxe to get 12 bits of data.
 
Last edited:

moorea21

Senior Member
I'm trying to test the VS 'solution' (rather than the exe) with an 08m2 using C.4 as serin.

As far as I can tell, I've correctly wired the new serial port (with same type of jackplug as used to program a picaxe,) and I think I understand how the VS code to send serial data works (line 100 etc, from 'B(0) = N'), but nothing is appearing on my LCD screen when this is loaded onto the picaxe:-

Code:
'Put value of 'N' onto LCD, from VS Violin, via AXE027 on COM3
'Serin is C.4, pin 3 on chip
'Serout for LCD is C.1, pin 6 on chip
'No serout pin wired for jackplug yet
#picaxe 08m2

init:
	pause 300
	serout C.1,N2400,(254,1)
	pause 50
	serout C.1,N2400, (254,128)	'put on start of 1st line
	'serout C.1,N2400, ("testing")
	pause 50
	
main:
	serin C.4,N2400,b1
	serout C.1,N2400, (254,128)
	serout C.1,N2400, (#b1)
	pause 4
	goto main

Baud rate of VS program and picaxe both set to 2400, frames/s at 20, 'Out on serial' is ticked, both VS and picaxe IDE set to COM3, LCD works fine, jumper for 08m2 set to 'OUT'.

I was hoping this (below) could be used as simplest test of whether my serial port is able to receive data:-

Code:
Sub testSerial(ByVal test As String)
    test = "TEST"
    Using com3 As IO.Ports.SerialPort = 
            My.Computer.Ports.OpenSerialPort("COM3")
            com3.WriteLine(test)
    End Using
End Sub
but creating a 'project' out of this code is not like in VB6 (no surprise.) Would that be something you could put together quite easily and send? If its no trouble.
 

hippy

Technical Support
Staff member
It's always best to start as simple as possible. In this case a PC program which just sends an "X" or other character, have the PICAXE set a LED which indicates what was expected has been received. Then move up to other characters, multiple characters if required, then variable data.
 

moorea21

Senior Member
All working now! I had to tick 'Out on Screen' as well as 'Out on Serial', as the code for writing to the port is under 'If chkScreen.Checked' not 'If chkSerial.Checked'.

There was a slight glitch with my picaxe software; when N <10 (ie in single figures) the value of N on the lcd screen seemed to be 10*N (ie N =9 but lcd says 90.) But it turned out that the '0' was just left over from when b1 had equalled 10.

Next step will be to take 'N' and end up with max7219 address/data and actually light some leds, then work out how to send serial to another picaxe which can have its clock frequency changed for making different notes on pwm; can't do that on the same picaxe that receives serial input, as the baud rate will go out the window.

And then the minor matter of building the 'instrument' itself...
 

BESQUEUT

Senior Member
All working now! I had to tick 'Out on Screen' as well as 'Out on Serial', as the code for writing to the port is under 'If chkScreen.Checked' not 'If chkSerial.Checked'..
OUPS : bad copy/paste...
It is preferable to correct code and not check out on screen...
Code:
        If chkSerial.Checked Then
            With SerialPort1
                B(0) = N
                If .IsOpen Then .Write(B, 0, 1)
            End With
        End If

        If chkScreen.Checked Then
            Me.Text = "Y=" & Y & " N=" & N
        End If
 
Last edited:

BESQUEUT

Senior Member
Violin V4 uploaded

New option to limit data stream : only send data when changed, or at least one time/s
==> will be easier for the Picaxe...
 

moorea21

Senior Member
Thanks! Anything that helps the picaxe out is a good idea; its going to have to run the 'light the right led' code and the 'make the right note' code simultaneously, so eveery bit helps.
 
Top