Skip to content

Commit 32df3ed

Browse files
committed
shorten sleep time in flush
1 parent be5f968 commit 32df3ed

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

R/ar_stream.R

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
#'
1111
#' @export
1212
ar_stream <- function(fd, eolchar = "\n", buf_max = 256, timeout = 5000) {
13+
ar_flush(fd)
14+
ar_read(fd, eolchar, buf_max, timeout)
1315
repeat(cat(ar_read(fd, eolchar, buf_max, timeout)))
1416
}

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
As one important piece of the fast growing ["IoT"](https://en.wikipedia.org/wiki/Internet_of_things) movement, arduino chips enable scientists and hobbyists to build customizable digital devices at will at a very inexpensive price. For the scientific community, it opens up a new way to collect various formats of data, such as accelerometer, gyroscope, thermometer and IR. Data collected by arduino can be sent to computers both wirelessly (through the WiFi kit on some recent devices such as ESP8266) or wirely through serial ports. This package handles reading arduino data from serial port into R.
55

6-
Current approaches in R, including the `serial` package or [this post](https://www.r-bloggers.com/connecting-the-real-world-to-r-with-an-arduino/), both have dependency requirements. This package binds the light-weight [arduino-serial](https://github.com/todbot/arduino-serial) C library to R and is both dependency-free and fast.
6+
Current approaches in R, including the `serial` package or [this post](https://www.r-bloggers.com/connecting-the-real-world-to-r-with-an-arduino/), both have dependency requirements. This package binds the light-weight [arduino-serial](https://github.com/todbot/arduino-serial) C library by Tod E. Kurt to R using Rcpp. It is both dependency-free and fast.
77

88
# Installation
99
```r
@@ -15,7 +15,10 @@ devtools::install("hebrewseniorlife/arduino")
1515
library(arduino)
1616

1717
# Use the baud rate you set in `Serial.begin();` in arduino
18+
# On Mac
1819
con <- ar_init("/dev/cu.SLAB_USBtoUART", baud = 57600)
20+
# On Windows
21+
con <- ar_init("COM1", baud = 57600)
1922

2023
# Start to stream arduino data into console. Press STOP to stop.
2124
ar_stream(con)

src/arduino-serial-lib.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,6 @@ Rcpp::String ar_read(int fd, char eolchar = '\n',
253253
// [[Rcpp::export]]
254254
int ar_flush(int fd)
255255
{
256-
sleep(2); //required to make flush work, for some reason
256+
usleep(10000); //required to make flush work, for some reason
257257
return tcflush(fd, TCIOFLUSH);
258258
}

0 commit comments

Comments
 (0)