Serial Communication with Arduino

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 184
Joined: Wed Apr 10, 2013 5:09 pm

Serial Communication with Arduino

Post by andrewferguson » Wed Mar 04, 2015 7:13 pm

Hello,

I have been trying to allow LiveCode and an Arduino Uno to communicate with each other through serial. I have tried various methods, and yet I cannot get either transmitting or receiving from LiveCode to work.

Receiving data from Arduino in LiveCode

I set up a simple sketch on the Arduino which transmitted a line of text repeatedly every second. Using this thread: http://forums.livecode.com/phpBB2/viewt ... =9&t=22617, I created the following script (placed on a button):

Code: Select all

on MouseUp
   open driver "COM4:" for binary update
   read from driver "COM4:" for 1 line in 100 milliseconds
   put it
   close driver "COM4:"
end mouseUp
When clicking on the button, nothing is placed in the message box (i.e. it is not reading any data from the serial port). Repeatedly clicking on the button reveals that sometimes the data is received: about 1 in every click gives the correct text or a garbled version of it. This makes me think that LiveCode must be reading the serial port at the exact time that the Arduino sends the text for the text to be received by LiveCode.

Sending data from LiveCode in Arduino

I set up a simple sketch on the Arduino that turned on an LED when it received a letter ('a') from the serial port. I tested this using the standard Arduino serial monitor program and it worked successfully. When I tried to send 'a' from LiveCode, the LED did not switch on. However, the RX (receiving serial data light on the Arduino) light flashed to indicate that the Arduino was receiving something, however I am not sure what that something was.

Does anyone know how I can fix these problems? For receiving data, I would ideally like the serial port to appear like a file, where data can be "written" to it bu the Arduino, and only disappears from the file once LiveCode has read it. For sending data, I would just like it to work! (the text that LiveCode sends to Arduino can be received by the Arduino).

Thank you,
Andrew

andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 184
Joined: Wed Apr 10, 2013 5:09 pm

Re: Serial Communication with Arduino

Post by andrewferguson » Sat Mar 07, 2015 5:16 pm

Hi everyone,

After a bit of googling, coding and testing, I have found the answer to this.

LiveCode 7 appears not to work with serial communication. I have now switched back to using LiveCode 6.5.2, and everything works well.

There was only I change that needs to be made to my above code for communication with an Arduino. The 'open driver "COM4:" for binary update' line should be run a while before any communication with the Arduino takes place. This is because when this line is run the Arduino will restart, to allow it to communicate with the newly created serial port. It takes around 2-3 seconds for the Arduino to restart, and therefore any send/read commands issued during this time will not be acted upon by the Arduino.

Regarding the problem with LiveCode 7 and serial communication, has this bug been reported yet?

Thanks,
Andrew

Edit: I have just noticed that this bug has been reported as Bug 12545. According to the LiveCode 7.0.0 Release Notes, this bug was fixed in LiveCode 7, however looking at the comments in the quality control center, people seem to be having the same problems with LiveCode 7 as me.

zhanghuanqian
Posts: 20
Joined: Sat Jan 24, 2015 2:27 pm

Re: Serial Communication with Arduino

Post by zhanghuanqian » Mon Jan 18, 2016 6:47 am

I have the same problem. and have the problem used the LC8.0.
how can i deal with it?

simon.schvartzman
Posts: 638
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: Serial Communication with Arduino

Post by simon.schvartzman » Wed Jun 20, 2018 2:58 pm

Hi @andrewferguson & @zhanghuanqian were you able to solve it? How?
I'm starting a project involving LC to Arduino communication and it would save me time if you help me to avoid false starts.

Many thanks in advance
Simon
________________________________________
To ";" or not to ";" that is the question

Post Reply

Return to “Talking LiveCode”