Page 1 sur 23

Jedicut and Arduino over USB

Posté : ven. sept. 07, 2012 12:40 pm
par Martin
Hi again,

now starting with the basics. The purpose of the new jedicut plugin USBSerial is to use jedicut on PC's and Laptops without a parallel Interface, which is nowadays more and more the case. But all PC's have a USB-interface which can be used.
A second target was to do the timing for the stepper motors and a possible PWM Modulation for the wire heating not on the PC because of the timing lags which will occur on e.g. windows and slower PC's.
To achieve this targets a low cost well known microcontroller system, the arduino, will do the job. It (e.g. the arduino uno) will have an integrated USB-interface and enough ports to handle most parallel port stepper motor boards and do additional tasks like PWM for wire heating. The development environment for arduino is free and well documented.

To start with USBSerial the following hardware parts are necessary:

1x Arduino uno board with USB cable (normally around 30€, but I think hobby king in china, sells them now for 15$ with cable)
1x Connector to your Stepper board (e.g. a 25 pin Sub-D connector, ~2€)
1x Connector to arduino board (header with ~20pin, ~2€)

Now short wires need to be soldered between the arduino and the stepper board connectors.
For the letmathe mdlcnc board I did it as follows:
[pre]
Arduino uno LPT Sub-D connector
12 1 All motors On/Off
8 2 X step
9 3 X direction
10 4 Y step
11 5 Y direction
4 6 Z step (X2)
5 7 Z direction (X2)
6 8 A step (Y2)
7 9 A direction (Y2)
GND 18-25 Ground
[/pre]

If this is done, all hardware parts are ready and the software part can be started.
Other boards my need a different wiring and an adapted arduino software too.
I will explain the software part in the next post:)

Re: Jedicut and Arduino over USB

Posté : lun. sept. 10, 2012 9:39 am
par Martin
If the hardware is ready it may look like my prototype:
jeduinok.jpg jeduinok.jpg Vu 30088 fois 45.74 Kio
Now I want to explain the interface definition, the commands which will be exchanged between the jedicut plugin and the arduino.
The serial Parameters are 115200 baud 8 bits no parity 1 stop bit.
I am using 2 bytes per command. The first byte is the command name and the second byte the parameter.
With two bytes per command and a rate of 115200 baud a maximum rate of of around 5000 commands per second is possible.

For Example:
0x48 0x24 is the ascii value for 'H' followed by the value 0x24=36 for the value -- This means Wire heating with value 36

[pre]
The commands currently sent from the plugin are:

'A' with parameter '1' or other value -- all Motors on/off ('1' on, all other values means all Motors off)
'H' with parameter 0 to 255 -- Wire heating (0 means off, 255 full)
'F' with parameter 0 to 255 -- Frequency, it is the value entered in the jedicut options for 'Cut speed' respectively 'Fast speed'
'M' with parameter 0 to 255 -- Motor step command, corresponds to the 8 Motor bits (4 direction + 4 Step) defined in the jedicut options for 'Parallel Port' configuration
[/pre]

There are a number of responses defined, which sent from the microcontroller to the plugin. Responses consists only of one byte.
[pre]
The responses are:
'S' -- Stop transmission, the buffer is full, wait for a 'C'
'C' -- Transmission can be continued
'L' -- Limit switch hit (only defined in plugin, but not used)
'A' -- Stop complete cut (only defined in plugin, but not used)
[/pre]
In the next posting I will explain how the current implementation of the plugin and the arduino software are working together.

Re: Jedicut and Arduino over USB

