Arduino HAL Mapping

More
17 Nov 2010 21:27 #5378 by gatonero
Arduino HAL Mapping was created by gatonero
Hi EMC2 heroes,

today I started to drive my homemade CNC-Mill with EMC2. Because its controller is an Arduino I need a special configuration. So I followed Jeff Epler's explanations of the improved interface between HAL and the Arduino board .

Now I'm very confused how to map my arduino pins to the HAL pin names.

This is my arduino pin setting how it is actually connected to the stepper drivers:
//cartesian bot pins
#define X_STEP_PIN 3
#define X_DIR_PIN 4
#define X_ENABLE_PIN 5
#define X_MIN_PIN 6
#define X_MAX_PIN 7

#define Y_STEP_PIN 8
#define Y_DIR_PIN 9
#define Y_ENABLE_PIN 10
#define Y_MIN_PIN 11
#define Y_MAX_PIN 12

#define Z_STEP_PIN 14
#define Z_DIR_PIN 15
#define Z_ENABLE_PIN 16
#define Z_MIN_PIN 17
#define Z_MAX_PIN 18

And this is the arduino-vcp.hal file where the pins should been set:
loadusr -W arduino /dev/ttyUSB0 3
loadusr -Wn arduino-vcp pyvcp arduino-vcp.xml

show pin arduino-vcp

net ain0 arduino.analog-in-00 => arduino-vcp.analog-in-00 arduino-vcp.analog-in-00b
net ain1 arduino.analog-in-01 => arduino-vcp.analog-in-01 arduino-vcp.analog-in-01b
net ain2 arduino.analog-in-02 => arduino-vcp.analog-in-02 arduino-vcp.analog-in-02b
net ain3 arduino.analog-in-03 => arduino-vcp.analog-in-03 arduino-vcp.analog-in-03b
net ain4 arduino.analog-in-04 => arduino-vcp.analog-in-04 arduino-vcp.analog-in-04b
net ain5 arduino.analog-in-05 => arduino-vcp.analog-in-05 arduino-vcp.analog-in-05b

net din0 arduino.digital-in-08 => arduino-vcp.digital-in-08
net din1 arduino.digital-in-12 => arduino-vcp.digital-in-12
net din2 arduino.digital-in-13 => arduino-vcp.digital-in-13

net aout0 arduino.analog-out-03 => arduino-vcp.analog-out-03-f
net aout1 arduino.analog-out-05 => arduino-vcp.analog-out-05-f
net aout2 arduino.analog-out-06 => arduino-vcp.analog-out-06-f
net aout3 arduino.analog-out-09 => arduino-vcp.analog-out-09-f
net aout4 arduino.analog-out-10 => arduino-vcp.analog-out-10-f
net aout5 arduino.analog-out-11 => arduino-vcp.analog-out-11-f

net dout0 arduino.digital-out-02 <= arduino-vcp.digital-out-02
net dout1 arduino.digital-out-04 <= arduino-vcp.digital-out-04
net dout2 arduino.digital-out-07 <= arduino-vcp.digital-out-07

setp arduino.digital-in-08-pullup 1
setp arduino.digital-in-12-pullup 1
setp arduino.digital-in-13-pullup 1

waitusr arduino-vcp

Any help is highly requested.

Best
gatonero

Please Log in or Create an account to join the conversation.

More
18 Nov 2010 00:06 - 18 Nov 2010 13:03 #5382 by andypugh
Replied by andypugh on topic Re:Arduino HAL Mapping
I am a bit puzzled...

How is your PC connected to the Arduino?

What "sketch" is on the Arduino?
Last edit: 18 Nov 2010 13:03 by BigJohnT. Reason: Andy's keyboard

Please Log in or Create an account to join the conversation.

