Communicating with a Cheap Chinees Caliper
I bought a caliper at the Gamma (dutch D.I.Y.) for Euro 9,80 . It came in a plastic box with foam lining and two battery´s. I wanted to find out if these could be used in a DRO (Digital Read Out) system.
Opening the Caliper
The firmware for the microcontroller
To make some testcode I use a microchip PICDEM2 prototyping board with a PIC16F877.
I wrote the Code in 'C' using the CCS compiler.
I use the hardware SPI of the PIC (RC4,SDI) (RC3,SCL)
Results are dumped to the RS232 (19200bps) port and to the LCD.
Conclusion :
We see that it is very easy to read the value from these calipers.
We need a minimum on hardware interfacing providing voltage level translation.
The base firmware is simple and needs code added to catch all the exceptions, this firmware example can easily be combined with the CCS MODBUS (serial communication bus) routines to connect this caliper to Mach3 (CNC control software).
Connecting a cheap Chinees Caliper to Mach3 over ModBus
To make the cccal firmware run nicely in conjunction with the modbus routines we make SPI reception interupt based and put SPI synchronisation in a state-machine to prevent any dedicated wait locations in the firmware.
You can see the base firmware on the bottom of the page.
Configure Mach3 for ModBus
Make sure the modbus serial bus is activated in Mach3. Tick the box and restart mach3.
To test the modbus we use the 'Modbus Serial Control Monitor' located in the [Function Cfg´s -> Setup serial modbus control] menu. Then select the [Test ModBus] button.
Make sure all the settings are correct Port nr, bitrate, etc. and push the [Read] Button and data should appear in the box on the right.
Once you receive the data its time to display the Caliper data somewhere in the Mach3 screens.
There are several ways to do this , we begin with Macro´s , using the macropump. ( another (better) way is BRAINS )
First we set up mach3 to receive the data and make it available in mach3 through inputs 64.66 (3 words)
The Firmware for the PIC
ToDo list :
Test/streamline firmware , this is just a throw together of some code.
Handle the autopower off of the Caliper. ( We can probably send data to the caliper too )
I bought a caliper at the Gamma (dutch D.I.Y.) for Euro 9,80 . It came in a plastic box with foam lining and two battery´s. I wanted to find out if these could be used in a DRO (Digital Read Out) system.
To interface this signal to a uController we use a simple transistor , ( you can also use a 74LVxx gate they work down to Vcc 1.0Volt) |
Serial Modbus Mach3 Cnc. Free download flowplayer for mac. I created a new Mach3 profile by cloning an existing working profile. Modbus is turned on via the Ports and Pins dialog. Check the Modbus dialog. Mach3 Modbus Function Codes. Serial Modbus Comms Setup Baud rate Serial Port Data Format Modbus Timeout Important!!! Mach3 CNC Controller. 1.Setup Mach3 Modbus. Upload firmware To Arduino. Run 'Modbus Serial Tester' เพื่อทำการทดสอบ Modbus.
First step, look with oscilloscope at data coming from caliper. In the scope image below we see a Clock signal (ch2) Data signal : (ch1) caliper displaying 0.00mm Data signal : (chA) caliper displaying 0.01mm Voltages ~1.5 volt Data should be clocked in on rising flank. LSBit is send first Signals normaly high (also when caliper is OFF) |
A frame is made up of 6 nibbles / 3 Bytes / 24 bits. Framelength is about 15msec. Frames a send every 200msec. The pictures to the right show [1.68mm] binary 168 = 128+32+8 lsb-> 00010101 <-msb Pushing the Inch/mm button we see bit 23 (last bit) of the frame toggle. when a measurement becomes negative we see bit 20 toggle. |
Opening the Caliper
Remove the sticker from the backside. Remove the 4 screws. Carefully lift the plastic housing from the metal caliper-base. We now se the backside from the pcb where the measuring surfaces are. Remove the two rubber dust/dirt sliders left and right. Remove the 4 screws. Carefully lift the pcb from the plastic housing. Don´t bump the lcd, you want it to stay |
We solder some wires to the pcb : Black - Ground Orange - Data Brown - Clock Red - Supply (Soldered at Capacitor) note. Both outer pad´s are Ground |
The firmware for the microcontroller
To make some testcode I use a microchip PICDEM2 prototyping board with a PIC16F877.
I wrote the Code in 'C' using the CCS compiler.
I use the hardware SPI of the PIC (RC4,SDI) (RC3,SCL)
Results are dumped to the RS232 (19200bps) port and to the LCD.
Conclusion :
We see that it is very easy to read the value from these calipers.
We need a minimum on hardware interfacing providing voltage level translation.
When using the caliper hardware in a CNC (lathe/mill) enviroment or other harsh situations extra hardware is needed (esd-protection, optocouplers, DC-DC converters, TIA485 bus, etc.)
The base firmware is simple and needs code added to catch all the exceptions, this firmware example can easily be combined with the CCS MODBUS (serial communication bus) routines to connect this caliper to Mach3 (CNC control software).
Connecting a cheap Chinees Caliper to Mach3 over ModBus
To make the cccal firmware run nicely in conjunction with the modbus routines we make SPI reception interupt based and put SPI synchronisation in a state-machine to prevent any dedicated wait locations in the firmware.
You can see the base firmware on the bottom of the page.
Configure Mach3 for ModBus
Make sure the modbus serial bus is activated in Mach3. Tick the box and restart mach3.
To test the modbus we use the 'Modbus Serial Control Monitor' located in the [Function Cfg´s -> Setup serial modbus control] menu. Then select the [Test ModBus] button.
Make sure all the settings are correct Port nr, bitrate, etc. and push the [Read] Button and data should appear in the box on the right.
Once you receive the data its time to display the Caliper data somewhere in the Mach3 screens.
There are several ways to do this , we begin with Macro´s , using the macropump. ( another (better) way is BRAINS )
First we set up mach3 to receive the data and make it available in mach3 through inputs 64.66 (3 words)
Writing a Macro go to menu [Operator -> VB scripts editor] this will open the Visual Basic editor. We receive data in input 64, 65 and 66. input 66 is the LSbyte input 65 is the MSbyte input 64 has the flags Neg, inch/mm On the right we see the result of the macro. The caliper displays 10.78mm on its displays. through the modbus mach3 received the same data. It is then displayed on the main X axis DRO (has nr 0) . |
Finishing the Macro When you get some numbers you can add the negative and inch/mm bits. Save the macro as [macropump.m1s] if you want to run it as a macropump. To run the macropump activate it in menu [Config -> General Config] and active the tickbox [run macropump]. You have to restart Mach to make it active. You should now see you X-axis DRO display the caliper information. |
The Firmware for the PIC
ToDo list :
Test/streamline firmware , this is just a throw together of some code.
Handle the autopower off of the Caliper. ( We can probably send data to the caliper too )
I will describe here how to connect arduino directly to mach3 without any additional hardware.
This will not use any modbus library it is just proof of working. You will end up with ability of mach3 to read input pin on arduino. https://fashionclever561.weebly.com/boot-usb-mac-os-x-download.html. But if this will work for you then adding full modbus library for proper comunications shouldnt be any problem.
Serial Modbus Mach3 Cnc
Gv r9200 driver for mac. Small think about modbus
Modbus is software protocol not hardware, so you can use it not only ower rs232 or rs485 but also let say uart usart. Doesnt matter the amount of connections the hardware protocol uses, basicaly it boils down to one comunication line for half duplpex and two for full duplex.
Sheet Cam
The comunication of mach3 with arduino will be done using uart. Mac legacy software no longer installed. so rx tx lines.
In this case the standard Usb cable connecting pc and arduino will do.
Free down load kendara porondam soft wear. https://celestialminder.weebly.com/download-apps-to-mac-desktop.html. But you can buy USB to rs485 adapter and connect to rx tx lines and it should be basicaly the same think.
Mini Modbus Board
On the image is the whole setup. Arduino connected to PC + one led but you dont need the LED (it is just indicator so i know what information should be send back from arduino) and cable so you can ground a pin on arduino. Serial killer crime scene images. Led should have resistor in series, i just coudnt be bothered and the led suvived.
On left side of image is the USB to rs485 adapter (you dont need that). i just wanted to add it in case you wanted to know what the one i have looks like. and it works fine. i was trying it with some rs485 hardware.
On left side of image is the USB to rs485 adapter (you dont need that). i just wanted to add it in case you wanted to know what the one i have looks like. and it works fine. i was trying it with some rs485 hardware.