简体   繁体   English

连接Arduino Ethernet Shield并读取数据问题处理

[英]Connecting Arduino Ethernet Shield and reading data issue PROCESSING

i am new to this forum and the whole thing with Processing. 我是这个论坛的新手,也是处理过程的新手。 I have a specific question to ask and thanks a lot for your time and thoughts! 我有一个特定的问题要问,非常感谢您的时间和想法!

How can i connect my Arduino with Ethernet Shield, getting temperature values from a sensor so they can be seen to a processing script? 如何将Arduino与Ethernet Shield连接起来,如何从传感器获取温度值,以便可以在处理脚本中看到它们? In a straight Arduino script, one gets the value, connects from the ethernet shield to a server and does what one likes. 在一个简单的Arduino脚本中,人们获得了价值,将其从以太网屏蔽连接到服务器,然后按照自己的喜好进行操作。 I have accomplished that. 我已经做到了。

In my case i want Arduino to just run the script of reading an analog input value from the sensor. 在我的情况下,我希望Arduino仅运行从传感器读取模拟输入值的脚本。 Is it possible? 可能吗?

I have made the serial connection work and read the values alright through the usb, but with ethernet shield? 我已经完成了串行连接,并可以通过USB读取值,但是带有以太网屏蔽? How can i get the value that arduino reads WITHOUT USB/Serial connection? 我如何在没有USB /串行连接的情况下获得arduino读取的值

ps. ps。 i am using WAMP server etc, Windows 7 我正在使用WAMP服务器等Windows 7

I am trying the UDP connection script example for both arduino and processing from http://arduino.cc/en/Tutorial/UDPSendReceiveString , but 我正在尝试arduino和从http://arduino.cc/en/Tutorial/UDPSendReceiveString处理的UDP连接脚本示例,但是

1)i ain't sure if that's what i need, 1)我不确定这是否是我需要的,

2)i have excluded from firewall ports 6000, 8888 for my tests and have put the IP address of my Arduino at the Arduino script and "localhost" at the Processing script 2)我已经从防火墙端口6000、8888中排除了我的测试,并将我Arduino的IP地址放在Arduino脚本中,将“ localhost”放在处理脚本中

THE CODE COPIED FOR BETTER USE HERE 此处复制以供更好使用的代码

/*
  UDPSendReceive.pde:
 This sketch receives UDP message strings, prints them to the serial port
 and sends an "acknowledge" string back to the sender

 A Processing sketch is included at the end of file that can be used to send
 and received messages for testing with a computer.

 created 21 Aug 2010
 by Michael Margolis

 This code is in the public domain.
 */


#include <SPI.h>         // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h>         // UDP library from: bjoern@cs.stanford.edu 12/30/2008


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 1, 177);

unsigned int localPort = 8888;      // local port to listen on

// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
char  ReplyBuffer[] = "acknowledged";       // a string to send back

// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;

void setup() {
  // start the Ethernet and UDP:
  Ethernet.begin(mac,ip);
  Udp.begin(localPort);

  Serial.begin(9600);
}

void loop() {
  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();
  if(packetSize)
  {
    Serial.print("Received packet of size ");
    Serial.println(packetSize);
    Serial.print("From ");
    IPAddress remote = Udp.remoteIP();
    for (int i =0; i < 4; i++)
    {
      Serial.print(remote[i], DEC);
      if (i < 3)
      {
        Serial.print(".");
      }
    }
    Serial.print(", port ");
    Serial.println(Udp.remotePort());

    // read the packet into packetBufffer
    Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
    Serial.println("Contents:");
    Serial.println(packetBuffer);

    // send a reply, to the IP address and port that sent us the packet we received
    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write(ReplyBuffer);
    Udp.endPacket();
  }
  delay(10);
}


/*
  Processing sketch to run with this example
 =====================================================

 // Processing UDP example to send and receive string data from Arduino
 // press any key to send the "Hello Arduino" message
 */

 import hypermedia.net.*;

 UDP udp;  // define the UDP object


 void setup() {
 udp = new UDP( this, 6000 );  // create a new datagram connection on port 6000
 //udp.log( true );         // <-- printout the connection activity
 udp.listen( true );           // and wait for incoming message  
 }

 void draw()
 {
 }

 void keyPressed() {
 String ip       = "192.168.1.177"; // the remote IP address
 int port        = 8888;        // the destination port

 udp.send("Hello World", ip, port );   // the message to send

 }

 void receive( byte[] data ) {          // <-- default handler
 //void receive( byte[] data, String ip, int port ) {   // <-- extended handler

 for(int i=0; i < data.length; i++)
 print(char(data[i]));  
 println();  
 }

Read those values into a file and use that file to send data to processing. 将这些值读入文件,然后使用该文件将数据发送到处理中。 http://py.processing.org/reference/createReader.html http://py.processing.org/reference/createReader.html

Great scheme. 伟大的计划。 Only one problem. 只有一个问题。 It works perfectly on my system. 它在我的系统上完美运行。 I loaded my Arudino Uno R3 with your Arduino sketch and loaded the Processing sketch as well. 我用您的Arduino草图加载了Arudino Uno R3,还加载了Processing草图。 Worked like a charm, first try. 像魅力一样工作,首先尝试。 Didn't change anything on my Arduino, Windows system, Processing (2.0.3), network, etc. 在我的Arduino,Windows系统,Processing(2.0.3),网络等上没有任何更改。

Could be you have a Arduino board problem (unlikely) or an Ethernet shield problem (sadly, more likely). 您可能是Arduino板问题(不太可能)或以太网屏蔽问题(可悲的是,可能性更大)。 You could have a network problem (even more likely). 您可能有网络问题(甚至更有可能)。

Try Wireshark. 尝试Wireshark。 You will really just be guessing until you take a look at the Wireshark output. 在查看Wireshark输出之前,您实际上只是在猜测。 Note that Wireshark has filters. 请注意,Wireshark具有过滤器。 You will need them. 您将需要它们。 Filter out all of the non-UDP traffic. 过滤掉所有非UDP流量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM