I have an Arduino (Uno) connected to a macbook on MacOS 10.14 using USB and I am trying to exchange data using R.
Setting up a connection and reading data works fine, but writing data provokes an error and I am not sure what’s wrong. A working example:
#loading the R package for serial communication require(serial) #storing the appropriate serial device name con_dir = "/dev/" con_arduino_cu<-list.files(con_dir, pattern ="cu.usb") #setting up connection parameters, making sure the BAUD rate matches the one used by the Arduino con <- serialConnection(name = "testcon" ,port = con_arduino_cu ,mode = "9600,n,8,1" ,buffering ="none" ,newline = 1 ,translation = "cr" #opening and testing the connection open(con) isOpen(con) #this reads that from the Arduino read.serialConnection(con) #But this returns an error: 'Error: [tcl] can't read "tcl_tmp_cu": no such variable' write.serialConnection(con,"Hello world")
I have tried using the ttl connection instead of the cu connection, but this makes R hang.
Any idea on whats wrong, or for alternative ways to write data over USB?