Go Down

Topic: Writing to Arduino using R (Read 304 times) previous topic - next topic


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:

Code: [Select]

#loading the R package for serial communication

#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

#this reads that from the Arduino

#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?


I am not sure what you expect with posting R code.
We don't use it here.

Have no idea what a "cu connection" is either.



This is (now?) in the "interfacing section" so any computer language should be OK.

OP might be better of in a forum for the specific language though.

OP, does your Arduino code work with a normal terminal program (e.g. serial monitor)?
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up