I want to buffer numbers with arduino and send serial all at once.

Asked 2 years ago, Updated 2 years ago, 91 views

I write a program where arduino reads numbers from analogRead and temporarily stores them in a buffer, but it's not working well.Please let me know how I can solve this problem.
I am trying to use an array to resolve the above, but I cannot read the official numbers.

This is what we need to do to run the arduino program with python and display the numbers on python.

The current code is as follows:

Thank you for your cooperation.

void setup()
{
  pinMode(1,OUTPUT);
  Serial.begin (9600);
}


void loop()
{
  chara;
  if (Serial.available()>0)
  {
    a = Serial.read();
    if(a=='z')
    {
      delay(10);
      digitalWrite (8, LOW);
      Measure();
    }

    if(a=='y')
    {
      digitalWrite (8, HIGH);

    }
  }
}

void Measure()
{
  intx;
  intv[300];
  inti [300];
  for (x=1; x<=300;x++)
  {
    v[x] = analogRead (A3);
   i[x] = analogRead(A4);
    delayMicroseconds (1000);

  }
  delay(5000);
  for (x=1; x<=300;x++)
 {
   Serial.print(v[x]);
   Serial.print(', ');
   Serial.println(i[x]);
 }
}

arduino

2022-09-30 20:24

1 Answers

Is the input pin designation correct?
I can't find the code that defines the input pin used in the function Measure(), A3, A4 values.

v[x]=analogRead(A3); 
i[x] = analogRead(A4);

If you want to read analog values from pins 3 and 4,

v[x]=analogRead(3); 
i[x] = analogRead(4);

Try correcting it.

If "Unable to read official numbers" refers to a phenomenon in which fluctuating values are read without meaning, it is likely that analog values are read from empty pins.
So I suspected the analogRead argument.


2022-09-30 20:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.