Real time plotting of multiple sensors data to in python

I have the following code to extract data from multiple sensors and plot it real time, but I am getting an error.

no matching function for call to ‘sendToPC(double*)’

and 1 more thing, how do I connect my various sensors, to the same analog pin ? or to multiple pins ?

unsigned long timer = 0;
long loopTime = 5000;   // microseconds

void setup() {
  Serial.begin(38400);
  timer = micros();
}

void loop() {
  timeSync(loopTime);
  //int val = analogRead(0) - 512;
  double data1 = (analogRead(0) -512) / 512.0;
  sendToPC(&val);
}

void timeSync(unsigned long deltaT)
{
  unsigned long currTime = micros();
  long timeToDelay = deltaT - (currTime - timer);
  if (timeToDelay > 5000)
  {
    delay(timeToDelay / 1000);
    delayMicroseconds(timeToDelay % 1000);
  }
  else if (timeToDelay > 0)
  {
    delayMicroseconds(timeToDelay);
  }
  else
  {
      // timeToDelay is negative so we start immediately
  }
  timer = currTime + timeToDelay;
}

void sendToPC(int* data1, int* data2, int* data3)
{
  byte* byteData1 = (byte*)(data1);
  byte* byteData2 = (byte*)(data2);
  byte* byteData3 = (byte*)(data3);
  byte buf[6] = {byteData1[0], byteData1[1],
                 byteData2[0], byteData2[1],
                 byteData3[0], byteData3[1]};
  Serial.write(buf, 6);
}

void sendToPC(double* data1, double* data2, double* data3)
{
  byte* byteData1 = (byte*)(data1);
  byte* byteData2 = (byte*)(data2);
  byte* byteData3 = (byte*)(data3);
  byte buf[12] = {byteData1[0], byteData1[1], byteData1[2], byteData1[3],
                 byteData2[0], byteData2[1], byteData2[2], byteData2[3],
                 byteData3[0], byteData3[1], byteData3[2], byteData3[3]};
  Serial.write(buf, 12);
}

Please help me, thanks in advance.

You are calling sendToPC() only with 1 parameter and the two definitions of that function require to enter 3 parameters (int or double).

So, how do I correct it ?

:thinking: :wink:
Learning C++ language??

// Strange way to send and int via serial port
void sendToPC(int* data1)
{
  byte* byteData1 = (byte*)(data1);
  byte buf[2] = {byteData1[0], byteData1[1]};
  Serial.write(buf, 2);
}

Thanks man, but am getting this error now.

cannot convert ‘double*’ to ‘int*’ for argument ‘1’ to ‘void sendToPC(int*)’

void sendToPC(double* data1)
{
  byte* byteData1 = (byte*)(data1);
  byte buf[12] = {byteData1[0], byteData1[1], byteData1[2], byteData1[3]};
  Serial.write(buf, 4);
}

Now am getting this error man,

‘byteData’ was not declared in this scope

There is no byteData var in function above, check what have you copied/written

Sorry, that was my bad. Now I have a question, do I have to connect all my sensors to the same A0 pin ? And am not able see the data in serial monitor.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.