I'm using the example in the MD_MAX72XX for Esp8266 to display a custom message to a 128X8 SPI matrix display. The code works and I slightly modified it with a timer and a movement detector (RCWL0516) so the leds will be off when noone is watching (to prevent light pollution).
So far, the example is about filling a field on the Esp webpage and clicking the button :
Code: Select all
const char WebPage[] =
"<!DOCTYPE html>" \
"<html>" \
"<head>" \
"<title>MajicDesigns Test Page</title>" \
"<script>" \
"strLine = \"\";" \
"function SendText()" \
"{" \
" nocache = \"/&nocache=\" + Math.random() * 1000000;" \
" var request = new XMLHttpRequest();" \
" strLine = \"&MSG=\" + document.getElementById(\"txt_form\").Message.value;" \
" request.open(\"GET\", strLine + nocache, false);" \
" request.send(null);" \
"}" \
"</script>" \
"</head>" \
"<body>" \
"<p><b>MD_MAX72xx set message</b></p>" \
"<form id=\"txt_form\" name=\"frmText\">" \
"<label>Msg:<input type=\"text\" name=\"Message\" maxlength=\"255\"></label><br><br>" \
"</form>" \
"<br>" \
"<input type=\"submit\" value=\"Send Text\" onclick=\"SendText()\">" \
"</body>" \
"</html>";
I have done that in the past using the serial server plugin & an arduino to display on a TFT. It works but it's cumbersome. I guess I can do it again, hook an arduino to the Display and link it with serial to an Esp module.
Code: Select all
-- ~/domoticz/scripts/lua/script_device_SerialOut.lua
-- Slave Arduino Uno with TFT will expect 19200 Bps (check Arduino code and Serial server on Wemos
-- $ to reset text style %24 and # to increase style by 1 %23
-- So for text in style n°4 string should start with $### = Reset to 1 +1 +1 +1 so 4
----------------------------------------------------------------------------------------------------------
-- Script parameters
----------------------------------------------------------------------------------------------------------
Debug = "Yes" -- Turn debugging on ("YES") or off ("NO")
local SERSTR
local PRESERSTR
----------------------------------------------------------------------------------------------------------
-- Script functions
----------------------------------------------------------------------------------------------------------
function Serout() -- Output the message to Wemos Serial
if Debug=="Yes" then
print ("Six : " .. SERSTR)
end
SERSTR = "http://172.19.0.206/control?cmd=serialsend," .. PRESERSTR .. os.date("%X") .. "%20" .. SERSTR
os.execute('curl -s ' ..SERSTR)
end
----------------------------------------------------------------------------------------------------------
-- CommandArray
----------------------------------------------------------------------------------------------------------
commandArray = {}
if (devicechanged['Security-Hall Door'] == 'Alarm') then
SERSTR = "Hall%20open"
PRESERSTR = "%24%23%23"
elseif (devicechanged['Security-Hall Door'] == 'Normal') then
SERSTR = "Hall%20Close"
PRESERSTR = "%24%23"
elseif (devicechanged['Security-Kitchen door'] == 'Alarm') then
SERSTR = "Kitchen%20open"
PRESERSTR = "%24%23%23"
elseif (devicechanged['Security-Kitchen door'] == 'Normal') then
SERSTR = "Kitchen%20Close"
PRESERSTR = "%24%23"
elseif (devicechanged['Security-Fitness Room'] == 'Alarm') then
SERSTR = "Fitness%20open"
PRESERSTR = "%24%23%23"
elseif (devicechanged['Security-Fitness Room'] == 'Normal') then
SERSTR = "Fitness%20Close"
PRESERSTR = "%24%23"
----------------------------------------NO DEVICE ---------------------------------------------
--elseif (devicechanged['Bedroom window'] == 'Alarm') then
-- SERSTR = "Bedroom%20open"
-- PRESERSTR = "%24%23%23"
-- elseif (devicechanged['Bedroom window'] == 'Normal') then
-- SERSTR = "Bedroom%20Close"
-- PRESERSTR = "%24%23"
-- elseif (devicechanged['Pantry window'] == 'Alarm') then
-- SERSTR = "Pantry%20open"
-- PRESERSTR = "%24%23%23"
-- elseif (devicechanged['Pantry window'] == 'Normal') then
-- SERSTR = "Pantry%20Close"
-- PRESERSTR = "%24%23"
----------------------------------------NO DEVICE ---------------------------------------------
elseif (devicechanged['Security-Motion Salon'] == 'Motion') then
SERSTR = "Salon%20motion"
PRESERSTR = "%24%23%23%23"
elseif (devicechanged['Security-Motion Hall'] == 'Motion') then
SERSTR = "Hall%20Motion"
PRESERSTR = "%24%23%23%23"
elseif (devicechanged['Security-Motion Office'] == 'Motion') then
SERSTR = "Office%20Motion"
PRESERSTR = "%24%23%23%23"
elseif (devicechanged['Lantern Switch'] == 'On') then
SERSTR = "Lantern%20On"
PRESERSTR = "%24%23%23%23%23"
elseif (devicechanged['Lantern Switch'] == 'Off') then
SERSTR = "Lantern%20Off"
PRESERSTR = "%24%23%23%23%23"
else -- Script will stupidely run for every device change so you need this
return commandArray
end
Serout()
return commandArray
Code: Select all
//////////////////////////////////////////////////////////////////////////////
/// This is the program for the "slave" Arduino TFT ///
/// Solder the 4 pins of the "serial connector" of the Uno to a 90° right ///
/// angle connector. This way you'll be able to connect a cable and place ///
/// the TFT on top of the UNO. ///
/// It's just below the ICSP, RX TX 5V GND. Connect it to the Wemos TX RX ///
/// 5V & GND with a cable. ///
/// 5V -- 5V ///
/// GND -- GND ///
/// RX -- TX ///
/// TX -- RX ///
/// 19200 Bps was enough for me, but feel free to change the speed of the ///
/// Serial port. Remember to do it on the Wemos too ! ///
/// ///
//////////////////////////////////////////////////////////////////////////////
/// 20171116 Grumpf. ///
//////////////////////////////////////////////////////////////////////////////
// http://www.barth-dev.de/online/rgb565-color-picker/ here to choose your 16 bits colr !!!
#include <Adafruit_GFX.h> // Hardware-specific library
#include <MCUFRIEND_kbv.h>
#include <fonts/FreeSans9pt7b.h>
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define TRS80DarkGreen 0x0140
#define HayYellow 0xFFAA
#define Mud 0x59C5
#define Darkmud 0x4100
#define Blood 0x6000
#define Bone 0xeff9
#define Undersea 0x0085
#define Foam 0xa79f
#define Jungle 0x6544
#define Ivy 0x3921
#define Piggy 0xFBD7
#define Ham 0x88F4
#define Pumpkin 0xCCA0
#define ArduinoL 0x4D74
#define ArduinoD 0x2B2B
//////////////////////////////////////////////////////////////////////////////
/// Parameters here are for 9341 Controller 320X240 ///
//////////////////////////////////////////////////////////////////////////////
int16_t ht, top, line, lines, scroll;
short FG, BG; // Foreground color, background
byte TexSiz, TexStyle = 1;
char Buff;
void setup()
{
//////////////////////////////////////////////////////////////////////////////
/// INIT TFT, no test is made for the type of controller ///
/// You may have to adapt the code to your controller ///
/// Check with other examples and modify accordingly ///
//////////////////////////////////////////////////////////////////////////////
tft.reset();
uint16_t id = tft.readID();
tft.begin(id);
tft.setRotation(0); //Portrait, scroll is only supported this way
tft.fillScreen(BLACK);
tft.setTextColor(HayYellow, Undersea);
tft.setTextSize(2);
tft.setCursor(100, 0);
tft.print("ID = 0x");
tft.println(id, HEX);
top = 0; // these controllers scroll full screen
FG = CYAN;
BG = BLACK;
TexSiz = 1;
tft.setFont(&FreeSans9pt7b);
TextSizechanged();
//////////////////////////////////////////////////////////////////////////////
/// INIT SERIAL for input ///
//////////////////////////////////////////////////////////////////////////////
Serial.begin(19200);
}
//////////////////////////////////////////////////////////////////////////////
/// MAIN ///
/// It is assumed that the text does not exceed the number of characters ///
/// than can be printed in one line. If it is, then it'll appear on "top" ///
/// of the TFT. ///
/// § character will reset the TFT to default type color and # will change ///
/// The style to the next one. So if you wish your message to appear as ///
/// Style to, start it with $#, style 4 $### etc. ///
/// For DOmoticz, %20 = Space, %23 = # and %24 =$
//////////////////////////////////////////////////////////////////////////////
void loop()
{
if(Serial.available()){
cleartop();
delay(100);
tft.setCursor(0, 10 +(scroll + top) * ht);
if (++scroll >= lines) scroll = 0;
tft.vertScroll(0, 319, (scroll) * ht);
while (Serial.available() >0) {
Buff = Serial.read();
if (Buff == '#') {
TexStyle++;
Buff = 0;
Style();
}
if (Buff == '$') {
Buff = 0;
TexStyle = 1;
Style();
}
tft.print(Buff);
}
}
delay(100);
line++;
}
void cleartop(){
tft.fillRect(0, (scroll + top) * ht -1, 240, ht, BG);
}
void TextSizechanged()
{
switch (TexSiz) {
case 1: // Free Sans
tft.setTextSize(1);
ht = 10; //24 chars per line
lines = 20;
case 2: // 19 chars per line
ht = 16;
lines = 20;
break;
case 3: // 13 chars per line
ht = 24;
lines = 13;
break;
case 4: // 9 chars per line
ht = 32;
lines = 10;
break;
}
tft.setTextColor(FG, BG);
}
void Style(void){
switch (TexStyle) {
case 2 : // Doors & Windows closed
FG = ArduinoL;
BG = ArduinoD;
break;
case 3 : // Doors & Windows Opened
BG = HayYellow;
FG = Blood;
break;
case 4 : // Movement
FG = RED;
BG = Undersea;
break;
case 5 : // Lights
FG = HayYellow;
BG = BLACK;
break;
case 6 : //
FG = Ivy;
BG = Jungle;
break;
case 7 : //
FG = Piggy;
BG = Ham;
break;
default:
FG = WHITE;
BG = BLACK;
TexStyle = 1;
}
tft.setTextColor(FG, BG);
tft.fillRect(0, (scroll + top -1) * ht -1, 240, ht, BG); // Fonts do NOT draw background like raster so you need this...
}
Problem is, I have no clue how to do that. I tried some commands but it's too obscure for me.
Any advice ?