STONE HMI + ESP8266EX + Intelligent Display Terminal of Wifi PC Application Synchronization Display
by greyli1987 in Circuits > Electronics
520 Views, 1 Favorites, 0 Comments
STONE HMI + ESP8266EX + Intelligent Display Terminal of Wifi PC Application Synchronization Display
Hardware used in the project
1. STONE TFT LCD MODULE STVC070WT-01
2. ESP8266EX
3. WIFI module BC2310
STONE TFT LCD MODULE STVC070WT-01
STVC070WT-01 is a 7-inch HMI display module, which has 128M built-in storage space and can communicate with external via RS485/RS232. The official development STONE TOOLBOX (Free GUI Design software) is also provided to speed up the development process. The system also uses the Wifi module BC2310 and a simple Windows PC desktop program to achieve data interoperability between PC and screen.
System Design
STVC070WT-01 is an intelligent display terminal from Beijing STONE Technology Co., Ltd. with a Cortex-M4 processor and 128M storage space. Any visual material and interface switching logic can be written into this display terminal in advance. And it can communicate with the outside through a serial port. Here we write the interface elements and interface switching logic directly into STVC070WT-01, and then reserve the serial commands to the outside so that we can communicate with the PC application through the Wifi module.
STVC070WT-01 Development
This program uses one variable storage space 0x1251 to store the light display brightness (corresponding data: 1 and 0). Details of TOOL development can be found in the above document and will not be repeated here.
After the GUI interface is designed and developed by using TOOL, we connect the computer to the STVC070WT-01 via the USB cable. After connecting it the screen will display the message "After download, please plug out USB mini". (as shown in the 1st picture)
Click the download button in the image below left to download our program into STVC070WT-01. The following right image is displayed after a successful download. (as shown in the 2nd and 3rd picture)
As shown in the figure below, click the switch button at the right bottom to change the brightness of the small light in the middle. (as shown in the 4th and 5th picture)
BC2310 Wifi Module Development
We use BeecomIoT's Wifi module BC2310, which is equipped with Espressif's ESP-WROOM-02 Wifi module, and modify its code so that it can read the registers that can be written to STVC070WT-01. (as shown in the 1st picture)
And lead the three wires of DIN, DOUT, and GND of the adapter cable and connect them to TX, RX, and GND of BC2310. (as shown in the 2nd picture)
The ESP-WROOM-02 chip module has external dimensions of (18.00±0.10) mm x (20.00±0.10) mm x (2.80±0.10) mm and is currently configured in an SOP 8 (150 mil) SPI Flash package with a 2 dBi PCB onboard antenna. (as shown in the 3rd picture)
ESP-WROOM-02 is embedded with ESP8266EX. ESP8266EX, developed by Espressif, provides a highly integrated Wi-Fi SoC solution with low power consumption, compact design, and high stability to meet users' needs.
The ESP8266EX has complete and self-contained Wi-Fi networking capabilities and can be used as a standalone application or as a slave running on another host MCUs. When the ESP8266EX is used standalone, it can boot directly from an external flflash. The built-in cache memory facilitates improved system performance and optimizes the storage system. In addition, the ESP8266EX can be used as a Wi-Fi adapter in any microcontroller-based design simply through the SPI/SDIO interface or UART interface.
The ESP8266EX integrates an antenna switch, RF balun, power amplifier, low-noise amplifier, filter, and power management module. This compact design requires very little external circuitry and minimizes PCB size.
The ESP8266EX also integrates an enhanced version of Tensilica's L106 Diamond Series 32-bit core processor with on-chip SRAM. The ESP8266EX can be externally connected to sensors and other devices via IO. A software development kit (SDK) provides sample code for some applications.
The leading features of the (ESCP-ESPRESSIF Systems' Smart Connectivity Platform) include:
- Quick switching between sleep/wake modes for energy savings
- Adaptive RF adjustment for low-power operation l Front end signal processing function
- Troubleshooting and RF co-existence mechanism eliminate cellular/Bluetooth/DDR/LVDS/LCD interference 1.1. Wi-Fi Key Features
- Support 802.11b/g/n l 802.11n (2.4GHz) with speeds up to 72.2Mbps
- Restructuring (defragmentation) l 2 x virtual Wi-Fi interface
- Beacon automatic monitoring (hardware TSF)
- Support Infrastructure BSS in Station mode/SOFTAP mode/hybrid mode
Note: When STVC070WT-01 was delivered from the factory, J17 of the back panel solder pad was connected together for the convenience of computer serial port communication, but this will lead to communication failure between it and the WiFi module, so it is necessary to ensure that it is disconnected here.
PC Application Development
PC Application Development
After the PC is connected to Wifi, it uses the official STONE serial communication protocol to synchronize the light on and off by reading and writing data from 0x1251 and STVC070WT-01. The PC desktop application is written in C# and uses Microsoft's development environment Visual Studio.
The core code of the PC application is as follows:
<p><em>using</em><em> System;</em></p><p><em>using</em><em> System.Collections.Generic;</em></p><p><em>using</em><em> System.ComponentModel;</em></p><p><em>using</em><em> System.Data;</em></p><p><em>using</em><em> System.Drawing;</em></p><p><em>using</em><em> System.Linq;</em></p><p><em>using</em><em> System.Net;</em></p><p><em>using</em><em> System.Net.Sockets;</em></p><p><em>using</em><em> System.Text;</em></p><p><em>using</em><em> System.Threading.Tasks;</em></p><p><em>using</em><em> System.Windows.Forms;</em></p><p><em>namespace</em><em> StoneBcLightWifi</em></p><p><em>{</em></p><p><em>public</em><em>partial</em><em>class</em><em>Form1</em><em> : Form</em></p><p><em> {</em></p><p><em>private</em><em>const</em><em>int</em><em> port = 8888;</em></p><p><em>bool</em><em> curLightState = </em><em>false</em><em>;</em></p><p><em>byte</em><em>[] recvBuf = </em><em>new</em><em>byte</em><em>[256];</em></p><p><em>int</em><em> recvBufIndex = 0;</em></p><p><em> Socket client;</em></p><p><em>private</em><em>bool</em><em> StartClient()</em></p><p><em> {</em></p><p><em>// Connect to a remote device. </em></p><p><em>try</em></p><p><em> {</em></p><p><em>// Establish the remote endpoint for the socket. </em></p><p><em>// The name of the</em></p><p><em>// remote device is "host.contoso.com". </em></p><p><em> IPAddress ipAddress = IPAddress.Parse(</em><em>"192.168.4.1"</em><em>);</em></p><p><em> IPEndPoint remoteEP = </em><em>new</em><em> IPEndPoint(ipAddress, port);</em></p><p><em>// Create a TCP/IP socket. </em></p><p><em> client = </em><em>new</em><em> Socket(ipAddress.AddressFamily,</em></p><p><em> SocketType.Stream, ProtocolType.Tcp);</em></p><p><em>// Connect to the remote endpoint. </em></p><p><em>try</em></p><p><em> {</em></p><p><em> client.Connect(remoteEP);</em></p><p><em> }</em></p><p><em>catch</em><em>(Exception e)</em></p><p><em> {</em></p><p><em> Console.WriteLine(e.ToString());</em></p><p><em>return</em><em>false</em><em>;</em></p><p><em> }</em></p><p><em> Receive(client);</em></p><p><em>// Release the socket. </em></p><p><em>// client.Shutdown(SocketShutdown.Both);</em></p><p><em>// client.Close();</em></p><p><em>return</em><em>true</em><em>;</em></p><p><em> }</em></p><p><em>catch</em><em> (Exception e)</em></p><p><em> {</em></p><p><em> Console.WriteLine(e.ToString());</em></p><p><em> }</em></p><p><em>return</em><em>false</em><em>;</em></p><p><em> }</em></p><p><em>private</em><em>void</em><em> Receive(Socket client)</em></p><p><em> {</em></p><p><em>try</em></p><p><em> {</em></p><p><em>// Create the state object. </em></p><p><em> StateObject state = </em><em>new</em><em> StateObject();</em></p><p><em> state.workSocket = client;</em></p><p><em>// Begin receiving the data from the remote device. </em></p><p><em> client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,</em></p><p><em>new</em><em> AsyncCallback(ReceiveCallback), state);</em></p><p><em> }</em></p><p><em>catch</em><em> (Exception e)</em></p><p><em> {</em></p><p><em> Console.WriteLine(e.ToString());</em></p><p><em> }</em></p><p><em> }</em></p><p><em>private</em><em>void</em><em> ReceiveCallback(IAsyncResult ar)</em></p><p><em> {</em></p><p><em>try</em></p><p><em> {</em></p><p><em>// Retrieve the state object and the client socket</em></p><p><em>// from the asynchronous state object. </em></p><p><em> StateObject state = (StateObject)ar.AsyncState;</em></p><p><em> Socket client = state.workSocket;</em></p><p><em>// Read data from the remote device. </em></p><p><em>int</em><em> bytesRead = client.EndReceive(ar);</em></p><p><em>if</em><em> (bytesRead > 0)</em></p><p><em> {</em></p><p><em>// There might be more data, so store the data received so far. </em></p><p><em>for</em><em>(</em><em>int</em><em> i = 0; i < bytesRead; i++)</em></p><p><em> {</em></p><p><em> recvBuf[recvBufIndex+i] = state.buffer[i];</em></p><p><em> }</em></p><p><em> recvBufIndex += bytesRead;</em></p><p><em>if</em><em> (recvBufIndex >= 16)</em></p><p><em> {</em></p><p><em>if</em><em> (recvBuf[8] == 0)</em></p><p><em> {</em></p><p><em> curLightState = </em><em>false</em><em>;</em></p><p><em> }</em></p><p><em>else</em></p><p><em> {</em></p><p><em> curLightState = </em><em>true</em><em>;</em></p><p><em> }</em></p><p><em> pictureBoxLight.Invoke(</em><em>new</em><em> EventHandler(</em><em>delegate</em></p><p><em> {</em></p><p><em> setLight(curLightState);</em></p><p><em> }));</em></p><p><em> recvBufIndex = 0;</em></p><p><em> }</em></p><p><em>// Get the rest of the data. </em></p><p><em> client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,</em></p><p><em>new</em><em> AsyncCallback(ReceiveCallback), state);</em></p><p><em> }</em></p><p><em>else</em></p><p><em> {</em></p><p><em>/**</em><em> set light </em><em>*/</em></p><p><em> Receive(client);</em></p><p><em>if</em><em>(recvBuf[9] == 0)</em></p><p><em> {</em></p><p><em> curLightState = </em><em>false</em><em>;</em></p><p><em> }</em></p><p><em>else</em></p><p><em> {</em></p><p><em> curLightState = </em><em>true</em><em>;</em></p><p><em> }</em></p><p><em> pictureBoxLight.Invoke(</em><em>new</em><em> EventHandler(</em><em>delegate</em></p><p><em> {</em></p><p><em> setLight(curLightState);</em></p><p><em> }));</em></p><p><em> recvBufIndex = 0;</em></p><p><em> }</em></p><p><em> }</em></p><p><em>catch</em><em> (Exception e)</em></p><p><em> {</em></p><p><em> Console.WriteLine(e.ToString());</em></p><p><em> textBoxLog.Invoke(</em><em>new</em><em> EventHandler(</em><em>delegate</em></p><p><em> {</em></p><p><em> textBoxLog.Text = </em><em>"Receive failed"</em><em>;</em></p><p><em> }));</em></p><p><em> }</em></p><p><em> }</em></p><p><em>public</em><em> Form1()</em></p><p><em> {</em></p><p><em> InitializeComponent();</em></p><p><em> }</em></p><p><em>private</em><em>void</em><em> pictureBoxLight_Click(</em><em>object</em><em> sender, EventArgs e)</em></p><p><em> {</em></p><p><em> curLightState = !curLightState;</em></p><p><em> setLight(curLightState);</em></p><p><em>byte</em><em>[] sendBuf = </em><em>new</em><em>byte</em><em>[] { 0xA5, 0x5A, 0x05, 0x82, 0x12, 0x51, 0x00, 0x01 };</em></p><p><em>if</em><em>(curLightState)</em></p><p><em> {</em></p><p><em> sendBuf[7] = 0x01;</em></p><p><em> }</em></p><p><em>else</em></p><p><em> {</em></p><p><em> sendBuf[7] = 0x00;</em></p><p><em> }</em></p><p><em>try</em></p><p><em> {</em></p><p><em>if</em><em>(client.Send(sendBuf) <= 0)</em></p><p><em> {</em></p><p><em> textBoxLog.Text = </em><em>"Send failed"</em><em>;</em></p><p><em> }</em></p><p><em> }</em></p><p><em>catch</em><em>(Exception ex)</em></p><p><em> {</em></p><p><em> textBoxLog.Text = </em><em>"Send failed"</em><em>;</em></p><p><em> }</em></p><p><em>/* set light */</em></p><p><em> }</em></p><p><em>private</em><em>void</em><em> setLight(</em><em>bool</em><em> b)</em></p><p><em> {</em></p><p><em>if</em><em> (b)</em></p><p><em> {</em></p><p><em> pictureBoxLight.Image = </em><em>global</em><em>::StoneBcLightWifi.Properties.Resources.lightOn;</em></p><p><em> }</em></p><p><em>else</em></p><p><em> {</em></p><p><em> pictureBoxLight.Image = </em><em>global</em><em>::StoneBcLightWifi.Properties.Resources.lightOff;</em></p><p><em> }</em></p><p><em> }</em></p><p><em>private</em><em>void</em><em> buttonConnect_Click(</em><em>object</em><em> sender, EventArgs e)</em></p><p><em> {</em></p><p><em>if</em><em>(StartClient())</em></p><p><em> {</em></p><p><em> textBoxLog.Text = </em><em>"Successful"</em><em>;</em></p><p><em> }</em></p><p><em>else</em></p><p><em> {</em></p><p><em> textBoxLog.Text = </em><em>"Failed"</em><em>;</em></p><p><em> }</em></p><p><em> }</em></p><p><em> }</em></p><p><em>public</em><em>class</em><em>StateObject</em></p><p><em> {</em></p><p><em>// Client socket. </em></p><p><em>public</em><em> Socket workSocket = </em><em>null</em><em>;</em></p><p><em>// Size of receive buffer. </em></p><p><em>public</em><em>const</em><em>int</em><em> BufferSize = 256;</em></p><p><em>// Receive buffer. </em></p><p><em>public</em><em>byte</em><em>[] buffer = </em><em>new</em><em>byte</em><em>[BufferSize];</em></p><p><em>// Received data string. </em></p><p><em>public</em><em> StringBuilder sb = </em><em>new</em><em> StringBuilder();</em></p><p><em> }</em></p><p><em>}</em></p>