Go Down

Topic: Vb.Net DataReceived event doesn´t fire up on leonardo (Read 3412 times) previous topic - next topic


Sep 28, 2012, 02:28 am Last Edit: Sep 28, 2012, 02:31 am by ntiagobr Reason: 1
Hello everyone, recently bought an Arduino Leonardo, however I am not able to receive data on VB.net side, I can send data to Arduino but can´t receive, DataReceived event doesn´t fire on VB.NET, can someone help me, already googled and I can´t see no reason why event DataReceived isn´t working.

Here´s my Vb code :

Code: [Select]
Public Class Form1

   Public WithEvents SerialP As System.IO.Ports.SerialPort

   Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


           SerialP = New System.IO.Ports.SerialPort
           SerialP.BaudRate = 9600
           SerialP.PortName = "COM15"
           SerialP.DataBits = 8
           SerialP.ReadTimeout = 5000
           SerialP.WriteTimeout = 5000
           SerialP.Parity = IO.Ports.Parity.None
           SerialP.StopBits = IO.Ports.StopBits.One
           SerialP.Handshake = IO.Ports.Handshake.None
           'SerialP.Encoding = System.Text.Encoding.Default 'very important!
           SerialP.Encoding = System.Text.Encoding.UTF8

       Catch ex As Exception
       End Try

   End Sub

   Public Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialP.DataReceived
   End Sub

   Sub GetSerialPortNames()
       ' Show all available COM ports.
       For Each sp As String In My.Computer.Ports.SerialPortNames
   End Sub

   Private Sub SendToSerialP()
       If SerialP.IsOpen Then

       End If
   End Sub

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   End Sub

   Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed

   End Sub
End Class

And here is my Sketch :

Code: [Select]
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte;      // a variable to read incoming serial data into
int counter;

void setup() {
 // initialize serial communication:
 while (!Serial) {
   ; // wait for serial port to connect. Needed for Leonardo only
 // initialize the LED pin as an output:
 pinMode(ledPin, OUTPUT);
 counter = 0;

void loop() {


void establishContact() {
 while (Serial.available() <= 0) {
   Serial.print('A');   // send a capital A


Problem solved  8), after some digging, i figured out the issue, properties SerialP.DtrEnable and SerialP.RtsEnable must both be set to True.

Thank you all anyway.

I will leave the this post, who knows, it can be useful to someone else.



Just wanted to say thanks for posting up the solution you found, I'd been trying everything I could think of to trick the Leonardo into thinking that the connection was active, but had completely overlooked the handshaking!  :smiley-red:

Works a treat, thanks again!



:D Great! ;)

I'm glad it helped, I regret there is so little help about this issue.



Bumping this topic as it just saved my skin. Wasted a whole day trying to figure out why a sketch and app that worked with the Uno didn't work with Leonardo - eventually google threw up this after many dead ends.

Thank you so much. How annoying that it is different.


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131