Skip to Content
Dan k
Chen
ATWINC1500 to ATWINC1500
Explorations Dan Chen / December 30, 2016

 

Look up your IP addresses

Some routers allows you to assign static IP address via the admin page. You will need to provide the router with the MAC address, so it will dedicate an assigned IP address to a MAC address every time when the connection has been established.

Label the IP address somewhere, after you lookup the IP address from either the router or the serial monitor.

 

Download the code

Download WiFiUdpRXTX_neopixel.ino
After you download the code make sure you

Change the IP Address 
Udp.beginPacket(“192.168.13.3”, 2390);
Your router will most likely change the IP address, unless you assign the IP address ti the MAC address of your ATWINC1500

Change SSID and Password
Make sure your ATWINC1500 is able to connect to the router.
The green light indicates that the connection has been established
Check the sample code for ATWINC1500 for WEP/WEP2 connections

Change your input and output
In my example, I used the potentiometer as input, then map the value for NEO-Pixel as output
You might want to adjust the input and output method and wiring for your application.
Lastly, make sure you use the serial monitor to see the TX and RX write out, make sure what you are sending is what the other device is receiving.

 

What’s in the code

Receiving Buffer

 

Get the Buffer and Buffer Size
int len = Udp.read(packetBuffer, 255);
if (len > 0) packetBuffer[len] = 0;
Serial.print(“RX: “);

Convert to String
String snum;
for (int c = 0; c < len ; c++) {
char k = packetBuffer[c];
snum = snum + k;
}

Convert String to Int
int num = snum.toInt();

 

Send Data via UDP

 

messageSender();

Receiver’s IP address and Port
Udp.beginPacket(“192.168.13.3”, 2390);

Append Data as String

//String stringOne = “Data: “;  // incase you wanna pass char with the value
String stringOne;
stringOne += senVal;

char charBuf[5];
stringOne.toCharArray(charBuf, 5);

Udp.write(charBuf);
Udp.endPacket();

delay(100); // add a little delay, you don’t wanna send to fast, the ATWINC1500 is fast but not that fast

 

/*
  WiFi UDP Send and Receive String

  This sketch wait an UDP packet on localPort using a WiFi shield.
  When a packet is received an Acknowledge packet is sent to the client on port remotePort

  Circuit:
   WiFi shield attached

  created 30 December 2012
  by dlf (Metodo2 srl) + Dan Chen

*/
#include 
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, A2, NEO_GRB + NEO_KHZ800);


#include 
#include 
#include 

// Define the WINC1500 board connections below.
// If you're following the Adafruit WINC1500 board
// guide you don't need to modify these:
#define WINC_CS   8
#define WINC_IRQ  7
#define WINC_RST  4
#define WINC_EN   2     // or, tie EN to VCC and comment this out
// The SPI pins of the WINC1500 (SCK, MOSI, MISO) should be
// connected to the hardware SPI port of the Arduino.
// On an Uno or compatible these are SCK = #13, MISO = #12, MOSI = #11.
// On an Arduino Zero use the 6-pin ICSP header, see:
//   https://www.arduino.cc/en/Reference/SPI

// Setup the WINC1500 connection with the pins above and the default hardware SPI.
Adafruit_WINC1500 WiFi(WINC_CS, WINC_IRQ, WINC_RST);

// Or just use hardware SPI (SCK/MOSI/MISO) and defaults, SS -> #10, INT -> #7, RST -> #5, EN -> 3-5V
//Adafruit_WINC1500 WiFi;
int counter = 1;
int presenVal = 0;
int status = WL_IDLE_STATUS;
char ssid[] = "SkyNet";  //  your network SSID (name)
char pass[] = "2038435600";       // your network password
int keyIndex = 0;            // your network key Index number (needed only for WEP)

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

char packetBuffer[255]; //buffer to hold incoming packet
char  ReplyBuffer[] = "acknowledged";       // a string to send back

Adafruit_WINC1500UDP Udp;


int senPin = A1;
int senVal = 0;



void setup() {
  pixels.begin();

#ifdef WINC_EN
  pinMode(WINC_EN, OUTPUT);
  digitalWrite(WINC_EN, HIGH);
#endif

  //Initialize serial and wait for port to open:
  Serial.begin(9600);


  /*
    while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
    }
  */

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(5000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();

  Serial.println("\nStarting connection to server...");
  // if you get a connection, report back via serial:
  Udp.begin(localPort);
}

void loop() {

  // if there's data available, read a packet
  int packetSize = Udp.parsePacket();





  if (packetSize)
  {

    int len = Udp.read(packetBuffer, 255);
    if (len > 0) packetBuffer[len] = 0;
    Serial.print("RX: ");
    //Serial.println(packetBuffer);

    String snum;
    for (int c = 0; c < len ; c++) { char k = packetBuffer[c]; snum = snum + k; } int num = snum.toInt(); //Serial.print("Pack: "); //Serial.print(packetBuffer); //Serial.print(" String: "); Serial.println(num); pixels.setPixelColor(0, Wheel(( num ) & 255)); pixels.show(); //delay(20); } messageSender(); } void messageSender() { senVal = analogRead(senPin); senVal = map(senVal, 0, 1024, 0, 255); int diff = abs(presenVal - senVal); //Serial.print("diff: "); //Serial.println(diff, DEC); if ( diff > 3) { // send the data also mute some noise


    Serial.print("TX: ");
    Serial.println(senVal, DEC);

    //Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    // Computer or Iphone's IP address and Port

    // Make sure that you enter the IP address of the recever
    // sending seneor data to the other device
    Udp.beginPacket("192.168.13.3", 2390);
    //Udp.beginPacket("192.168.13.2", 2390);

    //String stringOne = "Data: ";
    String stringOne;
    stringOne += senVal;

    char charBuf[5];
    stringOne.toCharArray(charBuf, 5);

    Udp.write(charBuf);

    //Udp.write(ReplyBuffer);
    Udp.endPacket();

  }

  delay(100);


  presenVal = senVal;









}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  /*
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  */
}



uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if (WheelPos < 170) {
    WheelPos -= 85;
    return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

Take it Public

DDNS port forwarding

User your router’s admin page to config your DDNS and ports to forward..

 

Port Mapping on Mac

If you are using DDNS service on your router for port forwarding, then you don’t need this.

This is Port Forwarding on your mac,

#1 Downloaded the app port forwarding wizard for free on the app store

screen-shot-2016-11-16-at-8-07-28-am

#2 Add your 3d printer camera to the list but clicking the Add.

Enter the internal ip address
The port number in our case is 2390
Protocol is UDP

#4 Look up your public IP address (public IP address)

 

You can figure out your public IP  by googling “what is my ip”

Now you can live stream your printer video anywhere in the world as long as the program is running or you have the DDNS setup.

screen-shot-2016-11-16-at-8-11-55-am

 

DAN K CHEN © 2024