Results 1 to 40 of 68

Thread: [RESOLVED] Converting voltage level into graphical display

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Thanks for helping ! =)

    Am i right to place the VoltsQ.Count>2 as follows, please correct me if i'm wrong.

    Code:
    If VoltsQ.Count > 2
    
     'Put your code for drawing the axes etc. here.
    
    
                'Details of the graph layout -- fill in your own values here!
                Dim Origin As New Point(50, 119)
                Dim xAxisLength As Integer = 210
                Dim yAxisLength As Integer = -120
    
                'Turn the queue into an array:
                Dim voltsQarray As Single() = voltsQ.ToArray
    
                'Define an array of data points:
                Dim DataPoints(voltsQ.Count - 1) As Point
                Dim x, y As Integer
    
                'Fill in the array using the voltage readings:
                For i As Integer = 0 To voltsQ.Count - 1
                    'Get the volts value from the queue:
                    Dim v As Single = voltsQarray(i)
                    'Find the distance along the x axis:
                    x = Origin.X + CInt(i * xAxisLength / 40)
                    'find the height of the data point on the Y axis:
    
                    y = Origin.Y + CInt(v * yAxisLength / maxVolts)
                    'Put the point in the array
                    DataPoints(i) = New Point(x, y)
    
                Next
                'Draw the waveform:        
                e.Graphics.DrawCurve(Pens.Green, DataPoints)
    
            End If

    Btw, after placing all the code into the program, this is what i observe [ please see attached image ] Hmm.. its still a straight line though but it is varying quantity against time. So i believe its correct ?
    Attached Images Attached Images  

  2. #2
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display

    Quote Originally Posted by catherine0136 View Post
    Thanks for helping ! =)
    Am i right to place the VoltsQ.Count>2 as follows, please correct me if i'm wrong.
    That should work, but it would be neatest to put it after drawing the axes. That way they will still show when there is no signal. It must come before you define voltsQarray.

    Btw, after placing all the code into the program, this is what i observe [ please see attached image ] Hmm.. its still a straight line though but it is varying quantity against time. So i believe its correct ?
    It's not what I would expect if everything is working properly. There might be something wrong in the code, but you should try to eliminate other possibilities. What happens when you change the light on the solar cell? What happens to the line when you disconnect the solar cell or the RS232 interface? And what happens when you type a different value in the textbox?

    BB

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Code:
    It's not what I would expect if everything is working properly. There might be something wrong in the code, but you should try to eliminate other possibilities. What happens when you change the light on the solar cell? What happens to the line when you disconnect the solar cell or the RS232 interface? And what happens when you type a different value in the textbox?

    Originally, it shows a straight line because it is taking the voltage from the "Average Voltage" textbox.

    I edited so that i'll let the waveform follow the voltage from the "Voltage Level in Volts(V)" textbox, in which the voltages displayed in "Voltage Level in volts varies greatly from 2.30V to slightly above 3.0V, and the waveform will be like this (see attached image - Solar Cell).

    When my hand is place over the solar cell, i am able to observe that the voltage level will decrease and the waveform will also move lower. (See attached image - Solar Cell 1)

    Is it whole waveform correct?

    I'll attached the coding which i insert into my program in the next thread.
    Attached Images Attached Images   

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    Following is the code of PictureBox2, to display the waveform.

    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.Blue)
    
            Dim BluePen As New Pen(Color.Blue)
    
            ' Drawing a vertical and a horizontal line 
            g.DrawLine(BluePen, 50, 225, 50, 15)   'vertical line
            g.DrawLine(BluePen, 50, 120, 260, 120)  'horizontal line
    
    
            'Details of the graph layout 
            Dim Origin As New Point(50, 119)
            Dim xAxisLength As Integer = 210
            Dim yAxisLength As Integer = -120
    
            If voltsQ.Count > 2 Then
    
                'Turn the queue into an array:
                Dim voltsQarray As Single() = voltsQ.ToArray
    
                'Define an array of data points:
                Dim DataPoints(voltsQ.Count - 1) As Point
                Dim x, y As Integer
    
                'Fill in the array using the voltage readings:
                For i As Integer = 0 To voltsQ.Count - 1
                    'Get the volts value from the queue:
                    Dim v As Single = voltsQarray(i)
                    'Find the distance along the x axis:
                    x = Origin.X + CInt(i * xAxisLength / 40)
                    'find the height of the data point on the Y axis:
    
                    y = Origin.Y + CInt(v * yAxisLength / maxVolts)
                    'Put the point in the array
                    DataPoints(i) = New Point(x, y)
    
                Next
                'Draw the waveform:        
                e.Graphics.DrawCurve(Pens.Green, DataPoints)
    
            End If
    
    
            'Draw vertical strings 
            Dim vertStrFormat As New StringFormat()
            vertStrFormat.FormatFlags = StringFormatFlags.DirectionVertical
            g.DrawString("-", horzFont, horzBrush, 49, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 49, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 59, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 69, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 79, 113, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 89, 106, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 99, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 109, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 119, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 129, 113, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 139, 106, vertStrFormat)
    
            g.DrawString("-", horzFont, horzBrush, 149, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 159, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 169, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 179, 113, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 189, 106, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 199, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 209, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 219, 113, vertStrFormat)
            g.DrawString("-", horzFont, horzBrush, 229, 113, vertStrFormat)
            g.DrawString("--", horzFont, horzBrush, 239, 106, vertStrFormat)
    
    
            ' y-axis drawing 
    
            g.DrawString("  4 --", vertFont, vertBrush, 25, 12)
            g.DrawString("    --", vertFont, vertBrush, 25, 12)
            g.DrawString("     -", vertFont, vertBrush, 25, 17)
            g.DrawString("     -", vertFont, vertBrush, 25, 22)
            g.DrawString("     -", vertFont, vertBrush, 25, 27)
            g.DrawString("     -", vertFont, vertBrush, 25, 32)
    
            g.DrawString("  3 --", vertFont, vertBrush, 25, 37)
            g.DrawString("    --", vertFont, vertBrush, 25, 37)
            g.DrawString("     -", vertFont, vertBrush, 25, 42)
            g.DrawString("     -", vertFont, vertBrush, 25, 47)
            g.DrawString("     -", vertFont, vertBrush, 25, 52)
            g.DrawString("     -", vertFont, vertBrush, 25, 57)
    
            g.DrawString("  2 --", vertFont, vertBrush, 25, 62)
            g.DrawString("    --", vertFont, vertBrush, 25, 62)
            g.DrawString("     -", vertFont, vertBrush, 25, 67)
            g.DrawString("     -", vertFont, vertBrush, 25, 72)
            g.DrawString("     -", vertFont, vertBrush, 25, 77)
            g.DrawString("     -", vertFont, vertBrush, 25, 82)
    
            g.DrawString("  1 --", vertFont, vertBrush, 25, 87)
            g.DrawString("    --", vertFont, vertBrush, 25, 87)
            g.DrawString("     -", vertFont, vertBrush, 25, 92)
            g.DrawString("     -", vertFont, vertBrush, 25, 97)
            g.DrawString("     -", vertFont, vertBrush, 25, 102)
            g.DrawString("     -", vertFont, vertBrush, 25, 107)
            g.DrawString("  0", vertFont, vertBrush, 25, 112)
    
            g.DrawString("     -", vertFont, vertBrush, 25, 117)
            g.DrawString("     -", vertFont, vertBrush, 25, 122)
            g.DrawString("     -", vertFont, vertBrush, 25, 127)
            g.DrawString("     -", vertFont, vertBrush, 25, 132)
            g.DrawString("    --", vertFont, vertBrush, 25, 137)
            g.DrawString(" -1--", vertFont, vertBrush, 25, 137)
    
            g.DrawString("     -", vertFont, vertBrush, 25, 142)
            g.DrawString("     -", vertFont, vertBrush, 25, 147)
            g.DrawString("     -", vertFont, vertBrush, 25, 152)
            g.DrawString("     -", vertFont, vertBrush, 25, 157)
            g.DrawString("    --", vertFont, vertBrush, 25, 162)
            g.DrawString(" -2--", vertFont, vertBrush, 25, 162)
    
            g.DrawString("     -", vertFont, vertBrush, 25, 167)
            g.DrawString("     -", vertFont, vertBrush, 25, 172)
            g.DrawString("     -", vertFont, vertBrush, 25, 177)
            g.DrawString("     -", vertFont, vertBrush, 25, 182)
            g.DrawString("    --", vertFont, vertBrush, 25, 187)
            g.DrawString(" -3--", vertFont, vertBrush, 25, 187)
    
            g.DrawString("     -", vertFont, vertBrush, 25, 192)
            g.DrawString("     -", vertFont, vertBrush, 25, 197)
            g.DrawString("     -", vertFont, vertBrush, 25, 202)
            g.DrawString("     -", vertFont, vertBrush, 25, 207)
            g.DrawString("    --", vertFont, vertBrush, 25, 212)
            g.DrawString(" -4--", vertFont, vertBrush, 25, 212)
    
            ' Dispose of objects 
            vertFont.Dispose()
            horzFont.Dispose()
            vertBrush.Dispose()
            horzBrush.Dispose()
            BluePen.Dispose()
    
            'Display text in Y-axis
            Dim Font1 As New Font("Comic Sans MS", 10, FontStyle.Bold)
            g.TranslateTransform(30, 148)
            g.RotateTransform(180)
            g.DrawString("Volts (V)", Font1, _
              Brushes.Blue, 0, 0, New StringFormat(StringFormatFlags.DirectionVertical))
    
        End Sub

    Following is the coding for the timer.
    I included this line, Single.TryParse(TextBoxVoltage.Text, volts1), so that the waveform will move according to the voltage shown in the "Voltage Level in Volts(V)", and not follow the average voltage(which will produce the straight line).

    Code:
     Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
    
            'read the voltage and get value from RS232 interface
            Call OpenPORT1()
    
            Single.TryParse(TextBoxVoltage.Text, volts1)
            'add the new reading to the end of the queue
            voltsQ.Enqueue(volts1)
    
            'remove the old reading at the head of the queue, to keep max. 40 data points    
            If voltsQ.Count > 40 Then voltsQ.Dequeue()
    
            'update the display with the new data     
            Me.Refresh()
    
        End Sub
    As for Call OpenPORT1(),

    Code:
     Private Sub OpenPORT1()
            If SerialPort1.IsOpen Then
                SerialPort1.Close()
            End If
    
            SerialPort1.PortName = "COM1"
            SerialPort1.BaudRate = 9600
            SerialPort1.Parity = System.IO.Ports.Parity.None
            SerialPort1.DataBits = 8
            SerialPort1.StopBits = System.IO.Ports.StopBits.One
    
            SerialPort1.RtsEnable = True
            SerialPort1.Open()
    
        End Sub

    I hope everything is correct.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display

    And as for the following:

    ' Drawing a vertical and a horizontal line
    g.DrawLine(BluePen, 50, 225, 50, 15) 'vertical line
    g.DrawLine(BluePen, 50, 120, 260, 120) 'horizontal line

    Code:
     'Details of the graph layout 
            Dim Origin As New Point(50, 119)
            Dim xAxisLength As Integer = 210
            Dim yAxisLength As Integer = -120
    I replaced it with a negative value. If i were to follow yours to put a positive value, the waveform will be at the negative side. I hope everything is correct. =)

  6. #6
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: [RESOLVED] Converting voltage level into graphical display


  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    77

    Re: [RESOLVED] Converting voltage level into graphical display


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width