Some questions about R

Hello!
I have a code on R for reading the Serail port of Arduino Uno.
I get the Array:
[1]
475 \ n, 474 \ n, 475 \ n, 475 \ n, 475 \ n, 475 \ n, 475 \ n, 475 \ n, 475 \ n, 475 \ n, 474 \ n, 474 \ n, 474 \ n, 474 \ n, 474 \ n, 473 \ n, 473 \ n, 473 \ n, 473 \ n, 472 \ n, 472 \ n, 472 \ n, 471 \ n, 471 \ n, 471 \ n , 470 \ n, 470 \ n, 469 \ n, 469 \ n, 468 \ n, 468 \ n, 467 \ n, 467 \ n, 466 \ n, 465 \ n, 465 \ n, 464 \ n, 463 \ n, 463 \ n, 462 \ n, 461 \ n, 460 \ n, 460 \ n, 459 \ n, 458 \ n, 457 \ n, 456 \ n, 455 \ n, 455 \ n, 454 \ n , 453 \ n, 452 \ n, 451 \ n, 450 \ n, 449 \ n, 448 \ n, 447 \ n, 447 \ n, 446 \ n, 445 \ n, 444 \ n, 443 \ n, 442 \ n, 441 \ n, 441 \ n, 440 \ n, 439 \ n, 438 \ n, 437 \ n, 436 \ n, 435 \ n, 435 \ n, 434 \ n, 433 \ n, 432 \ n , 430 \ n, 429 \ n, 428 \ n, 426 \ n, 425 \ n, 424 \ n, 422 \ n, 421 \ n, 420 \ n, 419 \ n, 418 \ n, 417 \ n, 416 \ n, 415 \ n, 414 \ n, 413 \ n, 412 \ n, 411 \ n, 411 \ n, 410 \ n, 409 \ n, 409 \ n, 409 \ n, 408 \ n, 407 \ n , 407 \ n, 407 \ n, 406 \ n, 406 \ n, 405 \ n, 405 \ n, 404 \ n, 404 \ n, 404 \ n, 403 \ n, 403 \ n, 403 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n , 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 402 \ n, 403 \ n, 403 \ n, 403 \ n, 403 \ n, 403 \ n, 404 \ n, 404 \ n, 404 \ n, 404 \ n, 404 \ n, 405 \ n, 405 \ n, 405 \ n, 405 \ n, 405 \ n, 405 \ n, 405 \ n, 406 \ n , 406 \ n, 406 \ n, 406 \ n, 406 \ n, 406 \ n, 407 \ n, 407 \ n, 407 \ n, 408 \ n, 408 \ n, 409 \ n, 410 \ n, 410 \ n, 411 \ n, 412 \ n, 4 12 \ n ...

How do I convert Array to a vector? Thank you.

How do I convert Array to a vector?

Why do you think you need to?

I want to build histogram from Micro-spectrometer C12880MA.

Arduino code (part):

#define SPEC_CHANNELS 288 // New Spec Channel
uint16_t data[SPEC_CHANNELS];
...
...
void printData() {
for (int i = 0; i < SPEC_CHANNELS; i++) {
Serial.println(data*);*

  • }*
    }
    RStudio code for Serial read:
    con <- serialConnection(name = "get_temps",
  • port = "COM10",*
  • mode = "115200,n,8,1",*
  • buffering = "none",*
  • newline = 1,*
  • translation = "cr")*
    isOpen(con)
    open(con)
    isOpen(con)
    ### grab data from serial port
    read.serialConnection(con)
    RStudio Result:
    [1]
    475 \ n, 474 \ n, ...
    I can't build diagram or histogram.

I can't build diagram or histogram.

Do you mean "I don't know how to..." instead of "can't"?

In either case, how is this an Arduino question?

Sorry, it's true. "I don't know how to..." and it's more R question.
Sorry.

What is R ?

RStudio (RStudio makes R easier to use. It includes a code editor, debugging & visualization tools)

HzAndriy:
RStudio (RStudio makes R easier to use. It includes a code editor, debugging & visualization tools)
https://www.rstudio.com/

OK, but what is R ?

A quick "Google" reveals that

R is an integrated suite of software facilities for data manipulation, calculation and graphical display.

So, it sounds like you want the Arduino to read values from a sensor and send it to "R" using the serial interface.

Is that right ?

Is the problem that you cannot read the incoming serial data in "R" or that you can read it but not put it into an array in "R" to be graphed ?

it's more R question.

That's what it sounds like to me too.

Yes, it's true. I use the Arduino to read values from a sensor and send it to "R" using the serial interface. It works.
I use how example, Arduino data to R · GitHub

