multiple figures while plotting in real time

Hi guys,

I have been trying to plot data in real time (in Pyton) from a DHT11 sensor (temperature and humidity) connected with a arduino Uno. I managed to get a code with which I can make one coordinate system with two graphs (see code 1). I also managed to change the code a little bit, so I can make 2 coordinate systems now, with in each plotted one graph (see code 2). The problem with the second code is, when I run it, I get two coordinate systems which overlap each other constantly.
I am working on a project of plotting multiple graphs in different coordinate systems (real time). So I would be very pleased if someone could help me plotting multiple graphs in real time (multiple coordinate systems)

Thanks in advance!!

I knnow this is no Python forum, but I posted my problem on several platforms, and did not get a reply.

PS. I followed the instructions and copied the code from this site (http://www.toptechboy.com/tutorial/python-with-arduino-lesson-11-plotting-and-graphing-live-data-from-arduino-with-matplotlib/)

I hope someone can help me.

Thanks in advance.

Line 25 of the code you didn't post looks like it might be wrong.

I was trying to post the Python code, but I got the message, that I was using forbidden words. I will try to upload the codes in another way.

arduino python plotting for real.txt (3.18 KB)

python code nummer 2.txt (4.13 KB)

Those two files are the same code, you have not posted the Arduino code.

Grumpy_Mike:
Those two files are the same code, you have not posted the Arduino code.

Yeah, I know, I changed only some comment lines (in front of the makeFig2).

Yeah, I know, I changed only some comment lines (in front of the makeFig2).

So in what way is that helpful in trying to ask for help?

This is the arduino program I momentarily use:

#include <dht.h>

dht DHT;


#define DHT11_PIN 7

float temp;
float humidity;

void setup(){
  Serial.begin(9600);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  
  Serial.print(DHT.temperature);
  Serial.print(" , ");
  Serial.println(DHT.humidity);
  delay(1000);
}

And this is the arduino code I am planning to use:

#include <SoftwareSerial.h>
#include <HMC5883L.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_BMP280.h>

File SDsaver;
int chipSelect=4;

int sensorPin = A1; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from the sensor

Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);

//bmp280 pins
#define BMP_SCK 6
#define BMP_MISO 7
#define BMP_MOSI 5
#define BMP_CS 4

Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK); //spi software library

void setup() {
Serial.begin(9600); //sets serial port for communication
Serial.begin(9600);
Serial.begin(9600);
SD.begin(chipSelect);

  Serial.println("HMC5883 Magnetometer Test"); Serial.println("");
  
  /* Initialise the sensor */
  if(!mag.begin())
  {
    /* There was a problem detecting the HMC5883 ... check your connections */
    Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");
    while(1);
  }
  
Serial.begin(9600);
Serial.println(F("BMP280 test"));
  
  if (!bmp.begin()) {  
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);  
}
}


void loop() {

SDsaver=SD.open("PTDATA.txt" , FILE_WRITE);
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); //prints the values coming from the sensor on the screen
delay(150);


/* Get a new sensor event */ 
  sensors_event_t event; 
  mag.getEvent(&event);
 
  /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
  Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print("  ");Serial.println("uT");

  // Hold the module so that Z is pointing 'up' and you can measure the heading with x&y
  // Calculate heading when the magnetometer is level, then correct for signs of axis.
  float heading = atan2(event.magnetic.y, event.magnetic.x);
  
  // Once you have your heading, you must then add your 'Declination Angle', which is the 'Error' of the magnetic field in your location.
  // Find yours here: http://www.magnetic-declination.com/
  // Mine is: -13* 2' W, which is ~13 Degrees, or (which we need) 0.22 radians
  // If you cannot find your Declination, comment out these two lines, your compass will be slightly off.
  float declinationAngle = 0.0;
  heading += declinationAngle;
  
  // Correct for when signs are reversed.
  if(heading < 0)
    heading += 2*PI;
    
  // Check for wrap due to addition of declination.
  if(heading > 2*PI)
    heading -= 2*PI;
   
  // Convert radians to degrees for readability.
  float headingDegrees = heading * 180/M_PI; 
  
  Serial.print("Heading (degrees): "); Serial.println(headingDegrees);
  
  delay(150);


  float sensorVoltage; 
  float sensorValue;
 
  sensorValue = analogRead(A0);
  sensorVoltage = sensorValue/1024*3.3;
  Serial.print("sensor reading = ");
  Serial.print(sensorValue);
  Serial.println("");
  Serial.print("sensor voltage = ");
  Serial.print(sensorVoltage);
  Serial.println(" V");
  delay(150);


 Serial.print(F("Temperature = "));
 Serial.print(bmp.readTemperature());
 Serial.println(" *C");
    
 Serial.print(F("Pressure = "));
 Serial.print(bmp.readPressure());
 Serial.println(" Pa");

 Serial.print(F("Approx altitude = "));
 Serial.print(bmp.readAltitude(1000.25)); // this should be adjusted to your local forcase
 Serial.println(" m");
    
 Serial.println();
 delay(150);

if(SDsaver) {
SDsaver.print(event.magnetic.x);
SDsaver.print(" , ");
SDsaver.print(event.magnetic.y); 
SDsaver.print(" , ");
SDsaver.print(event.magnetic.z); 
SDsaver.print(" , ");
SDsaver.println("uT"); 
SDsaver.println(headingDegrees);
SDsaver.println(sensorValue);
SDsaver.print(sensorVoltage);
SDsaver.print(" , ");
SDsaver.println(sensorVoltage);
SDsaver.print(bmp.readTemperature());
SDsaver.print(" , ");
SDsaver.print(bmp.readPressure());
SDsaver.print(" , ");
SDsaver.println(bmp.readAltitude(1005.25));
SDsaver.close();
  
}
}

And this is the arduino code I am planning to use:

With that Python code? Surly not as you have lots of serial print commands that you are not coping with in the Python.

The python code just takes two values and then tries to plot a graph with it. Then the next two come along and you try and plot a completely new graph with those two.

I am sorry, I posted indeed two timesthe same file.
Here are the good ones.

Sorry....

arduino forum 232.txt (2.22 KB)

arduino forum.txt (2.26 KB)

Stop it. Are you trying to take the piss, two identical python files again.

Grumpy_Mike:
With that Python code? Surly not as you have lots of serial print commands that you are not coping with in the Python.

The python code just takes two values and then tries to plot a graph with it. Then the next two come along and you try and plot a completely new graph with those two.

I am plotting the results of the first arduino sketch. I am not trying to plot the data from the other sketch with the same python code, but I would like to make two coordinate systems with in one temperature plotted and in the other humidity.

On one page.

In the second file (arduino forum 232.txt of the python code, I wrote to make a second figure. (makeFig2). So with that I managed (as said in my first post) to create 2 coordinate systems.
But the problem with these two, is that they constantly overlap each other.

In the first file (arduino forum.txt) I just created 1 coordinate system.

(deleted)