NEWS
LinuxCNC 2.5.2 Release
There are no translations available.

LinuxCNC 2.5.2 Update Released (changelog).
 
LinuxCNC 2.5.1 Release
There are no translations available.

LinuxCNC 2.5.1 Update Released (changelog). If the Package Manager does not prompt you to upgrade see this page.

 
LinuxCNC 2.5.0 Release
There are no translations available.

New major release (changelog). See the instructions to update your system from EMC 2.4 to LinuxCNC 2.5.
 
Home Forum Hardware Computer Arduino I/O with Linuxcnc

Welcome, Guest
Username: Password: Remember me

TOPIC: Arduino I/O with Linuxcnc

Arduino I/O with Linuxcnc 14 Авг 2012 07:40 #23166

  • ArcEye
  • ArcEye's Avatar
  • OFFLINE
  • Moderator
  • Posts: 1331
  • Thank you received: 102
  • Karma: 129
Apologies JR1050

I tried to split your last post into a new thread and succeeded but when I tried to remove it from the original thread it deleted both!

You asked if an Arduino Mega 2560 was able to be used as an I/O board for Linuxcnc

OK I have written you an arduino sketch and a hal component that will send and receive respectively, the values at 32 pins on the arduino mega.
The arduino pins used are 14-49, which I think are all digital and I set them to input

You will need to download AVR and Arduino 1.0.1, possibly install the -dev package for linuxcnc and learn how to use comp to create the component ( comp --install compname).
I could send you a compiled component, but that is the easy bit. I can't program your arduino board for you, so there is no shortcut to going to the arduino site and reading.

I have just tested it printing to stderr, you will need to connect the arduino pins to something to test them and connect the component pins bit-0 to 31 to something in hal to do anything.
Comment out the 3 test lines when using for real.
You just get mostly 0 but some 1's in the test print, but the pins are in an unknown floating state unconnected.
//arduinosend.ino
#include <SoftwareSerial.h>
#include "Wire.h"

void setup() 
{
    Serial.begin(9600);
    for(int x = 14; x < 50; x++)pinMode(x, INPUT);
}

void loop() 
{
int x, y, z;  
uint8_t  buff[5];

    buff[4] = '\0';
    z = 14;
    for(x = 0; x < 4; x++) // 4 packets 8 bits
        for(y = 0; y < 8 ; y++) bitWrite(buff[x], y, digitalRead(z++));
    Serial.write(buff, 4);
    delay(1000);    
}
//serialreceive.comp
component serialreceive              "Receiving 32 bits data from arduino";

pin out bit bit-##[32] = false       "Output bits";

option singleton yes;               
option userspace yes;

author "ArcEye arceye@mgware.co.uk";
license "GPL";
;;

#include <stdio.h>    /* Standard input/output definitions */
#include <stdlib.h> 
#include <stdint.h>   /* Standard types */
#include <string.h>   /* String function definitions */
#include <unistd.h>   /* UNIX standard function definitions */
#include <fcntl.h>    /* File control definitions */
#include <errno.h>    /* Error number definitions */
#include <termios.h>  /* POSIX terminal control definitions */
#include <sys/ioctl.h>

#define BAUDRATE B9600
#define DEVICE "/dev/ttyACM0"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))

int serialport_init();
                             
struct termios toptions;;       // port setup

void user_mainloop(void)
{
int c, x, y, z;
char ch;
int fd = serialport_init();
  
    while (fd != -1) 
        {
        usleep(1000000);
        FOR_ALL_INSTS() 
            {
            z = 0;
            for(x = 0; x < 4; x++) // 4 packets 8 bits
                {
                read(fd,&ch,1); 
                for(y = 0; y < 8 ; y++) bit(z++) = bitRead(ch, y);
                }
            // test - to show that bits were written
            // comment out next 3 lines when using for real
            for(x = 0; x < 32; x++) 
                fprintf(stderr,"%d",bit(x));
            fprintf(stderr,"\n");
            }
        }
    close(fd);
    exit(0);
}


//######################################################################

int serialport_init()
{
int fd;
 
    fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NDELAY);
    if (fd == -1)  
        {
        perror("init_serialport: Unable to open port ");
        return -1;
        }
    if (tcgetattr(fd, &toptions) < 0) 
        {
        perror("init_serialport: Couldn't get term attributes");
        return -1;
        }
    speed_t brate = BAUDRATE; 
    cfsetispeed(&toptions, brate);
    cfsetospeed(&toptions, brate);
    // 8N1
    toptions.c_cflag &= ~PARENB;
    toptions.c_cflag &= ~CSTOPB;
    toptions.c_cflag &= ~CSIZE;
    toptions.c_cflag |= CS8;
    // no flow control
    toptions.c_cflag &= ~CRTSCTS;
    toptions.c_cflag |= CREAD | CLOCAL;  // turn on READ & ignore ctrl lines
    toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl
    toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw
    toptions.c_oflag &= ~OPOST; // make raw
    toptions.c_cc[VMIN]  = 0;
    toptions.c_cc[VTIME] = 20;
    if( tcsetattr(fd, TCSANOW, &toptions) < 0) 
        {
        perror("init_serialport: Couldn't set term attributes");
        return -1;
        }
    return fd;
}

regards
Last Edit: 14 Авг 2012 08:19 by ArcEye.
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 14 Авг 2012 10:11 #23175

  • JR1050
  • JR1050's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 88
  • Thank you received: 1
  • Karma: 3
Arceye,

