Check my Arduino

A place for you to show off what you have made with LiveCode

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
NoN'
Posts: 75
Joined: Thu Jul 03, 2008 9:56 pm
Location: Paris
Contact:

Check my Arduino

Post by NoN' » Sat Oct 30, 2021 12:24 am

Within the framework of the "Spectrib" project that I presented before (viewtopic.php?f=143&t=36258) I got interested in the Arduino board and its programming. It should be used to manage the calibration of my spectrometer thanks to a series of LEDs.

I appreciate the Arduino IDE (simple and robust) but I would like to be able to work with the Arduino directly from LiveCode. That's why I initiated the "Check my Arduino" project.

To start, I used information found on the following pages (thanks to their authors):

- viewtopic.php?t=22652
- http://livecodeitalia.blogspot.com/2014 ... ta_95.html

...and it works pretty well !

This little work confirms that it is quite easy to get all kinds of data from so many sensors directly in our favorite development environment.

I want to continue it, now, as a collaborative and open source project so that it can be useful to the whole LiveCode community (and beyond). You will find here a copy of "Check my Arduino" that can be used as a development base for those who would not dare to start.
Check my Arduino.zip
(6.5 KiB) Downloaded 158 times

In the meantime, I suggest you to watch a "small" video that show you an example of possible interaction between LiveCode and Arduino (beware, it's quite "rough"!):

http://rg75.free.fr/CmArduino_Video_and ... rduino.mov

I also put the main script to show that you can get a satisfactory result with relatively little programming, and to inspire vocations.
Script of "Go" btn (adapted from : Max2019, see above):

Code: Select all

on mouseUp
   --- initialisation des variables
   global usbSerial
   if the hilite of btn "ajoutNLigne" then
      put 0 & tab into count
      put "N°" & tab into entete
   else
      put "" into count
   end if
   if the hilite of btn "ajoutHorodateur" then
      put the long date && ";" into horodate
      put "Horadata" & tab after entete
   else
      put "" into horodate
   end if
   put "Ligth intensity" & return after entete
   put "" into fld 1
   put fld "milliSecs" into interv
   put fld "quelPort" & ":" into usbSerial
   put fld "nbLines2scan" into nbLines
   put the botright of fld 1 into laloc
   set the points of graphic "Plot" to item 1 of laloc+30 & "," & item 2 of laloc
   put the  left of graphic "Plot" into deb
   put the  bottom of graphic "Plot" into lebas
   put the width of this window- the width of fld 1-30 into lalarg
   put round (lalarg/50) into enplus
   put "BAUD="& fld "bauds" & " DATA=" & fld "data" & " STOP=" & fld "stop" & " PARITY=" & fld "parity" & " xon=" & fld "xon" & " to=" & fld "to" & " dtr=" & fld "dtr" & " rts=" & fld "rts" into prefsDeCom
   set the serialControlString to prefsDeCom
   if fld "openFor" = "Read" and not the hilite of btn "Binary" then open driver usbSerial for text read
   if fld "openFor" = "Write" and not the hilite of btn "Binary" then open driver usbSerial for text write
   if fld "openFor" = "Read and Write" and not the hilite of btn "Binary" then open driver usbSerial for text update
   if fld "openFor" = "Read" and hilite of btn "Binary" then open driver usbSerial for binary read
   if fld "openFor" = "Write" and hilite of btn "Binary" then open driver usbSerial for binary write
   if fld "openFor" = "Read and Write" and hilite of btn "Binary" then open driver usbSerial for binary update
   if the result <> EMPTY then
      answer "ERROR:" && the result
      exit mouseUp
   else
      put "Connection établie à " & the long date && the long time & return & return & entete & return into fld 1
      read from driver usbSerial for nbLines line in interv milliseconds
      repeat while the mouseloc is not within the rect of btn "Cesse"
         set cursor to busy
         if the mouse is down then
            put the target into quoi
            if the optionkey is not down then
               send "mouseDown" to quoi
            else
               close driver usbSerial
               exit mouseUp
            end if
         else
            read from driver usbSerial for nbLines line in interv milliseconds
            if it is not "" and it is a number then
               put the points of graphic "Plot" into ron
               put the number of lines in ron into nbItems
               put item 1 of last line of ron into deb
               if nbItems * enplus > lalarg then
                  put (deb+enplus) & "," & lebas-it into line (nbItems+1) of ron
                  delete line 1 of ron
               else
                  put (deb+enplus) & "," & lebas-it into line (nbItems+1) of ron
               end if
               set the points of graphic "Plot" to ron
               set the botleft of graphic "Plot" to item 1 of laloc+30 & "," & item 2 of laloc
               
               if the hilite of btn "ajoutNLigne" then add 1 to word 1 of count
               if the hilite of btn "ajoutHorodateur" then put the long date && the long  time & tab into horodate
               put count & horodate & it & return after fld 1
               set the vscroll of fld 1 to ((the number of lines in fld 1)*15)
            end if
         end if
      end repeat
      close  driver usbSerial
   end if
end mouseUp
And I am sure that some people here will find a thousand ways to improve it :)

I'm talking about this project here, but it is an ongoing project. So maybe there is a better forum to discuss of this?
In all cases, don't hesitate to reply or contact me if you are interested in this project...

Renaud

Post Reply

Return to “Made With LiveCode”