hey! i'm trying to display the pitch, roll and yaw readings from arduino using visual basic. does anyone have the code for serial communication between arduino and visual basic?
Here's a bit of test code I used to get my Melexis IR temperature sensor working. Eventually, it will evolve into a full program to report cloud cover on my weather station.
Option Strict On
Public Class Form1
Dim temperatures As String = ""
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
SP.Write("t")
End Sub
Private Sub SP_DataReceived(sender As Object, e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SP.DataReceived
Dim dataIn As String = ""
Dim numbytes As Integer = SP.BytesToRead
For i As Integer = 1 To numbytes
dataIn &= Chr(SP.ReadChar)
Next
UpdateTextBox(dataIn)
End Sub
Private Sub UpdateTextBox(ByVal text As String)
If TextBox1.InvokeRequired Then 'If we are on the wrong thread....
TextBox1.Invoke(Sub() UpdateTextBox(text)) 'marshal update back onto the UI thread that TextBox1 was created on, i.e. call the method again, but this time on the correct thread.
Else
TextBox1.Text += text
End If
End Sub
Private Sub handledataIn(ByVal di As String)
temperatures = di
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
SP.Open()
If Not SP.IsOpen Then
MessageBox.Show("Unable to open COM2")
Me.Close()
End If
Debug.Print(CurDir)
End Sub
End Class
For this example, make a new project and place a SerialPort, a Button, and a Multiline TextBox on the form. Change the name of the SerialPort to SP.
I have my arduino code set up to report the temperatures when I send it a "t". If your progarm loops and keeps sending roll, pitch and yaw in, you won't need the button,'
Hope you have a lot of RAM to be using C++ Strings instead of C string arrays.
Hint: what works okay on a PC with tons of RAM may just bite you on an UNO with 2k RAM.
That's quite an assumption, considering that he did not post his Arduino code.
I am not making assumptions about how C++ Strings work and I was looking at your pseudocode anyway.
C++ Strings are a bad idea in a limited RAM environment. People who use them in such environments (like UNO or Leonardo) either have not learned how to use C string arrays or have cognitive problems or want to teach others BAD HABITS. Take your pick.
C++ Strings waste RAM. C++ Strings use dynamic allocation. C++ Strings copy themselves to "grow" and then leave a hole in your heap. Did I mention that UNO has only 2k RAM? Gee, I hope your code isn't time critical because C++ Strings aren't.
Figure out the implications before you come back with a snappy answer like yes, you can get away with using Strings in such-and-so cases which by itself should be a Clue. We have one String-defender here, there has to be at least one in the village so why not more?
Anyone who wants to write non-trivial code for and explore Arduino is better served learning and using C string arrays and just asking for trouble by using C++ Strings. That's not the only "don't" but it's a big one. I have a MEGA2560 with 512k bank switched RAM and still I wouldn't use Strings on it for less than Real Money.
But then what do I know?
I am not making assumptions about how C++ Strings work and I was looking at your pseudocode anyway.
What pseudo code? That was the VB (as in Visual Basic) code that DOES execute on the PC.
I managed to dodge VB by working in C++. I spent 10+ years on and off writing BASIC and I want them back!
I spent 10+ years on and off writing BASIC and I want them back!
I spent 10+ minutes on and off writing BASIC and I want them back!
VB and goto are in the same category IMHO.
GoForSmoke:
I am not making assumptions about how C++ Strings work and I was looking at your pseudocode anyway.
...
But then what do I know?
I think that sums it up pretty well.
I do not defend C++ Strings. Up until your post, there was no mention of them. A member asked a perfectly valid question, and I gave him a valid answer. When someone actually uses or inquires about C++ Strings, your opinion of them becomes relevant.
lar3ry, I gave the information my "opinion" is based on.
Those are facts.
The opinion is that anyone who knows the facts and uses C++ Strings in a small environment is not much of a programmer due to lack of logic ability.
If you do a search here you may find that a lot of other members with years of experience coding share my view.
Using C++ Strings on Arduino just because they work on a PC is like putting a bathtub on a bicycle just because you have one in your house. You can do it but it's daft.
GoForSmoke:
lar3ry, I gave the information my "opinion" is based on.
Those are facts.
Yes, and they were completely irrelevant to the thread.
The opinion is that anyone who knows the facts and uses C++ Strings in a small environment is not much of a programmer due to lack of logic ability.
If you do a search here you may find that a lot of other members with years of experience coding share my view.
Using C++ Strings on Arduino just because they work on a PC is like putting a bathtub on a bicycle just because you have one in your house. You can do it but it's daft.
You'll get no argument from me on that. Are you under the impression that I advocate the usage of C++ Strings? If so, you can get rid of that impression right now. I have been programming AVRs for for about 15 years, though mostly in assembly, and I am well aware of both the scarcity of memory and the inavdvisability of using memory-hungry C++ code.
As for the rest of you who don't like VB.Net, well sorry, but I don't do religious discussions, and I will answer any question I know an answer to, regardless of what language has relevance, or if I happen to know how to do it in any language.