Posté : mar. sept. 11, 2012 10:12 am
par Martin
Back again. First I want to explain the sequences within the plugin side.
A jedicut plugin exports a number of procedures/functions. Important are the procedure MoteurOnOff and the function EmettreBit.
There are a number of internal functions too. The plugin USBSerial has internal functions to open, write, read and close the serial port. Which serial port to use is defined in an ini-file called comport.ini and is located in the same directory as the jedicut.exe is located.
Its content is e.g.
[pre]
[COMPORT]
PORTNUMBER = 4 ;means COM4, usually taken for the virtual port of arduino
[/pre]
When the dll is loaded the serial port will be opened and when it will be unloaded the port will be closed.
Now if jedicut decides to start the movements it calls MoteurOnOff. USBSerial will send out the two byte values 0x41 and 0x31 ('A' and '1'). When the movement is over jedicut calls again MoteurOnOff (with false as parameter) and the USBSerial plugin sends out the values 0x41 and 0x30 ('A' and '0') and the additional command to turn of the wire heating, 0x48 and 0x00 ('H' and 0x00).

The most important function is EmettreBit. This function will be called by jedicut for each step a motor shall be do. This function will receive the values for the cut speed, the wire heating, the motor and the direction to rotate. To save bandwidth on the serial line the commands for wire heating ('H') and cut speed ('F') will only be sent out if the values have changed. The parameter values for 'F' are taken from the settings of cut and fast speed (range 0-255) and for 'H the values are % values (range 0-100%).
Each motor movement is defined by two bits (motor/Step and direction) of a byte. This two bits are given to EmettreBit. If the function is called in succession with different motors (that means different bits of the byte), the bits can put in the same byte. With the first request to the same motor the byte is sent out as parameter to the motor command 'M', so up to four motors will move at the same time. With this optimisation theoretical no sharp corner can be cut, but for now I think its within the tolerances.
In the next part I will talk about the microcontroller side.:)-D

Re: Jedicut and Arduino over USB

Posté : lun. sept. 17, 2012 9:20 am
par Martin
The arduino software in general has two procedures which are called by the arduino system automatically. The procedure setup() is called one time when the arduino boots up, here initialisation tasks like setting the baud rate or defining which pins are in or output shall be located. The procedure loop() is called from the system in a loop, that means if it is left it is immediately called again.

The software for handling the commands from the jedicut plugin consists of two important parts too:
  • The main loop, which polls the serial interface for incoming data. It is identical with the procedure loop(). It writes every two received bytes into a command buffer. If the buffer is filled up to a specific level, an 'S' is sent out to temporarily stop the transmission.
  • The timer interrupt service routine, which is called periodically and handles the commands the main loop has written into the command buffer. If enough commands are handled and enough memory is free in the buffer, a 'C' is sent out to indicate that the transmission can continue.
Using a buffer and a timer have two advantages. The motor commands are given to the stepper board with a very accurate timing and a short lag of the transmission from the plugin to the microcontroller will be survived without disorder of the stepper timing. As long as the PC is fast enough to generate and send out enough commands to fill up the buffer as fast as the cutting speed is set, a very smooth cutting will result. The software uses the onboard LED to indicate a possible underrun of the buffer, in this case the cutting speed need to be lowered a little bit.
Additional the complete pulse necessary to move one step is generated by the microcontroller. Only the direction bit must set correctly (0 or 1) and the corresponding motor/step bit must be set to 1. This reduces dramatically the amount of data sent from the plugin.

The software of the arduino needs to be adapted to the specific board used. In the procedure setup() the pins used for motor step and direction must be declared as output. Other pins e.g. used for wire heating or heating relay or limit switches must declared too.
The handling of the different commands needs to be rewritten to reflect the hardware used, but this is not difficult. I will support everyone who needs help with this task.

My current implementation of the arduino software is specialized to the letmathe mdlcnc board. It supports 4 motors and the relay for heating. PWM and limit switches are not implemented yet, but this would need only little work to implement. I have no switches installed and I make the heating manuel so there was no need to put this functionality into the software. If anybody needs this functionality I will give support to put it in. The cut speed is allowed to set from 0 to 127, which will result in 1000 to 500 steps per second.The relay will be turned on if the heating value is greater zero and turned off when the value is zero or all motors are turned off.

