Re: Converting voltage level into graphical display
Can you even get the voltage level to begin with? Once you can do that, then you can take the proper steps to retrieving it to a text based display, and finally to a Graphical Display.
Re: Converting voltage level into graphical display
Hi Catherine, Here's a simple dial voltmeter in a picture box. It draws the dial with Graphics.DrawPie and rotates the needle using Graphics.Transform and a graphics matrix (Matrix.RotateAt). Alternatively, you could use Math.Cos etc. to calculate the tip position of the needle. To indicate a voltage, set the volts variable and Refresh the picture box. If you study how it's done you may be able to work out how to add scale markings if required.
vb.net Code:
Private volts As Single
Private maximumVolts As Single = 1.0F
Private dialAngle As Single = 100.0F 'the angular width of the dial
Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
Re: Converting voltage level into graphical display
Hello everyone, thanks for all your help and the time to response to my questions. I'll take note of the references and the codes you guys suggest and i'll try it out today =)
Re: Converting voltage level into graphical display
Hello. I was wondering if will it be possible to do the following :
1) When a specific voltage is sense and is displayed on the textbox, is there any codes to allow the audio announcement of the voltage ?
(a) As voltage levels will usually be in decimal, like for example, (1.23 V) ,
it may be difficult to allow the audio announcement of exact voltages
like 1.23V?
(b) Do i have to do a pre-recording of the audios ? So that when a specific voltage is sense and displayed on the voltage level textbox, the program will call out the audio and play it out ?
If any of the above explanation is unclear, do inform me. =)
Anyways, Thanks in advance to everyone for your time in reading / responding / guidance on this.
[ fyi, i'll also be posting this enquiries on a new thread too ]
Re: Converting voltage level into graphical display
Hi Catherine, did you get my simple voltmeter working, or choose one of the other solutions? It would be nice to let everyone know and if so mark this thread resolved (see Thread Tools in the light blue bar just above the first message).
Your new questions are really a different topic, so you are right to post them in a new thread. But a speaking volt meter would be nice.
Re: Converting voltage level into graphical display
To : Boops Boops,
I tried your codings, it works on my laptop at home, with the diagram and needle.
Apologies if i didnt specify properly in the first place, but the actual circuit board and program is inside my school's computer, and i need the power supply to power up/connect the board, which i can only test out on Monday =)
There are/may still be some enquiries along the way which i still need your (everyones) guidance on the dial voltmeter, therefore i've yet to mark this thread as 'resolved'.
Hope you understand what i meant. =)
Once again, thanks for your help as it really helps me understand vb better. No worries, i'll mark this thread as 'resolved' once the voltmeter works =D
Re: Converting voltage level into graphical display
Thank you everyone for your suggestions. =)
With the help of the suggestions, currently, i am able to display the Voltage indication with a needle.
I googled and search for relevant info for few days (maybe i didnt type the correct keyword ? so the search engine is not able to provide me with the relevant info ?)
But i am still unable to :
1) find the coding on how to include scale markings on the voltmeter
2) and, on how to enable the needle to move and point to the actual voltage with reference to the voltage shown on the textbox ?
Re: Converting voltage level into graphical display
Originally Posted by catherine0136
1) find the coding on how to include scale markings on the voltmeter
I guess that would be hard for you to work out and it's not the kind of thing you can just "find". I have an idea for how to do it, but I don't have time now to work it out in detail. I'll post a solution later.
2) and, on how to enable the needle to move and point to the actual voltage with reference to the voltage shown on the textbox ?
How does the voltage get into the text box? Is it an actual voltage you are measuring, or do you type the number yourself?
I tried including the following codes: radians = (radians + 0.01) Mod Math.PI * 2
volts = CSng(Math.Sin(radians)) * maximumVolts
PictureBox2.Refresh()
into the code that BB suggested >>refer to the post [Nov 25th, 2009 07:44 PM by boops boops] , but the needle doesnt move the way i wanted it to be.
That code is just for testing if the needle works as intended. The idea was to add a Timer and a "Test" button to the voltmeter. You click the button to start and stop the timer. When the timer is running, the needle should swing from side to side. Did you get that far? Or do you need more explanation?
Re: Converting voltage level into graphical display
Hi Catherine,
The problems that you point out, scale markings and correct deflection calculations, are why I suggested the http://www.virtualroadside.com/downl...uments-1.0.zip download. I believe this will do all that you want. These "extras" can get a little messy.
Dick
Richard Grier, Consultant, Hard & Software
Microsoft MVP (Visual Basic)
Re: Converting voltage level into graphical display
@Catherine,
here's some code to add scale markings. Insert it in the Paint sub before the code to draw the needle, and delete the present "Dim pivot" line. You may need to adjust some of the numbers shown below in bold depending on your system font, to make sure the numerals line up nicely.
Code:
'Draw the dial graduations and numbering
Dim font As New Font(Me.Font.FontFamily, 7, FontStyle.Regular)
Dim pivot As New Point(PictureBox1.Width \ 2, PictureBox1.Height \ 2 + 2 * verticalMargin - 10)
Dim innerPoint1 As New Point(PictureBox1.Width \ 2, verticalMargin + 25)
Dim innerPoint2 As New Point(PictureBox1.Width \ 2, verticalMargin + 20)
Dim outerPoint As New Point(PictureBox1.Width \ 2, verticalMargin + 5)
For mark As Integer = -50 To 50
Dim markAngle As Single = dialAngle * mark / 100
Using mtx As New Drawing2D.Matrix
mtx.RotateAt(markAngle, pivot)
e.Graphics.Transform = mtx
End Using
If mark Mod 10 = 0 Then
'draw long line
e.Graphics.DrawLine(Pens.Gray, innerPoint1, outerPoint)
'draw numeral
e.Graphics.DrawString(mark / 10.ToString, font, _
Brushes.Black, innerPoint1.X - 5, innerPoint1.Y + 1)
Else
'draw short line
e.Graphics.DrawLine(Pens.Gray, innerPoint2, outerPoint)
End If
e.Graphics.ResetTransform()
Next
'Add label text
font = New Font(Me.Font.FontFamily, 10, FontStyle.Regular)
e.Graphics.DrawString("Volts", font, _
Brushes.Black, innerPoint2.X - 23, innerPoint2.Y + 35)
font.Dispose()
@Dick, I don't think Catherine will benefit much from downloading a ready-made analog ammeter in Csharp for a school project for a voltmeter in VB.Net. It looks very nice, but its functionality is limited to a trackbar to move the needle; I doubt if anyone here is going help with that. Besides, the code is 500+ lines, compared to about 130 for the functioning apparatus shown below).
Re: Converting voltage level into graphical display
To BB and DickGrier,
I apologise if i did not specify clearly in the first place regarding what are the requirements that i need for the voltmeter, which may have cause a little misunderstanding here =)
@DickGrier,
I went to the website you suggested, it was a good website which makes me understand how to control the needle using the trackbar and how it works. Its in C# though, so i tried converting to VB.net Code, but.. the codes couldnt work. (Maybe i have to edit some code first before it'll works ? )
@BB,
I decided to use your suggestions because what you suggested is more direct (as in its in VB.net).
But I sincerely thank you all for your suggestions. No worries, all suggestions from everyone have been looked through and tried out.
Re: Converting voltage level into graphical display
Oh, i forgotten to add in one thing. ^-^
To: BB
Regarding on how does the voltage get into the text box?
Basically, my circuit board is connected to a power supply(those laboratory DC power supply used in schools) and is connected to the computer via a RS232 cable. =)
Re: Converting voltage level into graphical display
Hi,
You may be right, though instead of the trackbar can be replaced by active reads, with a single line of code. Not much cost. The Oscilloscope function can simply be deleted. Converting the code to VB might not be worth the effort.
Your code and results look quite good. I'm sure that Catherine can use it.
Dick
Dick
Richard Grier, Consultant, Hard & Software
Microsoft MVP (Visual Basic)
Re: Converting voltage level into graphical display
Originally Posted by catherine0136
Oh, i forgotten to add in one thing. ^-^
Regarding on how does the voltage get into the text box?
Basically, my circuit board is connected to a power supply(those laboratory DC power supply used in schools) and is connected to the computer via a RS232 cable. =)
And I thought you already had that side of it sorted out! All I know is that there are special programs for reading data from RS232 ports, including some you can download for free. But I have no idea how good they are and how easy it is to interface them with VB.Net.
Maybe you should start another thread about "getting VB.Net data from RS232". There may be someone on this forum who can advise you, but is not following this thread about the graphics.
Re: Converting voltage level into graphical display
Ok. Thank you for your suggestion and also for your time =)
I've got this last question to ask.
>> Assuming the voltage level is key into the textbox manually, like the example you shown me, how do i actually get the needle to point to the voltage according to what is key into the box ? Maybe i'll be able to work out a way from there?
[i understand that this should be quite a easy one, but i dont seem to be able to get the code right ]
Re: Converting voltage level into graphical display
You could use the code I already gave you in the Audio thread, because that also sets the needle. Of course you may want to leave out the synthesizer and voice bits if you don't want Yosemite Sam nagging at you all the time. Alternatively you could leave them in and get rid of the Speak button altogether. But one question remains: when do you change the volts value?
If you double-click on a TextBox in the Designer, you get the outline code for its default event: TextChanged. But that won't do, since it would fire off for every character you type. A better way would be to wait until you press the Enter key. For that, you need the text box's KeyDown event (which you can get from the drop-down lists at the top of the code view page, in case you didn't know). This should work:
Code:
Private Sub TextBox1_KeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyValue = Keys.Enter Then
'copy the code from the Speak button in here.
End If
End Sub
One more tip. If you choose to leave the speech in, change voice.Speak to voice.SpeakAsync. That way the needle will move immediately instead of waiting for Sam or Anna to finish speaking.
Re: Converting voltage level into graphical display
Catherine,
You would use the SerialPort control in the Toolbox. You need to use the description of the data format that the board manufacturer provides to know how to convert the data into numbers that can be used to display. You may want to create another thread on this subject. If you do, make sure that you include more information on what this board is (manufacturer and model), and a description of the data format. I've done this many times, with many different types of boards or systems. The actual code varies greatly -- there isn't anything like a standard protocol for such data.
I do have lots of examples for this in my book, but it may be too late in the session for you to benefit from that source.
Dick
Richard Grier, Consultant, Hard & Software
Microsoft MVP (Visual Basic)
Re: [RESOLVED] Converting voltage level into graphical display
Hello.
I've got another problem i encounter which i need help on.
As stated in another post, my circuit board is connected to the solar panel and also voltage supply (those used in school labs), and the whole thing is connected to the computer via a RS-232 cable. I actually plan to plot the voltage level extracted from my circuit into Oscilloscope waveform, but after considering everyone's suggestions for a week plus, i believe that by plotting a straight line will be a better choice.
My project requirements needs me to display the voltage level into 2 types of graphical display and with the help of people from the forum, i was able to display one type which is the Voltage Needle Indication.
See the attached image and to the right of the image is "Graphical Display", which i've plotted the ruler markings(representing Voltage Level) and also with a red line, which i wish to allow the straight red line to blink and jump according to the voltage level shown on "Voltage Level in Volts(V) ".
I tried adding Me.Refresh() or PictureBox2.Refresh() to allow the red line to jump according to the voltage level, but i believe this isnt the correct method.
[[ PictureBox2 --> is the graphical display box ]]
>> Therefore, i hope someone can help me to correct my mistakes and also provide me guidance on how to allow the red line to jump and display according to the voltage level shown in the textbox.
>> I'm not sure if this graphical display i've mention make sense though, hope to receive suggestions or comments on this too.
Shown below are the code to display the ruler markings for reference. If any other code are required for your reference, please inform me. =)
Thanks in advance and wishing everyone an advance Merry X'mas !
Code:
Private Sub PictureBox2_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox2.Paint
Dim g As Graphics = e.Graphics
Dim vertFont As New Font("Verdana", 10, FontStyle.Bold)
Dim horzFont As New Font("Verdana", 10, FontStyle.Bold)
Dim vertBrush As New SolidBrush(Color.Blue)
Dim horzBrush As New SolidBrush(Color.Blue)
Dim horzBrush1 As New SolidBrush(Color.Red)
Dim bluePen As New Pen(Color.Blue)
Dim redPen As New Pen(Color.Red, 2)
' Drawing a vertical and a horizontal line
g.DrawLine(bluePen, 50, 220, 50, 15) 'vertical line
g.DrawLine(bluePen, 50, 220, 260, 220) 'horizontal line
g.DrawLine(redPen, 50, 200, 260, 200) 'horizontal line
'Draw vertical strings
Dim vertStrFormat As New StringFormat()
vertStrFormat.FormatFlags = StringFormatFlags.DirectionVertical
g.DrawString("-", horzFont, horzBrush, 49, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 59, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 69, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 79, 212, vertStrFormat)
g.DrawString("--", horzFont, horzBrush, 89, 205, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 99, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 109, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 119, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 129, 212, vertStrFormat)
g.DrawString("--", horzFont, horzBrush, 139, 205, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 149, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 159, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 169, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 179, 212, vertStrFormat)
g.DrawString("--", horzFont, horzBrush, 189, 205, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 199, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 209, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 219, 212, vertStrFormat)
g.DrawString("-", horzFont, horzBrush, 229, 212, vertStrFormat)
g.DrawString("--", horzFont, horzBrush, 239, 205, vertStrFormat)
' y-axis drawing
g.DrawString(" 4 --", vertFont, vertBrush, 25, 12)
g.DrawString(" -", vertFont, vertBrush, 25, 22)
g.DrawString(" -", vertFont, vertBrush, 25, 32)
g.DrawString(" -", vertFont, vertBrush, 25, 42)
g.DrawString(" -", vertFont, vertBrush, 25, 52)
g.DrawString(" 3 --", vertFont, vertBrush, 25, 62)
g.DrawString(" -", vertFont, vertBrush, 25, 72)
g.DrawString(" -", vertFont, vertBrush, 25, 82)
g.DrawString(" -", vertFont, vertBrush, 25, 92)
g.DrawString(" -", vertFont, vertBrush, 25, 102)
g.DrawString(" 2 --", vertFont, vertBrush, 25, 112)
g.DrawString(" -", vertFont, vertBrush, 25, 122)
g.DrawString(" -", vertFont, vertBrush, 25, 132)
g.DrawString(" -", vertFont, vertBrush, 25, 142)
g.DrawString(" -", vertFont, vertBrush, 25, 152)
g.DrawString(" 1 --", vertFont, vertBrush, 25, 162)
g.DrawString(" -", vertFont, vertBrush, 25, 172)
g.DrawString(" -", vertFont, vertBrush, 25, 182)
g.DrawString(" -", vertFont, vertBrush, 25, 192)
g.DrawString(" -", vertFont, vertBrush, 25, 202)
' Dispose of objects
vertFont.Dispose()
horzFont.Dispose()
vertBrush.Dispose()
horzBrush.Dispose()
bluePen.Dispose()
redPen.Dispose()
End Sub
Re: [RESOLVED] Converting voltage level into graphical display
As to the speech, here's a really primitive way of getting some speech support.
Code:
Imports System.Speech.Synthesis
Private Sub Speech(Byval text as String)
Dim Phrase As New Prompt(text)
Dim Phrase2 As New Prompt("More speech text.")
Dim Synth As New SpeechSynthesizer
Synth.Rate = 3
Synth.SpeakAsync(Phrase)
Synth.SpeakAsync(Phrase2)
End Sub
Re: [RESOLVED] Converting voltage level into graphical display
Hi Catherine,
You've managed to get a nice looking layout. The only line that matters for present purposes is this one:
Code:
g.DrawLine(redPen, 50, 200, 260, 200) 'horizontal line
Not surprisingly, it doesn't respond to your voltage value because it draws a line from (x=50, y=200) to (x=260, y=200). The y value (200) gives the height of the line measured in pixels, down from the top of the window. So those fixed Y values will have to change to represent the voltage.
Are you using the variable volts to represent the voltage in your program, as I suggested? From your code, it looks like you are drawing the x-axis at height y =212 and you are drawing the Y axis with 1 volt = 50 pixels. If that's right, then all you need is:
vb.net Code:
Dim voltsY As Integer = 212 - CInt(volts * 50)
g.DrawLine(redPen, 50, voltsY, 260, voltsY)
By the way, it would make sense to draw your X axis half way up, so that you can see negative volts if necessary. To do that, you would have to change the numbers you use for Y values in the DrawString statements to 106 or so, and change the Y scaling to something like 1 volt = 25 pixels. It will take a little work to get that looking tidy, so see if you can get the positive volts working first.
Re: [RESOLVED] Converting voltage level into graphical display
I need to actually do something to improve the varying movement of the :
1) Voltage Needle
2) Graphical Display Line
As in, when the whole circuit is powered up, theres a huge varying movement with the Voltage Needle and the Graphical Display Line, and i'm supposed to average it, so that the varying movement wont be that obvious. But i'm stuck on that.
To BB,
If i'm not wrong, my above mention is almost related to one of the solution that you provided in one of the thread i posted ..
>> http://www.vbforums.com/showthread.php?t=593714
But that method didnt work. Hmm..
I tried editing here and there, but i believe again, my method isnt the right way. Haha. So gonna need everyone's help again.
And am i correct to say, the main thing in order to solve this is by averaging the voltage level shown in "Voltage Level in Volts" ?
Re: [RESOLVED] Converting voltage level into graphical display
The code I gave you in posts #8 and #10 of that thread ought to work for calculating the average. The idea is:
1. declare Dim avg As Single and Dim voltsQ As New Queue on your form (not in a sub).
2. add a Timer to your form, and put the code to average the queued readings (from post #10 in the other thread) in its Tick sub.
3. use avg instead of volts in the Paint sub to control the position of the needle or the line - for example in the line with Dim voltsY in my last post above.
If there's any part of that's not clear, please say so.
Re: [RESOLVED] Converting voltage level into graphical display
>> To BB,
Thanks for your help =)
>> To Everyone,
Btw, i would also like to display the word " Volts(V) " in the Y axis, just like the one you see from the attached image.
But that image is crop from elsewhere and placed into a picturebox, which to me, doesnt look nice. I would prefer if the words are type in manually into a label and then rotate.
I did some research through the forums and websites, and came across this:
> http://www.vbforums.com/showthread.p...ight=Axis+Text
from there, i have a brief idea on it , tried out but it didnt work though. Or i may not have done it correctly.
So I hope to receive some guidance on that too. Thanks in advance.
Re: [RESOLVED] Converting voltage level into graphical display
Hello.
I need guidance on how to allow the waveform to move according to the voltage shown on a textbox.
(My circuit board is connected to a power supply and solar cell, and the whole thing is connected to the computer via a RS232 cable, from there, a voltage level is extracted and shown on the GUI)
People have suggested me to draw a straight line to represent the voltage, but after showing it to the school supervisors, they want me to try using waveform to move accordingly to the voltage level shown on a textbox. I'm kinda stuck on that. I would appreciate any suggestions regarding this. Thanks in advance ! =)
Re: [RESOLVED] Converting voltage level into graphical display
Hi Catherine, Happy New Year!
At the moment your code just draws a fixed line, with fixed numbers. You were supposed to change that into a line that shows a "voltage" value you enter in a textbox. I hope you understand enough by now to at least make an attempt.
By the way, are you now getting any real voltage data from a solar cell or not? If you are, you would have a changing voltage value you can use in your program. Probably it will be a clocked signal. That means the voltage reading will change at fixed intervals -- at a guess, something like 10 or 100 or 1000 times a second. Probably that depends on the interface settings.
If you don't have that kind of data yet, than you need to simulate it. Typing a number in a textbox is just a first step. You could go on from there to prepare a long list of made-up numbers to represent the voltage changing over a period, say a couple of seconds. But I showed you another way to simulate changing data in post #10 of this thread. I suggested using a sine wave to "test" the voltmeter, by waving the needle from side to side. It wouldn't be too difficult to change that into drawing a moving wavy line, like a simple oscilloscope. The whole idea is to make something that you could use to display real changing data, isn't it?
Re: [RESOLVED] Converting voltage level into graphical display
Hi BB,
Happy New Year to you too =)
Well, to make things clear, and to prevent any misunderstandings, usually i will do my research and try out before seeking guidance from forums. I dont look for straight forward answers, just a word or two of hints, a head start and i'm definately very grateful for that.
Even the thread you posted (Yesterday 06:02 PM) gives me a head start.
Yes, i am getting a real voltage.
Re: [RESOLVED] Converting voltage level into graphical display
@TokersBall_CDXX
i believe its DC ? Because the solar cell is connected to a Analog-to-Digital board then this whole thing is connected to the power supply and its also connected to the comp via a RS-232 cable.
And i've heard that drawing a straight line for my project is much better and more sensible, but during my presentation of the project to the supervisors, they want me to do into waveform.
@BB,
I would appreciate if you could give me a small hint on how to allow the waveform to move according to the voltage level.
I tried a few ways and also edited the coding you suggested to test the moving needle, i understand the concept, but i still couldnt get the code right.
Please do not misunderstand that i'm asking for direct answers, i just need some guidance. Thanks in advance.