Announcement

Collapse
No announcement yet.

Arduino - Web Server - Remote Pad

Collapse
X
Collapse
  •  

  • Arduino - Web Server - Remote Pad

    Web Remote Pad is one of the built-in embedded web apps in PHPoC [WiFi] Shield.

    When an user clicks or touches on touchable area of this web app, the web app sends x, y coordinates and touch's state to Arduino via WebSocket.

    This tutorial shows how to use Web Remote Pad to control Arduino.



    Hardware Required
    Note that: This web app is available on:
    • PHPoC [WiFi] Shield R2
    • PHPoC [WiFi] Shield R1 with upgrade firmware to v1.5.0 (or higher)




    Circuit
    • Stack PHPoC Shield or PHPoC WiFi Shield on Arduino Uno or Mega

    Note that: Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT be used for general I/O.

    How Web Remote Pad Works

    Web Remote Pad is a web apps that is stored on PHPoC [WiFi] Shield.

    When an user access this web app via a web browser, web apps is displayed on web browser.

    When the user clicks "Connect" button on this web app, a WebSocket connection is created between web app and Arduino.

    When the user clicks or touches on touchable area of web app, web app sends a string to Arduino via WebSocket connection.
    The string includes x, y coordinates (in pixel) and touch's state in order (separated by comma).
    The string is terminated by a carriage return and a newline characters.

    Coordinates



    Install Arduino IDE

    If you have not install Arduino IDE yet, please download and install Arduino IDE .




    Install Library
    • Run Arduino IDE.
    • Navigate to Sketch > Include Library > Manage Libraries

    • Search "Phpoc" on search bar of the Library Manager.

    • Select the PHPoC library and press the [Install] button.

    • Restart Arduino IDE for the next step.


    Setup Network Information
    This part is needed only for the first use.

    1. If Ethernet is used
    In case of using PHPoC Shield (P4S-348), you have two options to connect to network: Ethernet or WiFi.
    If using Ethernet, please follow this instruction to connect the shield to Ethernet.


    2. If WiFi is used
    WiFi is available in both P4S-347 and P4S-348. Please follow:

    Source Code
    • Open "WebRemotePad" example on Arduino IDE

      Code:
      	// Arduino Web Server - Remote Control (Touch Pad)
      	//
      	// PHPoC Shield and PHPoC WiFi Shield are Internet Shields for Arduino Uno and
      	// Mega.
      	// These Shields have the buit-in web server and WebSocket server. These Shields
      	// contain some buit-in embedded web apps. One of the buit-in embedded web apps
      	// is "Web Remote Pad". When an user clicks or touches on touchable area of this
      	// web app, the web app sends x, y coordinates and touch's state to Arduino via
      	// WebSocket.
      	//
      	// This example code shows how Arduino communicate with "Web Remote Pad".
      	//
      	// Arduino communicates with PHPoC [WiFi] Shield via pins 10, 11, 12 and 13 on
      	// the Uno, and pins 10, 50, 51 and 52 on the Mega. Therefore, these pins CANNOT
      	// be used for general I/O.
      	//
      	// This example code was written by Sollae Systems. It is released into the
      	// public domain.
      	//
      	// Tutorial for the example is available here:
      	// https://forum.phpoc.com/articles/tutorials/1247-arduino-web-server-remote-pad
      
      	#include <Phpoc.h>
      
      	PhpocServer server(80);
      
      	char touch_state;
      	int touch_x;
      	int touch_y;
      
      	void setup() {
      	  Serial.begin(9600);
      	  while(!Serial)
      	    ;
      
      	  // initialize PHPoC [WiFi] Shield:
      	  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
      	  //Phpoc.begin();
      
      	  // start WebSocket server
      	  server.beginWebSocket("remote_pad");
      
      	  // print IP address of PHPoC [WiFi] Shield to serial monitor:
      	  Serial.print("WebSocket server address : ");
      	  Serial.println(Phpoc.localIP());
      	}
      
      	void loop() {
      	  // wait for a new client:
      	  PhpocClient client = server.available();
      
      	  if (client) {
      	    // read a string that is terminated by a carriage return and a newline
      	    // characters:
      	    String touchStr = client.readLine();
      
      	    if(touchStr) {
      	      // when an user clicks or touches on touchable area of web app, web app
      	      // sends a string to Arduino. The string includes x, y coordinates and
      	      // touch's state in order (separated by comma). The string is terminated
      	      // by a carriage return and a newline characters.
      	      int commaPos1 = touchStr.indexOf(',');
      	      int commaPos2 = touchStr.lastIndexOf(',');
      
      	      touch_x = touchStr.substring(0, commaPos1).toInt();
      	      touch_y = touchStr.substring(commaPos1 + 1, commaPos2).toInt();
      	      touch_state = touchStr.charAt(commaPos2 + 1);
      
      	      // touch's state is a character. The possible values of touch's state are
      	      // 'S', 'M' and 'U', standing for "touch start", "touch move" and "touch
      	      // end", respectively.
      	      if(touch_state == 'S')
      	        Serial.print("Touch start at: ");
      	      else
      	      if(touch_state == 'M')
      	        Serial.print("Touch move to: ");
      	      else
      	      if(touch_state == 'U')
      	        Serial.print("Touch end at: ");
      
      	      Serial.print(touch_x);
      	      Serial.print(", ");
      	      Serial.println(touch_y);
      	    }
      	  }
      	}
    • The line-by-line explaination of code is presented inside the code.
      For more detail of functions's reference, please refer to PHPoC Shield for Arduino Library Reference
    • Compile the example code and upload to Arduino by clicking "Upload" button on Arduino IDE



    Test and Result
    • Open Serial Monitor of Arduino IDE.
    • Copy the IP address of the shield and keep the Serial Monitor windows open.
    • Open a web browser from PC, smartphone or tablet.
    • Paste IP address of PHPoC [WiFi] Shield on address bar.
    • Web browser shows web page that displays the list of web app.
    • Click Web Remote Pad icon. (You can also access directy by typing: ip_address/remote_pad.php).
    • Click "Connect" button.
    • Click/touch and move mouse/your figure on touch area of Web Remote Pad, and then release.
    • See log on Serial Monitor

      As we can see, state and coordinates of touch sent to Arduino each time the touch changes.



    Web Customization

    The web app has been created and preload to PHPoC [WiFi] Shield. User does not need to write the web code. User just needs to write Arduino code based on the Arduino example. However, user can modify user interface of web app via a setting page.

    Custommable Parameters:
    • Width: settable value. Width of the pad area.
    • Height: settable value. Height of the pad area.


    How To
    • Click "Setup" on Web App
    • It shows setup page. The below is default setting.
    • Change setting parameters as you want.



    See Also


    References
      Posting comments is disabled.

    Categories

    Collapse

    Latest Articles

    Collapse

    • Arduino - RS-485 Expansion Board
      by support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 03:45 PM
    • Arduino - RS-422 Expansion Board
      by support
      PES-2607 is an easy-to-use RS422/RS485 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS422 or RS485.
      Especially, Arduino does NOT use UART pins to communicate with RS422/RS485 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS422/RS485 expansion boards (up to 14) without using Arduino UART pins.

      Library and examples for...
      11-13-2018, 03:44 PM
    • Arduino - RS-232 Expansion Board
      by support
      PES-2606 is an easy-to-use RS-232 Expansion Board for Arduino Uno and Mega, which allows Arduino to exchange data with serial device via RS-232.
      Especially, Arduino does NOT use UART pins to communicate with RS-232 expansion board. Therefore, users can use Arduino UART pins for other purposes.
      Moreover, A single Arduino Uno/Mega can communicate with multiple RS-232 expansion boards (up to 14) without using Arduino UART pins.

      Library and example for the RS-232 expansion board...
      11-13-2018, 03:43 PM
    • Arduino - Stepper Motor Controller
      by support
      PES-2605 is an easy-to-use stepper motor controller for Arduino Uno and Mega, which uses micro-stepping method to precisely control stepper motor.
      Library and example for the stepper motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the step motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 03:41 PM
    • Arduino - DC Motor Controller
      by support
      PES-2604 is an easy-to-use DC motor controller for Arduino Uno and Mega.
      Library and example for the DC motor controller are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use the DC motor controller with an example of PhpocExpansion library for Arduino.


      Hardware Required...
      11-13-2018, 03:40 PM
    • Arduino - Digital Input Board
      by support
      PES-2602 is an easy-to-use 4-port Input Expansion Board for Arduino Uno and Mega, which allows Arduino to monitor state of DC electric device. In addition, it can monitor NPN, PNP and dry contact(relay).
      Library and example for the 4-port input expansion board are part of of PhpocExpansion library for Arduino. The library reference is available here.

      This tutorial shows how to use 4-port input expansion board with an example of PhpocExpansion library for Arduino.

      ...
      11-13-2018, 03:39 PM
    Working...
    X