Hello Guest it is April 19, 2024, 01:54:18 PM

Author Topic: Pokeys Mach4 plugin LUA reference for LCD  (Read 26728 times)

0 Members and 1 Guest are viewing this topic.

Pokeys Mach4 plugin LUA reference for LCD
« on: October 03, 2016, 04:46:22 PM »
Hi,

Is there a reference manual available anywhere for the Mach4 version of the pokeys plugin that will give me an idea of how to communicate with the LCD and also set the PWM duty cycle etc for the contrast and backlight pins via LUA code?

Any info is much appreciated as I have been searching for days and cant seem to find any way of doing this.

Thanks in advance,

Chris.
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #1 on: November 03, 2016, 01:57:39 PM »
Chris,

I have some of the same questions.  He is what I have discovered after many hours of playing.

If you look in MACH4 and go to the Diagnostics tab at the top then go down to Regfile - Newfangled Solutions, you can click there and a new window will open.  It shows all the registers available and if you have installed the Pokeys plugin you will find a + next to something like PoKeys_45617.  Now press the + on this group of registers and you will find all the registers accessible in the Pokeys device.  Now slide down near the bottom of the long list and you will see four entries.

LCD Line1:
LCD Line2:
LCD Line3:
LCD Line4:

Double click on any LCD line and you can actually enter any value and it will immediately show up on the LCD screen.  I have tested and verified this part works perfect.

Now I need to figure out how to take something like say the MACH4 DRO and write that to these registers.  This is something I am trying to figure out for a POKEYS pendant.  Hopefully this gets you pointed in the right direction.

Russ

Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #2 on: December 04, 2016, 01:07:51 PM »
Chris,
You can adjust the PWM duty cycle inside the plugin inside of Mach4 for the Pokey.  That does adjust the LCD contract on my pendant.  Right now I am working on a way to copy the DROs inside of MACH4 to the pokeys plugin register that holds the LCD display.  I have not been able to get it to work yet.  Hoping someone know exactly how to access those registers via LUA.  All the stuff I have tried does not work in LUA for the plugin registers.

Russ

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #3 on: December 05, 2016, 09:25:08 AM »
Look in the API help file at Mach registers.

I think you will use mc.mcRegSetValueString(number hReg, string value)
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #4 on: December 05, 2016, 10:56:31 AM »
Stakeboss,

Here is now you can get Mach4 to update an LCD screen attached to the Pokeys unit.

Go into the Screen Editor
click on the X DRO on the screen, then look at the left you will see droCurrentX
Now look at the window below this window and click on the second little box which is the events tab.
Now click on the first line below that called "On Update Script", now click on the box with the three dots to the right, that will open a blank Lua Page.

Now you need to copy the LUA code below and paste it on that blank LUA page.  Please update the serial number of your Pokeys device, and then save and exit the screen editor.
Now exit Mach4 and then start it up again.  Now the LCD will update each time you have the DROs update in Mach4.

DazTheGas helped me get this working, now the next part is to get a formatted output, because this will display the DRO on the screen for example 23.1234, but on the LCD it will be 23.123456.

I am working on how to do a formatted output that knows the screen is 20 digits long and I need it to follow the standard DRO format which is %4.4f

As soon as I get that part working I will post it as well.  This will at least get your LCD working.  Have Fun

Russ


local inst = mc.mcGetInstance()
local Xcoords = scr.GetProperty("droCurrentX","Value")
local Ycoords = scr.GetProperty("droCurrentY","Value")
local Zcoords = scr.GetProperty("droCurrentZ","Value")
local Acoords = scr.GetProperty("droCurrentA","Value")
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 1"))
mc.mcRegSetValueString(hreg, tostring(Xcoords))
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 2"))
mc.mcRegSetValueString(hreg, tostring(Ycoords))
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 3"))
mc.mcRegSetValueString(hreg, tostring(Zcoords))
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 4"))
mc.mcRegSetValueString(hreg, tostring(Acoords))

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #5 on: December 05, 2016, 11:08:33 AM »
This might work.........

replace
mc.mcRegSetValueString(hreg, tostring(Xcoords))

with
mc.mcRegSetValueString(hreg, string.format("%4.4f", Xcoords)
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #6 on: December 05, 2016, 11:46:25 AM »
Chaoticone,

Nope, what that does is print out %4.4f on the LCD screen.

I think the issue is the values are being retrieved and they are floating point.  Then you send it to the display as a string so it does not know how to handle the %f.4f.  I even removed the quotes and that gives me an LUA error.

There must be some other trick, I will keep looking at the manual.  Must have missed something somewhere.

Russ

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #7 on: December 05, 2016, 11:53:26 AM »
Might try this.....

local Xcoords = scr.GetProperty("droCurrentX","Value")
Xcoords = string.format("%4.4f", Xcoords)

If that works, do the same for Y and Z.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #8 on: December 05, 2016, 04:03:36 PM »
Chaoticone,

That is exactly what I was going to attempt.  The following code kind of works.  Let me explain.
When you start up Mach4 many times it does not write to the LCD display, not exactly sure why.
If you load the roadrunner TAP file and enable the machine and start running the LCD display suddenly starts following the On Screen DROs. 
These are displayed correctly for example screen shows 23.4567, now the LCD shows 23.4567, so that part is great.  Still need to figure out how to clear the display prior to these writes as it only updates the 4%.4f digits.

The next issue is also strange.  If I stop the Gcode, then press zero X that updates on the LCD display just fine, but if I try that to Y,Z, or A they do not update to zero.

Not sure if I need to grab the instance before each get handle, but that is not required in the screen load scripts.  Not positive.  Scratching my head on this one.

The other thing I would like to display X:  before the actual data on each line, so the axis shows.

Getting closer thanks for the help Chaoticone.

Russ



local inst = mc.mcGetInstance()
local Xcoords = scr.GetProperty("droCurrentX","Value")
local Ycoords = scr.GetProperty("droCurrentY","Value")
local Zcoords = scr.GetProperty("droCurrentZ","Value")
local Acoords = scr.GetProperty("droCurrentA","Value")
Xcoords = string.format("%4.4f", Xcoords)
Ycoords = string.format("%4.4f", Ycoords)
Zcoords = string.format("%4.4f", Zcoords)
Acoords = string.format("%4.4f", Acoords)
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 1"))
mc.mcRegSetValueString(hreg, tostring(Xcoords))
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 2"))
mc.mcRegSetValueString(hreg, tostring(Ycoords))
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 3"))
mc.mcRegSetValueString(hreg, tostring(Zcoords))
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 4"))
mc.mcRegSetValueString(hreg, tostring(Acoords))

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: Pokeys Mach4 plugin LUA reference for LCD
« Reply #9 on: December 05, 2016, 04:39:41 PM »
OK, are you putting all of this code in the X DRO on updates script? If so, you will need to put it in each DROs on update script respectively.

Code: [Select]
This goes in the X DROs on update script.....
local inst = mc.mcGetInstance()
local Xcoords = scr.GetProperty("droCurrentX","Value")
Xcoords = string.format("X%4.4f", Xcoords)
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 1"))
mc.mcRegSetValueString(hreg, tostring(Xcoords))

This goes in the Y DROs on update script......
local inst = mc.mcGetInstance()
local Ycoords = scr.GetProperty("droCurrentY","Value")
Ycoords = string.format("Y%4.4f", Ycoords)
local hreg = mc.mcRegGetHandle(inst, string.format("PoKeys_32062/LCD Line 2"))
mc.mcRegSetValueString(hreg, tostring(Ycoords))
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!