But it's working, when Arduino Read 1 item (for example Serial.println(temperature); ) one reading - one item (value) receved.
I have the sensor (https://impfs.github.io/review/) that give array for one read cycle and I don't know how this array can be graphed in R.

I don't know how this array can be graphed in R.

Then I fear that you are asking in the wrong place.

Is there an "R" or RStudion support forum or user group ?

Thank you, guys!
I will be searching answer on the RStudio support forum.

HzAndriy:
Yes, it's true. I use the Arduino to read values from a sensor and send it to "R" using the serial interface. It works.
I use how example, Arduino data to R · GitHub

But it's working, when Arduino Read 1 item (for example Serial.println(temperature); ) one reading - one item (value) receved.
I have the sensor (https://impfs.github.io/review/) that give array for one read cycle and I don't know how this array can be graphed in R.

you are trying to transmit from your arduino over serial, just iterate over the array and send your data.

  float f1 = 1.31;
  float f2 = 2.39;
  float f3 = 3.01;
  float arr[3] = { f1, f2, f3 };
  Serial << "My Array:";
  for (float i :arr) {
    Serial << static_cast<int>i;
    Serial << ".";
    Serial << static_cast<int>((i * 100)%100);
    Serial << ";";
  }

just iterate over the array and send your data.

The code in reply #6 does that but has been mangled by using an array index of [­i]

The problem would seem to be in receiving and storing the data in "R"

The problem was partly resolved. Manually (in RStudio) to do deleting "\ n" in string 475 \ n, 474 \ n, 475 \ n, 475 \ n, 475 \ n, .

But there is yet one problem. I reading (in R -
--- read.serialConnection(con)) all data from Serail. Their number increase and repeating.
How to do in order to read only new array but don't all arrays at once.

Code:

/*
  Macro Definitions
*/
#define SPEC_TRG         A0
#define SPEC_ST          A1
#define SPEC_CLK         A2
#define SPEC_VIDEO       A3
#define WHITE_LED        A4
#define LASER_404        A5

#define SPEC_CHANNELS    288 // New Spec Channel
uint16_t data[SPEC_CHANNELS];

unsigned long int_time = 4096;
int incomingByte = 0;

void setup() {
 
 //Set desired pins to OUTPUT
 pinMode(SPEC_CLK, OUTPUT);
 pinMode(SPEC_ST, OUTPUT);
 pinMode(LASER_404, OUTPUT);
 pinMode(WHITE_LED, OUTPUT);

 digitalWrite(SPEC_CLK, HIGH); // Set SPEC_CLK High
 digitalWrite(SPEC_ST, LOW); // Set SPEC_ST Low

 Serial.begin(115200); // Baud Rate set to 115200
}

/*
  This functions reads spectrometer data from SPEC_VIDEO
  Look at the Timing Chart in the Datasheet for more info
*/
void readSpectrometer() {
 
 // Start clock cycle
 for (int i = 0; i < 10; i++) {
   digitalWrite(SPEC_CLK, LOW);
   digitalWrite(SPEC_CLK, HIGH);
 }

 // set START high and do four clock cycles
 digitalWrite(SPEC_CLK, LOW);
 digitalWrite(SPEC_ST, HIGH);
 for (int i = 0; i < 4; i++) {
   digitalWrite(SPEC_CLK, HIGH);
   digitalWrite(SPEC_CLK, LOW);
 }

 //Clock cycles for integration time
 for (int i = 0; i < int_time; i++) {
   digitalWrite(SPEC_CLK, HIGH);
   digitalWrite(SPEC_CLK, LOW);
 }

 //Set SPEC_ST to low
 digitalWrite(SPEC_ST, LOW);

 //Sample for a period of time
 for (int i = 0; i < 88; i++) {
   digitalWrite(SPEC_CLK, HIGH);
   digitalWrite(SPEC_CLK, LOW);
 }

 //Read from SPEC_VIDEO
 for (int i = 0; i < SPEC_CHANNELS; i++) {
   data[i] = analogRead(SPEC_VIDEO);
   digitalWrite(SPEC_CLK, HIGH);
   digitalWrite(SPEC_CLK, LOW);
 }

 //Run clock for a small amount of time
 for (int i = 0; i < 7; i++) {
   digitalWrite(SPEC_CLK, HIGH);
   digitalWrite(SPEC_CLK, LOW);
 }
 digitalWrite(SPEC_CLK, HIGH);
}

/*
  The function below prints out data to the
  terminal or processing plot
*/
void printData() {
 
 for (int i = 0; i < SPEC_CHANNELS; i++) {
   Serial.println(data[i]); 
   //Serial.print(data[i]);
   //Serial.print(',');
 }
 //Serial.print("\n");
}

void loop() {
 
 readSpectrometer();
 printData();
 delay(2000);

 // check for incoming data
 if (Serial.available() > 0) {
   // read the incoming byte:
   incomingByte = Serial.read();
   if (incomingByte==93) {
     int_time=min(int_time*2,1048576);
   }
   if (incomingByte==91) {
     int_time=max(int_time/2,2);
   }
 }
}

Thank you!

How to do in order to read only new array but don't all arrays at once.

Is that another question about how to do something in "R" ?

The problem was partly resolved. Manually (in RStudio) to do deleting "\ n" in string 475 \ n, 474 \ n, 475 \ n, 475 \ n, 475 \ n, .

If the problem is the newline characters then don't send them. Use Serial.print() instead of Serial.println()

So, I now think of how to establish friendship "R" and Arduino

PaulS:
I'd like to win the lottery, too. Neither of us is likely to get what we want just be wishing.

PaulS:
Do you mean "I don't know how to..." instead of "can't"?

In either case, how is this an Arduino question?

Hey man...want to stop being an asshole? They didn't come here for snide remarks and for you to show everyone how superior you are at coding. They came for help, so prompt them, lead them, don't lambaste them.

Davidjb7:
Hey man...want to stop being an asshole?

In this situation the best way to deal with assholes is to drown them out. You would do that by trying to help @HzAndriy.

If you continue the childish name calling you will be spending some time away from the forum.