1. Read/Write USB
- Posted by irv Feb 12, 2018
- 1289 views
Can anyone suggest a starting point for reading/writing data from Arduino connected via USB (/dev/ttyUSB0, for example) in Euphoria?
I want to eventually graph the data, and control the Arduino via a control panel written in EuGTK.
2. Re: Read/Write USB
- Posted by jimcbrown (admin) Feb 12, 2018
- 1264 views
Can anyone suggest a starting point for reading/writing data from Arduino connected via USB (/dev/ttyUSB0, for example) in Euphoria?
I want to eventually graph the data, and control the Arduino via a control panel written in EuGTK.
You'd be in control of the data on both sides, right? Why wouldn't a simple open()/get()/puts() on /dev/tty/USB0 work?
3. Re: Read/Write USB
- Posted by ghaberek (admin) Feb 12, 2018
- 1261 views
Can anyone suggest a starting point for reading/writing data from Arduino connected via USB (/dev/ttyUSB0, for example) in Euphoria?
I want to eventually graph the data, and control the Arduino via a control panel written in EuGTK.
You'd be in control of the data on both sides, right? Why wouldn't a simple open()/get()/puts() on /dev/tty/USB0 work?
I don't think it's that simple unfortunately. You'd need to set up the port specs and enable raw throughput: https://stackoverflow.com/a/18134892/2300395
You could also try libserialport. It builds easily enough and the API looks pretty straight-forward to wrap.
-Greg
4. Re: Read/Write USB
- Posted by jmduro Feb 12, 2018
- 1291 views
If the Arduino is connected through a USB/serial adapter, then Jacques Deschênes's serial library will fit the job. I used it this way.
include serial.ew atom hCom1 constant MAXDWORD=#FFFFFFFF ------------------------------------------------------------------------------ public function serialOpen(integer port ,sequence baud ,sequence parity , sequence numBits ,sequence numStop ,sequence control) hCom1 = serial_open(port) if hCom1 < 0 then printf(1,"Error opening port %d.\n\n",port) return 0 else -- http://msdn.microsoft.com/en-us/library/aa363190%28v=VS.85%29.aspx -- A value of MAXDWORD, combined with zero values for both the ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier members, -- specifies that the read operation is to return immediately with the bytes that have already been received, -- even if no bytes have been received. SetCommTimeouts(hCom1,{MAXDWORD,0,0,0,0}) SetCommState(hCom1, "baud:"&baud&";parity:"&parity&";bits:"&numBits& ";stop:"&numStop&";control:"&control) PurgeComm(hCom1,PURGE_RXCLEAR) --puts(1, "serialOpen: port set at baud: "&baud&", parity: "&parity&", bits: "&numBits& -- ", stop bits: "&numStop&", flow control: "&control) return 1 end if -- return hCom1 end function ------------------------------------------------------------------------------ public procedure serialClose() serial_close(hCom1) --logMsg("serialClose: connection closed") end procedure ------------------------------------------------------------------------------ public procedure serialSend(object x) serial_puts(hCom1, x) end procedure ------------------------------------------------------------------------------ public function serialReceive() return serial_getc(hCom1) end function
Jean-Marc
5. Re: Read/Write USB
- Posted by evanmars Feb 14, 2018
- 1195 views
I did this a while ago to get info from a DS18B20 temp sensor connected to an Arduino
include serial.ew include std/get.e atom hCom sequence result integer VK_SPACE = #20 integer state = 0 atom t0 = time() public object temperature hCom = serial_open(10) if hCom != -1 then while 1 do if time() - t0 then temperature = value(serial_gets(hCom)) temperature = temperature[2] --printf(1,"%3.2fC, %3.2fF\n",{temperature,temperature*9/5+32}) if get_key() = VK_SPACE then exit end if t0 = time() end if end while else puts(1,"No connection to Arduino\n\n") puts(1,"Press Enter\n") getc(0) end if