Thank you!! This is exactly what I need to get started.Ive programmed stuff before using comp(all my plc's).Thanks again.

JR
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 15 Авг 2012 01:32 #23229

  • ArcEye
  • ArcEye's Avatar
  • OFFLINE
  • Moderator
  • Posts: 1331
  • Thank you received: 102
  • Karma: 129
Just so you can see how to address the pins, a screen shot of hal window



regards

NB
The pin states will oscillate when you test things.

Arduino pins configured as inputs are said to be in a high-impedance state and take little to trigger them.
This means however, that input pins with nothing connected to them, or with wires connected to them that are not connected to other circuits,
will report seemingly random changes in pin state, picking up electrical noise from the environment, or capacitively coupling the state of a nearby pin.

You may want to ground the unused pins with a pulldown resistor (10K resistor to ground) to prevent this

Depending upon the mounting point, you may want to mount inside a screened enclosure or shroud and use screened cables to prevent false signals
Last Edit: 15 Авг 2012 03:07 by ArcEye.
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 15 Авг 2012 16:31 #23276

  • JR1050
  • JR1050's Avatar
  • OFFLINE
  • Expert Boarder
  • Posts: 88
  • Thank you received: 1
  • Karma: 3
Thanks!! I cant wait to get the board and start working on this.

I have three other machines slated for an Emc conversion.Another Hardinge,a Cincinnatti Lathe that had an Acra 850 that died and a Matsurra 760v2.The matsurra runs but has an aggrivating tool changer problem that no one seems to be able to figure out.It is somehow tied to the original Yasnac control.These are future projects...

The Cinci lathe was setup with a Pmac control that works.I just dont care for the windows system,and its fussy.I do however want to reuse their operators panael,hence the need for the i/o board.


Thanks again!!

JR
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 20 Авг 2012 12:52 #23433

  • Lucariel
  • Lucariel's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
Very interesting ..
I tried to install your module "serialreceive" without success.

1. I installed the-dev package linuxcnc

2. I wanted to copy your "serialreceive.comp" in the directory "linuxcnc / src / hal / components" but I could not find the specified directory

could you explain step by step how to do?

thanks in advance
Luca

sorry for my bad english
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 21 Авг 2012 02:05 #23464

  • ArcEye
  • ArcEye's Avatar
  • OFFLINE
  • Moderator
  • Posts: 1331
  • Thank you received: 102
  • Karma: 129
Hi

Its not a module, it is the code for one

http://linuxcnc.org/docs/2.5/html/hal/comp.html
shows how to compile and install it
I wanted to copy your "serialreceive.comp" in the directory "linuxcnc / src / hal / components" but I could not find the specified directory
This refers to the linuxcnc source file tree, if you are not building your own Linuxcnc from sources it is not relevant

regards
Last Edit: 21 Авг 2012 02:07 by ArcEye.
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 21 Авг 2012 12:03 #23511

  • Lucariel
  • Lucariel's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
Thank you for having responded to me quickly .....

I had already read the document on the use of comp
unfortunately I can not perform the procedure for compile
I try to explain how I proceeded.

. I created a new text file on my desktop.
. I copied and pasted the code that you wrote (serialreceive.comp) in my text file
. I renamed the file to "serialreceive.comp."
. at this point the document that you linked to the point 11 writes:
"Place the. Comp file in the source directory " linuxcnc/src/hal/components " and re-run make. Comp files are automatically detected by the build system."
or
"If a. Comp file is a driver for hardware, it may be placed in " linuxcnc/src/hal/components " and will be built Unless LinuxCNC is configured as a userspace simulator."

in my system the path " /linuxcnc/src/hal/components " does not exist

I tried some additional information but I could not understand how.

all sorry for my English is not perfect and thanks in advance
Luke.
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 21 Авг 2012 12:18 #23512

  • BigJohnT
  • BigJohnT's Avatar
  • OFFLINE
  • Administrator
  • Posts: 4955
  • Thank you received: 86
  • Karma: 134
I have LinuxCNC installed with the LiveCD you have to get the dev by opening up a terminal and

sudo apt-get install linuxcnc-dev

Once that is installed then change directory to where your comp file is and

sudo comp --install serialreceive.comp

Once that is done you can use your comp by loading it in your hal file.

John
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 21 Авг 2012 12:23 #23513

  • Lucariel
  • Lucariel's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Karma: 0
Thank you once again for having responded to me quickly .....

I forgot to write that the package linuxcnc-dev is already properly installed
The administrator has disabled public write access.

Re:Arduino I/O with Linuxcnc 21 Авг 2012 14:58 #23517

  • andypugh
  • andypugh's Avatar
  • OFFLINE
  • Moderator
  • Posts: 4119
  • Thank you received: 141
  • Karma: 129
Lucariel wrote:
Thank you once again for having responded to me quickly .....

I forgot to write that the package linuxcnc-dev is already properly installed

The first instructions you described were for compiling in the source tree, ie with a full set of LinuxCNC source files.
You shouldn't need that, though you might do if the .comp file #includes some headers that are not available.

One thing you will need to check is that the component name in the file matches the file name. If you change only the file name, it will not work.

You ideally want to be in the same directory as the .comp file when you issue the sudo comp --install instruction. You will need "sudo" with an installed system.

If that doesn't work, post the last 100 lines or so of the output of the dmesg command.
The administrator has disabled public write access.
Moderators: ArcEye
Time to create page: 1.082 seconds
Powered by Kunena Forum
© 2013 LinuxCNC.org
Joomla! is Free Software released under the GNU General Public License.