连接Arduino以太网盾并读取数据问题PROCESSING
我是新来的这个论坛和处理整个事情。 我有一个具体的问题要问,并且非常感谢您的时间和想法!连接Arduino以太网盾并读取数据问题PROCESSING
如何将我的Arduino与Ethernet Shield连接起来,从传感器获取温度值,以便将它们看作是处理脚本? 在一个直接的Arduino脚本中,人们可以获得该值,从以太网屏蔽层连接到服务器并执行所喜欢的任务。我已经完成了。
在我的情况下,我希望Arduino只运行从传感器读取模拟输入值的脚本。 这可能吗?
我已经使串行连接工作,并通过USB读取值,但以太网屏蔽?我怎样才能得到的价值,arduino读取没有USB /串行连接?
ps。我使用WAMP服务器等,Windows 7的
我想两者的Arduino和处理来自http://arduino.cc/en/Tutorial/UDPSendReceiveString UDP连接的脚本示例,但
1)我不知道这是什么,我需要,
2)我已经排除防火墙端口6000,8888我的测试,并在Arduino的脚本已经把我的Arduino的IP地址和“本地主机”,在处理脚本
的代码复制用于更好地利用这里
/*
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: [email protected] 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();
}
伟大的计划。只有一个问题。它在我的系统上完美运行。我用Arduino草图加载了我的Arudino Uno R3,并加载了Processing草图。像魅力一样工作,先试试。没有改变我的Arduino,Windows系统,处理(2.0.3),网络等的任何东西。
可能是你有一个Arduino板问题(不太可能)或以太网盾问题(可悲,更可能)。你可能有网络问题(更可能)。
尝试Wireshark。直到看看Wireshark输出,你才会猜测。请注意,Wireshark具有过滤器。你将需要他们。过滤掉所有非UDP流量。
将这些值读入文件并使用该文件将数据发送到处理。 http://py.processing.org/reference/createReader.html
尽管这个链接可能回答这个问题,但最好在这里包含答案的基本部分,并提供参考链接。如果链接页面更改,则仅链接答案可能会失效。 – PKirby 2015-08-24 13:58:17
这不是直接回答你的问题,但是你能否请你先与USB /串口连接进行原型设计,以确保你可以首先发送和接收/组织信息?有一个内置的Arduino库,应该可以帮助你... – 2013-04-26 15:19:28
谢谢你的回复jesses, ,但正如我已经指出的,串行连接就好,一切都按预期工作。 ps。你能否指定你的原型是什么意思? – ODstuck 2013-04-27 02:34:27