消除CC3200上传感器读数的噪音?

时间:2016-07-26 12:33:27

标签: filter webserver client noise

我到目前为止所做的一步一步

1)微控制器使用德州仪器的CC3200(wifi构建微控制器) 2)导电橡胶线拉伸传感器 - 连接到微控制器的模拟引脚     **传感器的行为=(拉伸导电橡胶时电阻增加)

现在,以下是我调试到微控制器以运行传感器的代码参考(使用energia tool-IDE)。 代码只是为Web服务器编写的(我给了 - 可用的wifi ssid和密码 - 您可以在下面的程序中看到“iPhone和passowrd”),其中传感器的代码也写入,

此网络服务器读取并生成微控制器的IP地址以及拉伸传感器的值。

网络服务器代码:

#include <SPI.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
// which analog pin to connect
#define RUBBERPIN A3

// how many samples to take and average, more takes longer
// but is more 'smooth'
#define NUMSAMPLES 5
// the value of the 'other' resistor
#define SERIESRESISTOR 10000
int samples[NUMSAMPLES];

// your network name also called SSID
char ssid[] = "iPhone";
// your network password
char password[] = "123456789";
// your network key Index number (needed only for WEP)
int keyIndex = 0;

WiFiServer server(3000);

void setup() {
Serial.begin(115200);      // initialize serial communication
analogReference(EXTERNAL);
pinMode(RED_LED, OUTPUT);      // set the LED pin mode

// attempt to connect to Wifi network:
Serial.print("Attempting to connect to Network named: ");
// print the network name (SSID);
Serial.println(ssid); 
// Connect to WPA/WPA2 network. Change this line if using open or WEP      
network:
WiFi.begin(ssid, password);
while ( WiFi.status() != WL_CONNECTED) {
// print dots while we wait to connect
Serial.print(".");
delay(300);
 }

 Serial.println("\nYou're connected to the network");
 Serial.println("Waiting for an ip address");

  while (WiFi.localIP() == INADDR_NONE) {
 // print dots while we wait for an ip addresss
 Serial.print(".");
 delay(300);
  }

  // you're connected now, so print out the status  
   printWifiStatus();

  Serial.println("Starting dataerver on port 3000");
  server.begin();                           // start the web server on port        
  80
  Serial.println("Dataserver started!");

  }


void loop() {
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
  uint8_t i;
float average;
// take N samples in a row, with a slight delay
for (i=0; i< NUMSAMPLES; i++) {
samples[i] = analogRead(RUBBERPIN);
delay(10);
}
// average all the samples out
average = 0;
for (i=0; i< NUMSAMPLES; i++) {
average += samples[i];
}
average /= NUMSAMPLES;
Serial.println(average);

  client.println(average);
  delay(10);
}
delay(1);
// close the connection:
client.stop();
Serial.println("client disonnected");
 }
}


void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("Network Name: ");
Serial.println(WiFi.SSID());

// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
  }

运行此程序后,它会生成IP地址和传感器的值(

221.40

221.20

221.20

********* here =缺少值,图表上可见噪音

221.00

221.20

221.40

221.00

221.20

221.40

221.00

221.40

221.20

221.40

221.20

221.00

221.00

221.60

221.00

221.20

********* here =缺少值,图表上可见噪音

221.20

221.00

现在,

我将生成的IP地址写入客户端程序(在工具中名为processing.org)

这是我的客户代码

import processing.net.*;

Client c;
String input;
int data[];
int posx;
void setup() 
{
size(1000, 500);
background(204);
stroke(0);
frameRate(5); // Slow it down a little
// Connect to the server's IP address and port
c = new Client(this, "192.168.23.2", 3000); // Replace with your server's IP    
      and port
posx =2;
data = new int[3];
}

void draw() 
{
posx++;  

// Receive data from server
if (c.available() > 0) {
input = c.readString();
input = input.substring(0, input.indexOf("\n")); // Only up to the newline
println(input);
data[0]=data[1];

data[1] = int(input); // Split values into an array

// Draw line using received coords
stroke(0);
line(posx-1, data[0]+10, posx, data[1]+10);

  }
 }

运行以下程序后的结果:

服务器发送数据和客户端无线接收数据 - 一切正常 我能够看到我期待的输出信号。即,当我的传感器处于静止位置时,输出必须是直线,如果我拉伸我的传感器,电压信号必须增加 - 我能够看到所有这些。但是,

这是一个小问题

输出信号出现噪音(请查看下图。) Noise

所以我的问题是即使传感器处于静止位置 - 没有任何拉伸 - 出现峰值。

请帮帮我

0 个答案:

没有答案