大气压数据采集
目的本教程将教大家如何把Microduino-10DOF模块中的BMP180大气压传感器测到的数据以曲线图的方式在Processing中显示。 设备
原理图直接使用Microduino-10DOF上的BMP180大气压传感器 程序调试步骤一:按着原理图搭建硬件环境,像这样:
本例需要两端的代码,Processing端和Microduino端 Microduino: //得到大气压数据后输出到串口以便Processing显示 void vobmp085()
{
// request pressure (3x oversampling mode, high detail, 23.5ms delay)
barometer.setControl(BMP085_MODE_PRESSURE_3);
while (micros() - lastMicros < barometer.getMeasureDelayMicroseconds());
// read calibrated pressure value in Pascals (Pa)
pressure = barometer.getPressure();
Serial.println(pressure/1000,3);
delay(100);
}
Processing: //得到第一个串口的数据,并定义如果有换行就缓存 // is always my Microduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line
//把从Microduino接收到的数据以曲线图的形式显示在屏幕上,并标上标尺 void draw() {
background(255);
// Draw lines connecting all points
for (int i = 0; i < vals.length-1; i++) {
stroke(0);
strokeWeight(1);
line(i, vals[i], i+1, vals[i+1]);
}
// Slide everything down in the array
for (int i = 0; i < vals.length-1; i++) {
vals[i] = vals[i+1];
}
String val = myPort.readStringUntil('\n');
if (val != null) {
val = trim(val);
println(val);
pressure=Float.parseFloat(val);
}
vals[vals.length-1] = 200-pressure;
//Display scale
text ( "200-", 370, 10);
text ( "--", 370, 50);
text ( "100-", 370, 100);
text ( "--", 370, 150);
text ( "0-", 370, 200);
//show current num
text ( pressure+" Kpa", 0, 10);
}
步骤三:下载代码并编译通过。 步骤四:运行后,看看能不能显示出光大气压数据。 结果屏幕上会显示大气压的曲线图数据,像这样:
视频 |

