在网上买的这个串口屏叫UsartGPU35c,这与其他屏幕相比,

1、是TFT彩屏

2、IO用的少,只要两个RX、TX

3、内存占用少,因为屏幕自带一个单片机,所以你只需传指令就行了,不像其他TFT彩屏,每个点都要数据传进去,这导致很多低性能的单片机根本维持不了

 

我所用的板子是这块,安信可的nodemcu-32s,开发模式是arduino

连接方式很简单,这四个脚连接即可,屏幕是5V供电,RX接对方的TX,反之一样

 

显示的中文

 

我这块屏幕显示的是人名,所以无法准备好字模,只能调用已有字库,但屏幕字库中文只支持gb2312,arduino编辑器上的中文全是utf-8的,所以arduino直接传送中文,是显示乱码的(数字和英文、符号都不受影响)。

解决方案是arduino连接服务器,中文直接在服务器上转为gb2312数字,然后传送给屏幕,即可实现。

 

服务端代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


        string _str = GetHexFromChs("我站在方山顶上");       //将文字转为二进制代码

        Response.Write(_str);
    }



    public static string GetHexFromChs(string s)
    {
        if ((s.Length % 2) != 0)
        {
            s += " ";//空格
                     //throw new ArgumentException("s is not valid chinese string!");
        }

        System.Text.Encoding chs = System.Text.Encoding.GetEncoding("gb2312");

        byte[] bytes = chs.GetBytes(s);

        string str = "";

        for (int i = 0; i < bytes.Length; i++)
        {
            str += string.Format("{0:X}", bytes[i]);
        }

        return str;
    }
}

得到的是这么个东西

接下来在arduino上

创建一个 MyHex_String.cpp


#include "MyHex_String.h"
 
unsigned char MyHex_String::Hex0(char ch)
{
  {
    static const char* hex = "0123456789ABCDEF";
    for (unsigned char i = 0; i != 16; ++i)
      if (ch == hex[i])
        return i;
    return 0;
  }
}

char* MyHex_String::solve(char* dest, const char* src)
{
  {
    int i = 0;
    int cnt = 0;
    unsigned char* d = (unsigned char*)dest;
    while (*src)
    {
      if (i & 1)
      {
        d[cnt++] |= Hex0(*src);
      }
      else
      {
        d[cnt] = Hex0(*src) << 4;
      }
      src++;
      i++;
    }
    return dest;
  }
}

 

创建一个 MyHex_String.h


#ifndef MyHex_String_h
#define MyHex_String_h

#if defined(ARDUINO) && (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

#define MyHex_String_VERSION "0.4.1"

#define MyHex_String_OK                               0
#define MyHex_String_ERROR_CHECKSUM   -1
#define MyHex_String_ERROR_TIMEOUT    -2

class MyHex_String
{
public:
  unsigned char Hex0(char ch);
  char* solve(char* dest, const char* src);

};

#endif

 


#include <WiFi.h>
#include <HTTPClient.h>
#include <RSCG12864B.h>
#include "MyHex_String.h"
 MyHex_String  MyHex;//创建对象
HTTPClient http;

#ifndef STASSID


#define STASSID "xxxx4321"
#define STAPSK  "yyyy4321"

#endif


const char* ssid     = STASSID;
const char* password = STAPSK;

WiFiClient client;

int state=0;

int pin0=0;

void setup()
{
   Serial.begin(115200);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  
  WifiInit();

  pinMode(pin0,OUTPUT);

  digitalWrite(pin0,HIGH);
}
 
void loop()
{

  if(digitalRead(pin0)==state)
  {
    state=!digitalRead(pin0);

String zi= "";



String webstr=GetWeb();

  char dest[100] = { 0 }; 
  


 char  src[webstr.length()+1];
 webstr.toCharArray(src,webstr.length() + 1);
zi=MyHex.solve(dest, src);

 

  Serial.println("CLS(0);");
  Serial.println( "DS16(20,30,'"+zi+"',4);");//输出转换结果




  delay(2000);
    
  }
  
}

void WifiInit()
{
  
  
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      
    }
  


}



String GetWeb()
{
  
    http.begin("http://192.168.2.8:29000/Index.aspx?FName=8as丰立");


        int httpCode =  http.GET(); 

        Serial.println(httpCode);

        if(httpCode == 200) { // 访问成功,取得返回参数
      String payload = http.getString();
     

      return payload;


  } else { // 访问不成功,打印原因
     String payload = http.getString();
     Serial.print("context:");
     Serial.println(payload);

     return payload;
  }


}
sql 转GB2312

0xCED2D5BED4DAB7BDC9BDB6A5C9CF

SELECT CAST('我站在方山顶上' AS VARBINARY) AS [GB2312];   

更多推荐