02-21-2023 02:15 PM
Hi Folks,
Objective: Read Distance measurement data off Wiznet 5500 EVB Pico via TCP/IP
Protocol: TCP/IP
Pico IP: 10.10.10.112
Port: 23
Application Summary: I am using a Wiznet 5500 EVB Pico to read distance measurement off a Mitutoyo digital scale, and have the data send to the local network. I am able to read the data via the network utilizing the YAT terminal software using the TCP/IP Client. I am not sending any command to get the data stream, rather i am simply opening the port to get the data. I tried doing this functionality with LabVIEW and haven't had any luck so far. I have attached all the vi's I have tried; the Pico sketch and pictures of the YAT terminal being used to view the data.
The "TCP Monitor" vi is more of what i was experimenting with to get some results, and the "TCP monitor Type 2" vi is the LabVIEW TCP client example vi modified for the IP and port i am using in this application. Tried attaching the sketch couple of times and don't seem to work so had to put it here.
PICO Sketch
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0xA3, 0x12};
IPAddress ip(10, 10, 10, 112);
byte subnet[] = {255, 255, 255, 0};
EthernetServer server(23);
EthernetClient clients[8];
int req = 5; // mic REQ line goes to pin 5 through q1 (Arduino high pulls request line low)
int dat = 2; // mic Data line goes to pin 2
int clk = 3; // mic Clock line goes to pin 3
int i = 0;
int j = 0;
int k = 0;
int signCh = 8;
int sign = 0;
int decimal;
float dpp;
int units;
byte mydata[14];
String value_str;
long value_int; // was an int, could not measure over 32mm
float value;
void setup()
{
Ethernet.init(17); // WIZnet W5100S-EVB-Pico W5500-EVB-Pico
Serial.begin(9600);
pinMode(req, OUTPUT);
pinMode(clk, INPUT_PULLUP);
pinMode(dat, INPUT_PULLUP);
pinMode(20, OUTPUT);
digitalWrite(20, HIGH); // change
digitalWrite(req, LOW); // set request at high
Ethernet.begin(mac, ip, subnet);
server.begin();
delay(100);
}
void update_value()
{
digitalWrite(req, HIGH); // generate set request
for (i = 0; i < 13; i++)
{
k = 0;
for (j = 0; j < 4; j++)
{
while (digitalRead(clk) == LOW)
{
} // hold until clock is high
while (digitalRead(clk) == HIGH)
{
} // hold until clock is low
bitWrite(k, j, (digitalRead(dat) & 0x1));
}
mydata[i] = k;
}
sign = mydata[4];
value_str = String(mydata[5]) + String(mydata[6]) + String(mydata[7]) + String(mydata[8] + String(mydata[9] + String(mydata[10])));
decimal = mydata[11];
units = mydata[12];
value_int = value_str.toInt();
if (decimal == 0)
dpp = 1.0;
if (decimal == 1)
dpp = 10.0;
if (decimal == 2)
dpp = 100.0;
if (decimal == 3)
dpp = 1000.0;
if (decimal == 4)
dpp = 10000.0;
if (decimal == 5)
dpp = 100000.0;
value = value_int / dpp;
digitalWrite(req, LOW);
}
void loop()
{
// check for any new client connecting, and say hello (before any incoming data)
EthernetClient client = server.accept();
if (client)
{
for (byte i = 0; i < 8; i++)
{
if (!clients[i])
{
Serial.print("We have a new client #");
Serial.print(i);
Serial.print(" from IP ");
Serial.println(client.remoteIP());
// Once we "accept", the client is no longer tracked by EthernetServer
// so we must store it into our list of clients
clients[i] = client;
break;
}
}
}
update_value();
String strToSend = "";
if (sign == 😎
{
strToSend = "-";
}
strToSend += String(value, decimal);
// write to serial
Serial.println(strToSend);
// write to all connected clients
for (byte j = 0; j < 8; j++)
{
if (clients[j] && clients[j].connected())
{
clients[j].println(strToSend);
}
}
// stop any clients have disconnected from us
// (we never disconnect anyone from our side)
for (byte i = 0; i < 8; i++)
{
if (clients[i] && !clients[i].connected())
{
Serial.print("disconnect client #");
Serial.println(i);
clients[i].stop();
}
}
delay(100);
}
Solved! Go to Solution.
02-24-2023 08:12 AM
I figured the solution to my problem. It's pretty much what i tried before, and it seem to work for me now. I am attaching the working Vi solution to my problem.
Cheers!!