[Question]use of readData() on lua interpreter
local pin = readData([ESP201] P=4) if pin == 1 then print("[ESP201] P=4 V=0 ") else print("[ESP201] P=4 V=1 ") end
I'm writing a couple of scripts like this one (just change state of flash on esp32cam). I know this can be just a digitalRead, but its about using readData() , this doesnt work, I missed something? can readData used to read serial, like M27 data?
any help please to clarify it
readData() read any string received by lua interpreter, from ESP3D if you send any [ESPXXX] command but also any string from serial or usb
use available() to check if any string is available then readData() to collect one string at once
here a sample script that echo any message received by lua interpreter
--[[
Echo Serial
This example echo serial outout to serial with echo: header
Put this script in the ESP3D flash file system and call it from the init script in
configuration.h.
#define ESP_AUTOSTART_SCRIPT "[ESP300]/FS/detectpush.lua"
Be sure to have the following line comment out in the configure.h:
#define ESP_LUA_INTERPRETER_FEATURE
]]--
-- Setup
local availableMsg = 0
local message = ""
while (true) do
-- check if have data
availableMsg = available()
-- if any message
if (availableMsg > 0) then
message = "echo:" .. readData()
print(message)
end
-- yield to other tasks
yield()
end
I know documentation https://esp3d.io/ESP3D/Version_3.X/documentation/lua/ is very light but no one seems used this feature until now because I got no feedback on this feature, so feel free to propose, submit better documentation, of course I will help by answering any question or give clarifications if necessary
@kleffa did this answered your question ?
Yes, let me try some scripts and share as example
El lun, 5 de may de 2025, 21:20, Luc @.***> escribió:
luc-github left a comment (luc-github/ESP3D#1092) https://github.com/luc-github/ESP3D/issues/1092#issuecomment-2852917106
@kleffa https://github.com/kleffa did this answered your question ?
— Reply to this email directly, view it on GitHub https://github.com/luc-github/ESP3D/issues/1092#issuecomment-2852917106, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGMYMBJZ6XNI4EGGQYE56ZD25AE4LAVCNFSM6AAAAAB4NYJAO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDQNJSHEYTOMJQGY . You are receiving this because you were mentioned.Message ID: @.***>
--[[ FLASH BUTTON
This example is implemented in a ESP32-CAM.
You can set a macros, as a GCODE one, with this command
[ESP300]/FS/flash.lua
NOW YOU HAVE A FLAH BUTTON SET ON YOUR ESP32
You can also start it manually from the serial monitor by typing:
[ESP300]/FS/flash.lua
Be sure to have the following line comment out in the configure.h:
#define ESP_LUA_INTERPRETER_FEATURE
]]--
local FLASH_PIN = 4 -- GPIO for flash
pinMode(FLASH_PIN, OUTPUT) local STATE = digitalRead(FLASH_PIN)
if STATE == HIGH then digitalWrite(FLASH_PIN, LOW) else digitalWrite(FLASH_PIN, HIGH) end
--[[ Timelapse camera
This example is implemented in a ESP32-CAM.
in CURA post procesing tab, find time lapse, there is the option to set parking hotend
Put this script in the ESP3D flash file system and call it from camera trigger command
M118 P2[ESP300]/FS/autocam.lua
You can also start it manually from the serial monitor by typing:
[ESP300]/FS/autocam.lua
Be sure to have the following line comment out in the configure.h:
#define ESP_LUA_INTERPRETER_FEATURE
]]--
local FLASH_PIN = 4 -- GPIO for flash local FLASH_DELAY = 200 -- ms for flash to stabilize local POST_DELAY = 200 -- ms after capture before flash off
pinMode(FLASH_PIN, OUTPUT) --set FLASH_PIN digitalWrite ( FLASH_PIN, HIGH) --turn on flash delay ( FLASH_DELAY ) --pause print ( "[ESP171] path=DCIM\n") --take picture delay ( POST_DELAY ) --pause digitalWrite ( FLASH_PIN, LOW) --turn off flash
great thank you, I am happy lua is helpful for something, I did not get so many feedback
I think there should be a way to convine M118 and lua to make a variable to save the timelapse pics on sd/{jobname}/
Any idea is welcome
El jue, 26 de jun de 2025, 01:17, Luc @.***> escribió:
luc-github left a comment (luc-github/ESP3D#1092) https://github.com/luc-github/ESP3D/issues/1092#issuecomment-3007084676
great thank you, I am happy lua is helpful for something, I did not get so many feedback
— Reply to this email directly, view it on GitHub https://github.com/luc-github/ESP3D/issues/1092#issuecomment-3007084676, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGMYMBJ4YJIHLRD7A3OD42T3FN66BAVCNFSM6AAAAAB4NYJAO6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTAMBXGA4DINRXGY . You are receiving this because you were mentioned.Message ID: @.***>
I close topic as answered and no new activity
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.