0

我是这个论坛的新手,也是 Processing 的新手。我有一个具体的问题要问,非常感谢您的时间和想法!

如何将我的 Arduino 与 Ethernet Shield 连接,从传感器获取温度值,以便处理脚本可以看到它们?在直接的 Arduino 脚本中,获取值,从以太网屏蔽连接到服务器并做自己喜欢的事情。我已经做到了。

就我而言,我希望 Arduino 只运行从传感器读取模拟输入值的脚本。可能吗?

我已经使串行连接工作并通过 USB 读取值,但是使用以太网屏蔽?如何在没有 USB/串行连接的情况下获得 arduino 读取的值?

附言。我正在使用 WAMP 服务器等,Windows 7

我正在为 arduino 和http://arduino.cc/en/Tutorial/UDPSendReceiveString的处理尝试 UDP 连接脚本示例,但是

1)我不确定这是否是我需要的,

2)我已从防火墙端口 6000、8888 中排除我的测试,并将我的 Arduino 的 IP 地址放在 Arduino 脚本中,并将“localhost”放在处理脚本中

为了更好地使用这里复制的代码

/*
  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();  
 }
4

2 回答 2

1

将这些值读入文件并使用该文件将数据发送到处理。http://py.processing.org/reference/createReader.html

于 2015-08-24T13:54:22.483 回答
0

很棒的计划。只有一个问题。它在我的系统上完美运行。我用你的 Arduino 草图加载了我的 Arudino Uno R3 并加载了处理草图。像魅力一样工作,第一次尝试。没有改变我的 Arduino、Windows 系统、Processing (2.0.3)、网络等上的任何东西。

可能是您有 Arduino 板问题(不太可能)或以太网屏蔽问题(可悲的是,更有可能)。您可能遇到网络问题(更有可能)。

试试 Wireshark。在您查看 Wireshark 输出之前,您实际上只是在猜测。请注意,Wireshark 具有过滤器。你会需要它们。过滤掉所有非 UDP 流量。

于 2013-11-06T16:27:44.897 回答