UCCNC and Arduino

Post anything you want to discuss with others about the software.

UCCNC and Arduino

Postby camivic » Sat Dec 31, 2022 5:27 pm

Hi everyone.
I would like to start studying the possibility of communicating from UCCNC to an ARDUINO.
Could you point me to a simple guide to get started?
Maybe even a simple Arduino sketch that I can use as a base.
Thanks to all and happy new year.

Vincenzo
camivic
 
Posts: 26
Joined: Thu Dec 08, 2016 10:32 pm

Re: UCCNC and Arduino

Postby camivic » Mon Jan 02, 2023 9:57 pm

For the moment I have solved: I found an excellent sketch for arduino, configuring some "READ INPUT" and some "READ INPUT REGISTER".
With the "READ INPUT" everything works, while with the "READ INPUT REGISTER" connected to the Arduino A0 output, I don't understand what code to insert in the UCCNC macro in order to vary the SRO (or FRO).
Can anyone suggest me a solution?
Thank you.
camivic
 
Posts: 26
Joined: Thu Dec 08, 2016 10:32 pm

Re: UCCNC and Arduino

Postby dezsoe » Tue Jan 03, 2023 10:10 am

Here is a sample macroloop from my archive which handles analog and digital inputs/outputs:

Code: Select all
// ================================================================================================
// Arduino Modbus I/O sample
// ================================================================================================

ushort Inputs = 0;
ushort Pot1 = 0;
ushort Pot2 = 0;

exec.GetModbusregister(0, out Inputs);
exec.GetModbusregister(4, out Pot1);
exec.GetModbusregister(5, out Pot2);

int FRO = Convert.ToInt32(AS3.Getfield(232).Replace("%", ""));
int JRO = Convert.ToInt32(AS3.Getfield(913));

int newFRO = (int)((double)Pot1 / 1023.0 * maxFRO / 5.0) * 5;                   // 5% steps
int newJRO = (int)((double)Pot2 / 1023.0 * 100.0);

if (newFRO != FRO)
{
  AS3.Setfield(newFRO, 232);
  AS3.Validatefield(232);
}

if (newJRO != JRO)
{
  AS3jog.Setfield(newJRO, 913);
  AS3jog.Validatefield(913);
}

int newInputs = ((int)Inputs & 0x0F) ^ 0x0F;                                    // 4 inputs, change to active high

if (lastInputs == 16) lastInputs = newInputs;

if (newInputs != lastInputs)
{
  int change = newInputs ^ lastInputs;
  // NC reset switch -> force reset to switch state
  if ((change & 0x01) != 0)
  {
    if ((newInputs & 0x01) != 0)
      exec.Callbutton(513);
    else
      exec.Callbutton(512);
  }
  // Compare SPST switch state to screen button state -> press button if needed
  if ((change & 0x02) != 0)
  {
    if (((newInputs & 0x02) != 0) != AS3.Getbuttonstate(114))
      exec.Callbutton(114);
  }
  // NO pushbutton
  if ((change & 0x04) != 0)
  {
    if ((newInputs & 0x04) != 0)
      exec.Callbutton(130);                                                     // Button pressed
//  else
//    exec.Callbutton(0);                                                       // Button released
  }
  // NO pushbutton
  if ((change & 0x08) != 0)
  {
    if ((newInputs & 0x08) != 0)
      exec.Callbutton(522);
//  else
//    exec.Callbutton(0);
  }
  lastInputs = newInputs;
}

bool LED1 = exec.GetLED(19);
bool LED2 = exec.GetLED(54);
bool LED3 = false;
bool LED4 = false;

ushort digitalOut = (ushort)((LED1 ? 0x01 : 0) + (LED2 ? 0x02 : 0) + (LED3 ? 0x04 : 0) + (LED4 ? 0x08 : 0));

ushort analogOut1 = (ushort)(AS3.Getfielddouble(2451) / AS3.Getfielddouble(178) * 255); // Overridden RPM / max. RPM
ushort analogOut2 = (ushort)(0);

ushort[] data = new ushort[3];
data[0] = digitalOut;
data[1] = analogOut1;
data[2] = analogOut2;

exec.SetModbusregisters(10, data);

// ================================================================================================

#Events

// ================================================================================================

const double maxFRO = 150.0;

int lastInputs = 16;
dezsoe
 
Posts: 2055
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: UCCNC and Arduino

Postby camivic » Tue Jan 03, 2023 2:16 pm

Thanks dezsoe, i try it.
camivic
 
Posts: 26
Joined: Thu Dec 08, 2016 10:32 pm

Re: UCCNC and Arduino

Postby formantjim » Tue Jan 03, 2023 2:42 pm

Hi Camivic I would be interested to see that sketch for the Modbus Arduino if you could share please?
formantjim
 
Posts: 73
Joined: Fri May 31, 2019 5:28 pm

Re: UCCNC and Arduino

Postby Battwell » Wed Jan 04, 2023 1:20 am

I played with a couple of mega a few years ago using modbus
Made a great control panel :-)
Gives lots of extra io and analogs .
https://youtu.be/Mxr_4iRQsdQ
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 827
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: UCCNC and Arduino

Postby camivic » Wed Jan 04, 2023 9:43 am

formantjim wrote:Hi Camivic I would be interested to see that sketch for the Modbus Arduino if you could share please?


Hi formantjim,
attached you can found the sketch and library used with Arduino in Slave Modbus function.
Ciao.
Attachments
PLC_Uno.zip
(8.91 KiB) Downloaded 164 times
camivic
 
Posts: 26
Joined: Thu Dec 08, 2016 10:32 pm

Re: UCCNC and Arduino

Postby formantjim » Thu Jan 05, 2023 1:22 am

Many thanks. Nicely commented out I will give it try at the weekend.
I'm looking to build a quick and simple Modbus tester for the various pieces of software my company use with our vendors instruments. It will be a simple battery powered device using an UNO with Analogue values coming in via 4 to 20mA or a potentiometer and be read by the UNO and displayed in other software.
formantjim
 
Posts: 73
Joined: Fri May 31, 2019 5:28 pm


Return to General discussion about the UCCNC software

Who is online

Users browsing this forum: No registered users and 5 guests

cron