Finally some words about the procedure to 'burn' the software to the arduino board. If you have already the hardware (board and USB cable) you need to install the arduino development environment (its a zip, it must not to be installed only extracted). The homepage of the arduino is arduino software. There the development software can be found.
It includes the driver needed to install when the board is connected to the PC the first time. Then a virtual serial interface is created which you need to enter in the comport.ini file (see above). The arduino software file for foamcutting is called foamcutif.ino. It can simply loaded to the development environment and uploaded/'burned' to the connected board.

Ok, that's it for now. Questions as well as improvements are welcomed. If someone needs help, then I would be happy to assist in solving the problems :)

Re: Jedicut and Arduino over USB

Posté : lun. sept. 17, 2012 2:15 pm
par MAES
Hello Martin,

sorry, my english is not good.

Who can i find the Plugin for Jedicut?

I plan in the winter a board such arduino with a PIC from Microship.
I work many years with PIC's.

It is possible you can make a little flow-diagramm from the Plugin?

Greetings, Manfred

Re: Jedicut and Arduino over USB

Posté : mar. sept. 18, 2012 8:20 am
par Martin
Hi Manfred,

Jerome maintains a google code repository where all the jedicut plugins are hosted. You can find it at Jedicut extension. If you select source and then browse you can see a number of directories. Select branches and then Jedicut_2.3. Under USBSerial you can find all the sources, the C++ as well as the arduino code and ready useable USBSerial.dll in a debug-able as well as a release version.

Concerning the flow diagram I want to forward you to Jerome, who can explain in detail when is which function of the plugin called and with which parameters. What I can do is to post the short descriptions of the plugin functions I got from Jerome:
  • GetDllFamily: return if it's a file plugin or a communication plugin. Look at the svn for all values.
  • EmettreBit: Jedicut call it to send order to the cnc board.
  • MoteurOnOff: some cnc board use a bit to switch on/off steppers, like mm2001.
  • InitialiserChauffeEtCommunication : Jedicut call it to initiate heating settings and communication settings in the plugin (wich bit on wich port number).
  • EtatMachine: read the value on the board and return 0 or 1 if the heating value is controlled manual or by computer.
  • LireChauffeMachine: read the heating value setting up on the cnc board.
  • GetDescription: return a small description of the plugin to print it on Jedicut settings window.
  • AdapterOrdres: i use it in the last step in my algorithm if i want to rework all individual orders calculated by Jedicut. With this the plugin can adapt orders like you want: example, send 4 orders, one by stepper, at the same time.
Liebe Grüße

Martin

Re: Jedicut and Arduino over USB

Posté : mar. sept. 18, 2012 11:36 am
par MAES
Hi Martin,

thank you!!!:)-D

Re: Jedicut and Arduino over USB

Posté : ven. sept. 21, 2012 7:44 pm
par Andy Erwin
thats very cool! what CNC board are you using and will ones on EBAY work with this system? I need to learn the arduino system and get this up and going, I have the foam cutting mechanicals just sitting there, i need to get the electronics set up and this sounds like a great way to go

Re: Jedicut and Arduino over USB

Posté : sam. sept. 22, 2012 9:55 am
par Martin
My CNC board is the MDLCNC from rc-letmathe. It is a board operating on a parallel printer port using the usual step/direction interface. I think every board using this interface can be used, only the arduino code needs to be adapted. When you learn to program the arduino, you will be able to operate CNC boards with completely different interfaces too, but using the standards may the way to start. We will be happy to hear from your progress in mastering the arduino and building up your system. :)

Re: Jedicut and Arduino over USB

Posté : ven. sept. 28, 2012 2:58 pm
par MAES
Hello Martin,

i have install the USB_Serial.dll in Jedicut-Direktory DLL.

When i start Jedicut, i become a Error.
Error_USB.jpg Error_USB.jpg Vu 30087 fois 20.13 Kio
Greetings Manfred