Serial Communication - LattePanda Leonardo [SOLVED]

A place to talk about all the Operating Systems, Software & Hardware
Forum rules

- Posts are to be made in the relevant forum. Users are asked to read the forum descriptions before posting.

- Members should post in a way which is consistent with "normal writing". That is users should not post excessive numbers of emoticons, large, small or coloured text, etc. Similarly users should not SHOUT or use excessive punctuation (e.g. ! and ?) in topic titles or posts.

- Members should use an appropriate, descriptive subject when posting a new topic. Examples of bad subjects include; "Help me!", "I'm stuck!", "I've got an error!", etc. Examples of good subjects include; "Getting an TABLE FULL error upon login", "Cannot restore a backup".

- Members are asked to post in English only so that posts can be well received and properly monitored.

- Spam is not tolerated here under any circumstance. This includes offering hosting services (charged and free), installation services, solicitation etc. Recruiting members for your own projects (moderators, designers, professional MOD work, etc.) is not permitted and is also considered spam. Users posting spam will be warned and their post removed.

- Members should post in a way that is respectful of other users. Flaming or abusing users in any way will not be tolerated and will lead to a warning. Vulgar language and inappropriate material is not allowed and will be removed. We try to maintain a family friendly atmosphere whenever it is possible within the main subject matter of this community. Please keep this in mind when participating.

- Each user is allowed to create one account. If you would like to change your username, please contact us and, most likely, we can do it for you while you can keep all of your profile data, posts, and other content.

- If a user violates our guidelines and shows a disregard for them, our staff and our community, they run the risk of losing their account. We reserve the right to deactivate any account and to edit or remove any content without warning. These guidelines are subject to change at any time without notice.

Thank you for visiting LattePanda.com!
User avatar
atestani
Posts: 19
Joined: Mon Aug 14, 2017 7:27 pm

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".

User avatar
Lutz
Posts: 214
Joined: Mon Apr 18, 2016 4:30 am
Location: Germany, NRW

Fri Sep 08, 2017 6:25 am

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!

User avatar
ED209
Posts: 222
Joined: Tue Apr 19, 2016 3:31 pm

Fri Sep 08, 2017 8:21 am

Hi atestani, why don't you use the standard firmata protocol to build the communication between Arduino and CPU? Just be curious.

User avatar
LattePanda
Site Admin
Posts: 2642
Joined: Wed Jan 20, 2016 9:09 am

Fri Sep 08, 2017 8:43 am

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. :)
Enjoy Tinkering with LattePanda ! :lol:

User avatar
atestani
Posts: 19
Joined: Mon Aug 14, 2017 7:27 pm

Fri Sep 08, 2017 12:25 pm

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.

User avatar
ED209
Posts: 222
Joined: Tue Apr 19, 2016 3:31 pm

Thu Sep 14, 2017 11:21 am

Very cool! What's your next step? I also want to build some applications based on microcontroller and CPU together. Any idea?

User avatar
atestani
Posts: 19
Joined: Mon Aug 14, 2017 7:27 pm

Thu Sep 14, 2017 2:34 pm

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.
Attachments
LPSerial Test.zip
(15.03 KiB) Downloaded 273 times
Last edited by atestani on Fri Sep 15, 2017 12:12 pm, edited 1 time in total.

User avatar
ED209
Posts: 222
Joined: Tue Apr 19, 2016 3:31 pm

Fri Sep 15, 2017 7:51 am

I failed to upload attachments also...
@Admin, could you please fix that?

User avatar
LattePanda
Site Admin
Posts: 2642
Joined: Wed Jan 20, 2016 9:09 am

Fri Sep 15, 2017 9:17 am

Problem fixed! Now you can upload attachments properly!
Enjoy Tinkering with LattePanda ! :lol:

Post Reply