Serial Communication With My Arduino


happysmile

Recommended Posts

please help !

Using ARDUINO UNO to generate serial Comm signal "1111111111111111 \ 13 \ 10" which is a array in my Arduino application.

This array is status ON / OFF of 16 relays. ON = logic 0 and OFF = logic 1.

mydevice = Serial Ascii / 9600 N81

canal_0 in to see the data "1111111111111111" is going well, except for the first location. When it is "0" disappears.

Q. how to get state 1 to 16 in separate channels, canal_1 to canal_16

Link to comment
Share on other sites

I'm not sure how you are getting the data now, so I'll just explain how to do it all. I'm going to assume you have mydevice setup with a NULL protocol. I'm also going to assume that your device sends the data on its own. In a sequence put:

device.mydevice.purge()
private string datain
private data
while(1)
   try
      datain = device.mydevice.readuntil(10)
      if (getlength(datain) != 17) // 16 channels plus the carriage return
         continue
      endif
      data = asca(datain)
      for (private i = 0, i < 16, i++)
         execute("canal_" + doubleToStr(i+1) + ".addValue(" + doubleToStr(data[i] - 48) + ")")
      endfor
   catch()
      ? strLastError
   endcatch
   delay(0.05)
endwhile

That should do it, though of course I didn't test it. I used an ascii trick. ASCA() converts the string into an array of numbers. In your case, its either 48 for "0" or 49 for "1". But I want 0 or 1 in the channel, so I subtract 48.

Link to comment
Share on other sites

  • 9 months later...

Archived

This topic is now archived and is closed to further replies.