More
19 Nov 2010 10:19 #5430 by gatonero
Replied by gatonero on topic Re:Arduino HAL Mapping
The Arduino is connected via USB. With Jeff Eplers HAL Configuration and his Arduino firmware it should be possible to drive this USB device.What I don't understand is the pin mapping.The arduino pin mapping is how the analog/digital pins are mapped to the stepper drivers.

If its not clear I'll explain it more detailed when I'm back home this weekend.

Please Log in or Create an account to join the conversation.

More
19 Nov 2010 11:12 #5431 by andypugh
Replied by andypugh on topic Re:Arduino HAL Mapping
The Arduino sketch as written by Jeff does not have enough digital IO to drive your specified pinout. It has only 6 pins defined as digital and the PWM-capable pins are set up for PWM.

The arduino driver is a Userspace component, I don't think it is appropriate for step generation, whech needs to be done in a realtime component.

Please Log in or Create an account to join the conversation.

More
19 Nov 2010 12:27 #5435 by andypugh
Replied by andypugh on topic Re:Arduino HAL Mapping
I think my previous post might have sounded excessively discouraging.

Looking at the Contraptor page it seems like the standard layout uses an Arduino-based G-code interpreter and that you want to move the G-code interpretation to EMC2.
At that point there seems little point in keeping the Arduino as part of the system.

Does the computer which EMC2 is running on have a parallel port? If it does then it makes a lot more sense to connect that to the motor drivers in place of the Arduino.

How are you currently communicating with the Arduino?

Please Log in or Create an account to join the conversation.

More
19 Nov 2010 19:26 - 19 Nov 2010 20:22 #5445 by gatonero
Replied by gatonero on topic Re:Arduino HAL Mapping
Hi andypugh,

thank you very mutch for your assistance.

Also I have a parallel port at my home pc, I would prefer to drive my mill via USB using the Arduino board. Because of two reasons. 1) The mill is very easy to move from one place to the other for example to our fablab and our dorkbot meetings, where we are experimenting with different 3D machines (lasercutters, 3D-printers etc.). There I'm using my netbook. 2) I want to be as close as possible to the contraptor design. It uses nearly the same hard- and software technique as RepRap or Makerbot. My goal is if the contraptor succeeds to drive other arduino based systems with EMC2. I guess this is a real powerful, high sophisticated piece of open software which exactly meets the interests of open hardware projects.

Nevertheless I certainly will try it with the parallel port also but later, First I will try to get this Arduino stuff working.

As I understand Jeff Epler's elaboration it should be possible to get it running. Maybe I have to rearrange my connections between the Arduino and the stepper drivers. But I'm not familiar with the syntax of hal scripting and how the pins are mapped from
EMC2 via HAL to the Arduino pins. The communication is serial.


For better understanding how the Arduino is connected to the stepper drivers please have a look at Contraptor -Make Electronics And Motors . Most stuff and pictures are made by myself.

Here is Jeff's Arduino Code, which interprets EMC2 control sequences:
void setup() {
    Serial.begin(9600);
}   

uint8_t adc=0;
uint8_t firstbyte=0;
uint8_t pinmap[6] = {2,4,7,8,12,13};
uint8_t dacpinmap[6] = {3,5,6,9,10,11};
void loop() {
  while(Serial.available()) {
        uint8_t byte = Serial.read();
        if(((firstbyte & 0x80) == 0x80) && ((byte & 0x80) == 0)) {
            // got a packet
            uint16_t payload = (firstbyte << 7) | byte;
            uint8_t address = (firstbyte >> 4) & 7;
            uint8_t dac = payload & 0xff;
            uint8_t dir = (payload & 0x100) == 0x100;
            uint8_t out = (payload & 0x200) == 0x200;
            if(address < 6) {
                analogWrite(dacpinmap[address], dac);
                digitalWrite(pinmap[address], out);
                pinMode(pinmap[address], dir);
            }
        }
        firstbyte = byte;
    }
    uint16_t v = analogRead(adc) | (adc << 11);
    if(digitalRead(pinmap[adc])) v |= (1<<10);
    Serial.print((v >> 7) | 0x80, BYTE);
    Serial.print(v & 0x7f, BYTE);
    adc = (adc + 1) % 6;
}
]

