2 sensor readings onto cartesian plane + graph area calculation

Hello all,

I am tinkering about a project to use an arduino to build a digital engine indicator. This means the system is aimed at writing a pressure-volume-diagram.

I have looked up graphing with arduinos, but I only get solutions for one or more variables over time. What I am looking for is a solution, that writes the sensor data in a cartesian plane with the x-axis being the piston travel and the y-axis the pressure inside the engine for the given piston position. The solution needs to associate for each x-value a specific pressure value and draw the diagram after one rotation of the engine. This diagram can stay for a couple of seconds and then, the reading and graphing begins anew. How is that done?
The next step would be to calculate the average pressure of the diagram. Since the x-dimensions of the diagrams are constant (piston stroke), I'd subtract each lower y-value from the higher y-value for any given x-value within the x-dimensions of the graph, add it all up and divide with the piston stroke to get the average pressure and can calculate the internal power. The trick would be to make sure any given x-value actually HAS 2 y-values (potentially tricky for the lowest and highest x-value of the graph)

How would one approach this?

I would start by just printing piston stroke (x) and corresonding pressure (y) value pairs.
Then I would add in a print statement to mark the start/end of a cycle. Finally I would work out how to display or graph the data.

Why is it a problem to make sure that each x has two corresponding y values?
Surely you just keep reading stroke position and pressure as a constant stream of points?

Riccardo001:
his diagram can stay for a couple of seconds and then, the reading and graphing begins anew. How is that done?

You probably can't, and I think you will eventually realise that you wouldn't want to. This might be after you work out what happens in the two seconds when the graph is stationery. You might get value out of the PLX macro, which gives a constantly updated graph in Excel, using data from Arduino..

How many readings do you get with every engine revolution?

If you (also) get the crank shaft angle, you know when a rotation is finished. This angle will correspond to the volume, so that you may have measured this angle already.

,,Why is it a problem to make sure that each x has two corresponding y values?"

No, it isn't. Actually, I was aiming for that. The problem is, how do I make sure, that there ARE 22 y-values for one x-value. Because that way, I would be able to just subtract the smaller y-value from the bigger one for each x-value to calculate the average internal pressure. I was wondering if it was possible to divide the piston travel into say 50 segments (100 for one rotation was, what I aim for, but I could get tricky considering the rpms). That way, I could program it in a way to demand a pressure value for any step, that is reached at that moment. I don't know - It seems to be the simplest solution that comes in my mind - Like: 1. step: recognize the max and min points of the stroke and calculate the stroke. 2. step: divide the stroke into 50 segments. 3. step: whenever a segment is reached, the pressure sensor read gets associated with that x-value. Something like that? (capital question mark) Or maybe another method would be to use time as the thing to go. Maybe that would be easier. For any let's say 2 miliseconds, the sensor reading of each sensor get linked to draw a point. Meaning the faster the engine runs, the less points the graph will consist of. But this would not be such a problem.

,,Surely you just keep reading stroke position and pressure as a constant stream of points?"

This is let's say the starting point: There are 2 sensors offering values to the arduino. But to connect the values like mentioned here above is the question.

,,You probably can't, and I think you will eventually realise that you wouldn't want to. This might be after you work out what happens in the two seconds when the graph is stationery. You might get value out of the PLX macro, which gives a constantly updated graph in Excel, using data from Arduino..You probably can't, and I think you will eventually realise that you wouldn't want to. This might be after you work out what happens in the two seconds when the graph is stationery. You might get value out of the PLX macro, which gives a constantly updated graph in Excel, using data from Arduino.."

Actually this would be absolutely ok for now.

,,How many readings do you get with every engine revolution?

If you (also) get the crank shaft angle, you know when a rotation is finished. This angle will correspond to the volume, so that you may have measured this angle already."

I am not sure how many points I would need for a p-V-diagram, but I think 20 points for one revolution would already be very crude. I had 100 points in mind, though this would mean 0.2ms time difference for each point for 3300rpm. I doubt the sensors respond so fast. I need to experiment with that when it is set up to find the best settings for that.