Page 3 of 3

Re: Serial Communication - LattePanda Leonardo [SOLVED}

Posted: Thu Sep 07, 2017 9:26 pm
by atestani
Got it!!

The key is Leonardo doesn't execute SerialEvent() (for some reason!). It is supposed to execute between loop() passes as all other Arduinos do (almost all, there are two others like Leonardo... Micro and ETH, I think). In looking back at links to SerialEvent, I can now see that this is "documented" e.g. https://www.arduino.cc/en/Tutorial/SerialEvent but NOT in the links that describe differences between Leonardo and the rest of the Arduinos. like this:
https://www.arduino.cc/en/Guide/Arduino ... icro#toc11

To get this working, I just added a call to SerialEvent() as the first line in loop() and it now works with the Serial Monitor and my C# code on the LattePanda. Also, Arduino v1.69 doesn't upload to Leonardo correctly, so you need to upgrade to v1.8x.

I marked this thread as "SOLVED".

Re: Serial Communication - LattePanda Leonardo [SOLVED]

Posted: Fri Sep 08, 2017 6:25 am
by Lutz
Wow ! ... and congratulations! :o :D :o :D

Good to hear that you have solved the problem and many, many thanks to you for sharing the solution with us!

Re: Serial Communication - LattePanda Leonardo [SOLVED]

Posted: Fri Sep 08, 2017 8:21 am
by ED209
Hi atestani, why don't you use the standard firmata protocol to build the communication between Arduino and CPU? Just be curious.

Re: Serial Communication - LattePanda Leonardo [SOLVED}

Posted: Fri Sep 08, 2017 8:43 am
by LattePanda
atestani wrote:
Thu Sep 07, 2017 9:26 pm
Got it!!

The key is Leonardo doesn't execute SerialEvent() (for some reason!). It is supposed to execute between loop() passes as all other Arduinos do (almost all, there are two others like Leonardo... Micro and ETH, I think). In looking back at links to SerialEvent, I can now see that this is "documented" e.g. https://www.arduino.cc/en/Tutorial/SerialEvent but NOT in the links that describe differences between Leonardo and the rest of the Arduinos. like this:
https://www.arduino.cc/en/Guide/Arduino ... icro#toc11

To get this working, I just added a call to SerialEvent() as the first line in loop() and it now works with the Serial Monitor and my C# code on the LattePanda. Also, Arduino v1.69 doesn't upload to Leonardo correctly, so you need to upgrade to v1.8x.

I marked this thread as "SOLVED".
Hi atestani,

Sincerely thanks for your sharing, and it is good to know that you got the solution. I will share this thread to other same topic you posted in the forum to help more people get the solution. :)

Re: Serial Communication - LattePanda Leonardo [SOLVED]

Posted: Fri Sep 08, 2017 12:25 pm
by atestani
The reason for not using Firmata is it is a lot of code and overhead for a simple operation, plus there isn't a specific set of methods for sending strings back and forth. Also, it seems to be very slow, overall, at least in my tests.

Re: Serial Communication - LattePanda Leonardo [SOLVED]

Posted: Thu Sep 14, 2017 11:21 am
by ED209
Very cool! What's your next step? I also want to build some applications based on microcontroller and CPU together. Any idea?

Re: Serial Communication - LattePanda Leonardo [SOLVED]

Posted: Thu Sep 14, 2017 2:34 pm
by atestani
For anyone wanting to do this, all of my test code is in the attached file, both Arduino and C# code.

There are two things to note:
- The connecting program (C# test app, in this case) must set DTR on (and maybe RTS... I set it on and never went back to see if it is required).
- The Leonardo will not open the Serial port until a connection is made. You will see that the LED flashes rapidly while it is looking to connect and will not do so until the COM port is opened with the C# application.

Use this at your own risk as it is only test code I used to get communication working.

Re: Serial Communication - LattePanda Leonardo [SOLVED]

Posted: Fri Sep 15, 2017 7:51 am
by ED209
I failed to upload attachments also...
@Admin, could you please fix that?

Re: Serial Communication - LattePanda Leonardo [SOLVED]

Posted: Fri Sep 15, 2017 9:17 am
by LattePanda
Problem fixed! Now you can upload attachments properly!