I understand that this sequence controls the pins.
analogWrite(dacpinmap[address], dac);
digitalWrite(pinmap[address], out);
pinMode(pinmap[address], dir);

and this sequence returns signals to EMC2
uint16_t v = analogRead(adc) | (adc << 11);
    if(digitalRead(pinmap[adc])) v |= (1<<10);
    Serial.print((v >> 7) | 0x80, BYTE);
    Serial.print(v & 0x7f, BYTE);
    adc = (adc + 1) % 6;

But I don't have any clue how the mapping works.

Thanks a lot
Christoph

Link to Jeff' files:
arduino-vcp.hal
arduino-vcp.xml
arduino.py
halintf.pde

If you are interested to see my mill running please have a look! :-)
Last edit: 19 Nov 2010 20:22 by gatonero.

Please Log in or Create an account to join the conversation.

More
19 Nov 2010 22:00 #5449 by andypugh
Replied by andypugh on topic Re:Arduino HAL Mapping
USB is not realtime, it is not suitable for running stepper motors (it can be used to control remote step-generators, but even that is pushing it).
Jeff's Arduino driver is absolutely not intended for, nor is it suitable for, motion control. It runs as a userspace module apart from all the other issues.

This really isn't going to work. You are trying to use an Arduino as a USB to parallel convertor, basically. (And they don't work either)

You might find this interesting:

wiki.linuxcnc.org/emcinfo.pl?Emc2HardwareDesign#USB

(Which seems to suggest that by using the realtime USB code and the right code on the Arduino that it might be possible to do what you want to do)

Please Log in or Create an account to join the conversation.

More
20 Nov 2010 12:33 #5461 by gatonero
Replied by gatonero on topic Re:Arduino HAL Mapping
Thanks a lot! I understand that there has to be more development for running EMC2 with an USB interface, That is over my skills and I'll start using the parallel interface. Beside I will have attention what's going on with rt-usb.

Please Log in or Create an account to join the conversation.

More
08 Nov 2013 15:55 #40661 by biggsman
Replied by biggsman on topic Arduino HAL Mapping
Hi!
Please, could You let me know where do You put this Lines?
Does it works?

//cartesian bot pins
#define X_STEP_PIN 3
#define X_DIR_PIN 4
#define X_ENABLE_PIN 5
#define X_MIN_PIN 6
#define X_MAX_PIN 7

#define Y_STEP_PIN 8
#define Y_DIR_PIN 9
#define Y_ENABLE_PIN 10
#define Y_MIN_PIN 11
#define Y_MAX_PIN 12

#define Z_STEP_PIN 14
#define Z_DIR_PIN 15
#define Z_ENABLE_PIN 16
#define Z_MIN_PIN 17
#define Z_MAX_PIN 18

Please Log in or Create an account to join the conversation.

More
08 Nov 2013 15:55 #40662 by biggsman
Replied by biggsman on topic Arduino HAL Mapping
Hi!
Please, could You let me know where do You put this Lines?
Does it works?

//cartesian bot pins
#define X_STEP_PIN 3
#define X_DIR_PIN 4
#define X_ENABLE_PIN 5
#define X_MIN_PIN 6
#define X_MAX_PIN 7

#define Y_STEP_PIN 8
#define Y_DIR_PIN 9
#define Y_ENABLE_PIN 10
#define Y_MIN_PIN 11
#define Y_MAX_PIN 12

#define Z_STEP_PIN 14
#define Z_DIR_PIN 15
#define Z_ENABLE_PIN 16
#define Z_MIN_PIN 17
#define Z_MAX_PIN 18


Thanks!

Please Log in or Create an account to join the conversation.

Time to create page: 0.093 seconds
Powered by Kunena Forum