Dana Mah
Created June 27, 2018 © GPL3+

TCP debug port

My project will allow you to use your current serial debug statements over an Ethernet network.

Beginner30 minutes81
TCP debug port

Things used in this project

Story

Read more

Schematics

Demo Setup

This is the setup for the demo circuit.

Code

monitor.java

Java
This code will make a connection to the WizNet750sr. I will output any data that was sent to it to the screen.
import java.io.*;
import java.net.*;

class monitor{
 

  public static void main(String argv[]) throws Exception {
    Socket clientSocket = new Socket("192.168.11.2", 5000);
    InputStream is = clientSocket.getInputStream();
    byte[] buffer = new byte[1024];
    int read;
    while((read = is.read(buffer)) != -1) {
      String output = new String(buffer, 0, read);
      System.out.print(output);
      System.out.flush();      
    };
    clientSocket.close(); 
  }
} 

Sensor code

Arduino
For the purpose of this project, I created this demo code that will count from 1 to 100 and send the output out to a software serial port. It will also read the the software serial port (expecting an inputted number) to set the maximum count, ie, if you send in 1000 it will now count from 1 to 1000.
#include <SoftwareSerial.h>

#define resetPin 3

int sensorValue = 0;
int maxValue = 100;

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  Serial.println("USB Conected");
  
  mySerial.begin(115200);
  while (!mySerial);
  pinMode (resetPin,OUTPUT);
  digitalWrite(resetPin,HIGH); 
  mySerial.println("Wiz750sr Connected"); 
}

void loop() {
    mySerial.println(sensorValue);
    sensorValue++;
    if (sensorValue == maxValue)
      sensorValue =0;
    delay(1);
    //Check to see if any data was sent to the sensor.
    if (mySerial.available()) {
      int i;
      char c;
      char readData[100];          
        while (i<100 && mySerial.available()){ 
          c=mySerial.read();
          readData[i]=c;
          i++;
        }
        readData[i]=0; 
        Serial.println("Read TXT:" + String(readData));
        //Do something with the data, in this case we will set the maxValue to the input data.
        //Some error checking needs to be done here 
        maxValue = String(readData).toInt();
        //because this is just a demo, we will take the data read and send it out the USB serial port to the arduino serial monitor.  
        Serial.println("maxvalue:" + maxValue);
        Serial.println(maxValue);
        Serial.flush();
   }
}

Credits

Dana Mah

Dana Mah

12 projects • 27 followers
I'm a hobbyist interested in microcontroller solutions to simple problems.

Comments