Tim's Mechanical Spider Leg [LU9685-20CU]

by Palingenesis in Circuits > Robots

8978 Views, 64 Favorites, 0 Comments

Tim's Mechanical Spider Leg [LU9685-20CU]

Spider.png
Tim's mechanical Spider Leg 001.png
Tim's mechanical Spider Leg 000.png
LU9685-20CU.png
Tim's LU9685-20CU Controller 000.png
Tim's Spider Leg and LU9685-20CU

The video is a little long 1 hour, I ramble on a bit.

  • Starts with my wood version of the spider leg.
  • I then show a bit on the IDE I use (Visual Studio 2023 Community) for coding with Arduino.
  • I also show different ways of connecting the new LU9685-20CU Servo Controller with my application.

This is my design for a Spiders Leg.

  • Well, there's not quite the number of joints a Spider has.
  • I wanted to do something where the servo are hidden from view, to give it a more realistic appearance.
  • In my original I used 3D printed parts for the main parts and plastic straws to give it a retro look.
  • It has all the servo together where the hip joint rotates.
  • Now that I have a laser cutter, I have gone for a wood version.

There are 4 servo.

  • One Rotates the Hip.
  • One Rase/Lowers the Hip.
  • One Moves the Knee Joint.
  • One Moves the Ankle Joint.

To control the servo I am using the new LU9685-20CU Servo Controller.

  • The LU9685-20CU is like the PCA9685 in function only.
  • At the hart of the LU9685-20CU is a microcontroller from the STC8H family of microcontrollers.
  • You can communicate with an LU9685-20CU via I2C or UART.
  • No special Libraries are required, you just send values.
  • I have made an Application to control the LU9685-20CU similar to the one I made for the PCA9685.

This Instructable is a two in one.

  • I'll give instruction to build my Spider Leg (repeat eight times for a spider).
  • I will also explain how to use the new LU9685-20CU.

Supplies

_Laser CNC.png
_My 3D Printer.png
Plywood.png
Micro servo SG90_photo.png
LU9685-20CU.png
Arduino NANO LCD I2C.png
Plastic Hollow Sticks 3.4D.png
Dupont Cable.png
PVA Glue.png
Card.png
USB to Serial.png
Bluetooth_Module_4_Pin.png
Bluetooth_Dongle.png

A Laser Cutter and a 3D Printer is required to make this projects.

  • I have printed the Plastic Parts out of PLA.
  • I use A3 sheets of Plywood.
  • I also used some card for shims. (Old Cornflake packet about 0.5mm thick)

Four SG90 Servos are require per leg.

  • I have used cheep plastic geared servo, more expensive ones will be better.
  • 0.8mm diameter (20 AWG) Spring Wire, for connecting links to the horns of the Servo.

To control the servos I am using the new LU9685-20CU Servo Module.

An Arduino is required if you want to control the servos via I2C.

  • Using an Arduino and I2C, you can have up to 32 Servo modules connected.
  • To make it easy for connecting I am using an Arduino NANO and a breakout shield.
  • I have my Arduino NANO and Shield mounted to a 3D Printed Mount to hold an I2C Bus and LCD(I2C).

You can use a USB to UART module to control one LU9685-20CU Servo Module direct.

For the hinge pins I have used Lolly-Pop-Sticks.

  • These are about 3.5mm diameter hollow plastic tubes. (not the solid ones)

Some glue to glue the wood together.

  • I just used some PVA Glue the type used for crafts.

Some Dupont Cables to connect things together.

Screws

  • M1.7 x 6mm self tapping screws.

The Mechanism

Servo_1.gif
Servo_2.gif
Servo_3.gif
Servo_4.gif

It is all done with push/pull rods and levers.

The main body of the leg is just a hinge.

  • This hinge is rotated using a Crown and Pinion Gear.

The thee other joints are controlled by Rods and Levers.

  • Hopefully the animations will show how it all works.

Printed Parts

Tim's mechanical Spider Leg 002.png

A few parts need to be 3D Printed.

Here is a list of the printed parts:

  • 1 x Pelvis_Joint.stl
  • 1 x Top_ Pivot_Shaft.stl
  • 1 x Bottom_ Pivot_Shaft.stl
  • 1 x Leg_Pivot_Gear.stl
  • 1 x Leg_Pivot_Gear_Retainer.stl
  • 1 x Leg_Pivot_Pinion_Gear.stl
  • 2 x Servo_Restraint_A.stl (Print one as is, print one opposite handed)
  • 2 x Servo_Link_2-3.stl
  • 1 x Servo_Link_4.stl

Laser Cut Parts

Tim's mechanical Spider Leg 003.png

I have done several files for the Laser Cut Parts.

  • When cutting part on a laser there are things that need to be taken into account.
  • How much does the laser remove? Kerf.
  • How much larger does a hole need to be for a piece to fit snugly?

Depending on the machine cutting the parts and the software used, some times files have to be modified to account for the above.

  • My Laser Cutter is a Desktop Diode Laser CNC Machine, it cuts with a Kerf of 0.2mm.
  • This gives me a good tolerance fit of the pieces. I do not need the software to adjust Kerf or enlarge holes.

To this end I have made different versions of the files.

  • I have a cut all file that I use on my machine. 00_Cut_All.dxf
  • I have done a cut all to use for having them made out, this file has the holes bigger and all parts are spaced apart. Cut_All_Out.dxf
  • The single part files are drawn as is, so that they can be edited to suit your needs.

There is also some Shims.dxf needed, I cut these out of 0.5mm card. There is a file for the shims it has more shims than needed.

  • I put a lot in the file because small 0.5mm shims get lost easily.

Number required per leg (3mm Plywood)

  • 25 x Round_Spacer.dxf
  • 1 x Toe.dxf
  • 2 x Knee.dxf
  • 4 x Knee_Brace.dxf (two are used in the Hip_Top)
  • 2 x Knee_Top.dxf
  • 2 x Knee_Top_Brace.dxf
  • 1 x Knee_Cap.dxf
  • 2 x Hip.dxf
  • 2 x Hip_Brace.dxf
  • 2 x Hip_Top.dxf
  • 1 x Hip_Bottom.dxf
  • 2 x Servo_Knee_Link.dxf
  • 2 x Servo_Toe_Link.dxf
  • 3 x Spacer_Link.dxf
  • 1 x Spider_Body_Top.dxf
  • 1 x Spider_Body_Bottom.dxf
  • 1 x Spider_Body_Back.dxf
  • 2 x Spider_Body_Sides.dxf

I also made a stand for testing a leg.

  • 2 x Stand_Base.dxf
  • 2 x Stand_Brace.dxf
  • 2 x Stand_Post.dxf
  • 1 x Stand_Top.dxf

If your material is not exactly 3mm thick, you may want to adjust the holes to suit.

Joints (Hinge)

Tim's mechanical Spider Leg 004.png

The general rule for all joints is:

  • The outer parts have a tight fit hole for the hinge pin to hold it in place.
  • The hinge pins are made from 3.5mm diameter hollow plastic tubes (lolly pop sticks) Trim flush after fitting.
  • The inner parts have a slack slack fitting hole so that they can easily rotate around the hinge pin.
  • I ream the slack fitting holes with a 3.5mm drill bit.
  • Between each part including spacers is a card shim (0.5mm).

Don't glue any of the pins in place, if the holes have been cut correctly, the pins should be a tight and slack fit where necessary.

  • If this is not the case and all holes are slack, some glue should be done to the outer parts.

Wood Pre Assembly

Tims mechanical Spider Leg 005.png
Tims mechanical Spider Leg 006.png
Tims mechanical Spider Leg 007.png
Tims mechanical Spider Leg 008.png
Tims mechanical Spider Leg 009.png

The "Spider Body Assembly"

This consists of:

  • 1 x Spider_Body_Top.dxf
  • 1 x Spider_Body_Bottom.dxf
  • 1 x Spider_Body_Back.dxf
  • 2 x Spider_Body_Sides.dxf
  • 1 x Leg_Pivot_Gear.stl
  • 2 x M1.7 x 6mm screws

Glue the base, back and two sides together, leave the top until the leg is done.

  • Screw the Leg_Pivot_Gear to the underside of the Spider_Body_Top using two screws.

"Hip Assembly"

This consists of:

  • 2 x Hip.dxf
  • 2 x Hip_Brace.dxf

Glue the two Braces in between the two Hip parts.

"Hip Top Assembly"

This consists of:

  • 2 x Hip_Top.dxf
  • 2 x Knee_Brace.dxf

Glue the two Braces in between the two Hip Top parts.

"Knee Assembly"

This consists of:

  • 2 x Knee.dxf
  • 2 x Knee_Brace.dxf

Glue the two Braces in between the two Knee parts.

"Knee Top Assembly"

This consists of:

  • 2 x Knee Top.dxf
  • 2 x Knee_Top_Brace.dxf

Glue the two Braces in between the two Knee Top parts.

Wire Servo Links

Tims mechanical Spider Leg 018.png
Tims mechanical Spider Leg 017.png
Tims mechanical Spider Leg 016.png
Tims mechanical Spider Leg 019.png

There are three Servo Links

  • 2 x Basic (Servo_Link_2-3.stl) at 35mm centres to make Servo Link 2 and Servo Link 3
  • 1x Extended (Servo_Link_4.stl) at 28mm centres to make Servo Link 4

The wire is bent as shown.

  • To secure the wire into the plastic Servo_Link_2-3.stl and Servo_Link_4.stl, I warmed up the plastic around the wire and squeezed with pliers until the plastic was cold to clamp the wire in place.

The forth servo has the Leg_Pivot_Pinion_Gear.stl fixed to a four leg horn clipped down using two M1.7 x 6mm screws.

The servo are shown at the 90 degree position.

  • Some adjustment may be needed.

Assembly [Knee to Toe]

Tims mechanical Spider Leg 010.png

Using:

  • 1 x Toe.dxf
  • 1 x Knee Assembly.
  • 1 x Knee Top Assembly.
  • 2 x 3.5mm Plastic Hollow Tube.
  • 2 x Round_Spacer.dxf
  • 6 x Card Shims

Assemble the Toe to the Knee Parts.

Assembly [Hip Bottom]

Tims mechanical Spider Leg 011.png

Using previous and:

  • 1 x Hip_Bottom.dxf
  • 1 x 3.5mm Plastic Hollow Tube.
  • 2 x Round_Spacer.dxf
  • 4 x Card Shims

Assemble the Hip Bottom to the Previous Parts.

Assembly [Knee Cap]

Tims mechanical Spider Leg 012.png

Using previous and:

  • 1 x Knee_Cap.dxf
  • 1 x 3.5mm Plastic Hollow Tube.
  • 2 x Card Shims

Assemble the Knee Cap to the Knee Top Assembly.

  • The widest side of the Knee_Cap.dxf is to the top.

Assembly [Hip]

Tims mechanical Spider Leg 013.png

Using previous and:

  • 1 x Hip Assembly.
  • 1 x 3.5mm Plastic Hollow Tube.
  • 2 x Round_Spacer.dxf
  • 6 x Card Shims

Assemble the Hip Assembly to the Previous Parts.

Assembly [Hip Top]

Tims mechanical Spider Leg 014.png

Using previous and:

  • 1 x Hip Top Assembly.
  • 1 x 3.5mm Plastic Hollow Tube.
  • 2 x Round_Spacer.dxf
  • 4 x Card Shims

Assemble the Hip Top Assembly to the Knee_Cap.dxf.

Assembly [Servo Knee Link]

Tims mechanical Spider Leg 015.png

Using previous and:

  • 2 x Servo_Knee_Link.dxf
  • 1 x 3.5mm Plastic Hollow Tube.
  • 2 x Card Shims

Assemble the Hip Top Assembly to the Hip_Bottom.dxf.

Assembly [Servo Link 3]

Tims mechanical Spider Leg 021.png

Using previous and:

  • 1 x Servo Link 3
  • 1 x 3.5mm Plastic Hollow Tube.
  • 2 x Card Shims

Assemble theServo_Link_2-3.stl to the two Servo_Knee_Link.dxf

Assembly [Servo Link 2]

Tims mechanical Spider Leg 022.png

Using previous and:

  • 1 x Servo Link 2
  • 1 x 3.5mm Plastic Hollow Tube.
  • 4 x Round_Spacer.dxf
  • 6 x Card Shims

Assemble the Servo Link 2 to the Hip Assembly

Assembly [Toe Linkage]

Tims mechanical Spider Leg 023.png

Using previous and:

  • 3 x Spacer_Link.dxf
  • 2 x Servo_Toe_Link.dxf
  • 2 x 3.5mm Plastic Hollow Tube.
  • 8 x Round_Spacer.dxf
  • 23 x Card Shims

This bit is a little bit tricky to put together, you may want to glue some bits together before assembly.

  • All Highlighted parts move in unison.
  • The highlighted Pin should be a slack fit through most of the parts, only one of the Servo_Toe_Link.dxf needs to grip it to hold the Pin in place, you will need to remove this Pin later to fit the leg to the Pelvis_Joint.stl

At this stage I left the Highlighted Pin long and just squashed (deformed) the ends to it did not fall apart.

Assembly [Servo Link 4]

Tims mechanical Spider Leg 024.png

Using previous and:

  • 1 x Servo Link 4
  • 1 x 3.5mm Plastic Hollow Tube.

The Pin should be a tight fit into the two Servo_Toe_Link.dxf, the Servo Link 4 should be a slack fit onto the Pin.

  • Servo Link 4 will stay in place once the leg has been fitted to the Pelvis_Joint.stl

Servo

Tims mechanical Spider Leg 025.png

Using:

  • 4 x Servo (3 with normal Horns and one with a cut down 4 legged Horn)
  • 1 x Pelvis_Joint.stl
  • 2 x Servo_Restraint_A.stl (Print one as is, print one opposite handed)
  • 2 x M1.7 x 6mm self tap screws.

All the horns on the servo in the image should be placed as shown when the servo are set at the 90 degree positions.

  • I have numbered the Servo in the image for further reference.
  • Notice there is a piece of the Pelvis_Joint.stl that needs removing.


Hip Plastic Parts

Tims mechanical Spider Leg 026.png
Tims mechanical Spider Leg 027.png

Using previous and:

  • 1 x Top_ Pivot_Shaft.stl
  • 1 x Bottom_ Pivot_Shaft.stl
  • 1 x Leg_Pivot_Gear.stl
  • 1 x Leg_Pivot_Gear_Retainer.stl
  • 1 x Leg_Pivot_Pinion_Gear.stl
  • 9 x M1.7 x 6mm self tap screws.

Fit the Leg_Pivot_Pinion_Gear.stl to the top of the trimmed four legged horn of servo 1.

The Top_ Pivot_Shaft.stl and Leg_Pivot_Gear_Retainer.stl are fitted to the top of Pelvis_Joint.stl

  • I have put holes in the top of Spider Body Assembly to access the Top_ Pivot_Shaft.stl screws, should disassembly be required at a later date.

The Bottom_ Pivot_Shaft.stl is fitted to the underside of the Pelvis_Joint.stl

Leg to Pelvis Joint

Tims mechanical Spider Leg 028.png
Tims mechanical Spider Leg 029.png

The Large Pin that was just crimped at the ends will need to be carefully removed to fit the Leg to the Pelvis_Joint.stl

You will need to to remove and re-fit the Pins holding Servo Link 2 and Servo Link 3 to fit the Wires into the Servo Horns.

  • It was easier for me to explain where the Servo Link 2 and Servo Link 3 fit doing it earlier.
  • Servo Link 4 should just pull off the end of the pin, and a slight bit of bending to re-fit it.

Leg to Body

Tims mechanical Spider Leg 030.png
Tims mechanical Spider Leg 031.png

Fit the Leg into the Body and glue the top in place.

  • I have put holes in the top part of the body to gain access to some screws if disassembly is required at a later date.
  • You may want to just fix the top part in place with a rubber band until you have made any adjustments needed to the servo horns.
  • On the back part of the body are 4 holes to mount your leg to your creation, what ever you want to make. I may go for a scorpion instead.

Time to Control It [Tim's LU9685-20UC Servo Controller]

Tims LU9685-20CU Controller 000.png
Tims LU9685-20CU Controller 001.png
Tims LU9685-20CU Controller 002.png
Tims LU9685-20CU Controller 003.png
Tims LU9685-20CU Controller 004.png

To control it I am using a LU9685-20CU Servo Module.

  • I don't think they make the PCA6985 chips anymore now that we have the Intelligent LEDs.

I think the LU9685-20CU Servo Module is a new module and will be more popular due to is features.

  • LU9685-20CU is not the name of the chip, there is a powerful Microcontroller at its heart, from the STC8H family of Microcontrollers.
  • Communication can be done via I2C or UART connections.
  • The LU9685-20CU Servo Module does not need a library to communicate with it, values are sent direct.

I have written an Application to aid in the control of the LU9685-20CU Servo Module.

  • The application can be use as the main way of controlling the LU9685-20CU Servo Module, but my intention is for it to be an aid in creating you code to control you creations.
  • I have put some info in the application to help.

The application can be downloaded from my Blog:

If you look at the screen shots you will see that I have corrected the commands used to control the LU9685-20CU Servo Module.

  • The Chinese translation of the instructions that you get from the eBay shop where I purchased the modules had some things mixed up between the two connection methods.

I have attached the Data Sheet for the STC8H Family of Microchips.

Downloads

Voltages

Tims LU9685-20CU Controller 005.png
Tims LU9685-20CU Controller 006.png

As you may have seen in one of the previous screen shot, the STC Microcontroller can run at voltages of 1.9 to 5 volts.

I will be assuming that we are all using 5 volts Servo and 5 volts Logic.

If you look at the circuit diagram that I found for this Module

  • It shows a 5 volts Linear Regulator, This is useless if you are using 5 volts power to power 5 volts Servo. There will be a voltage drop through the Regulator, so you wont have 5 volts powering the Microcontroller, which in turn won't be giving a5 volts PWM.
  • My module came with a 3.3 volts Linear Regulator on it. This will be nice if I was using a 3.3 volts Microcontroller (like an EPS32) to talk to this Microcontroller, but there are other implications like boosting the PWM. We are not going there in this Instructable, we are using 5 volts all round to keep things simple.
  • So, what ever Linear Regulator you have on your module does not matter, because we are not going to use it.

Power To the servo will be by the way of the Terminals or Pins for the Servo

  • In the image I am powering the servo from spare Servo terminals I am not going to use for ease.
  • In the image I have connected a USB to UART Module. This is the easiest and quickest way to get started.

Power to the LU9685-20CU Servo Module Microcontroller will be by way of Pin DVCC

  • Powering the Microcontroller with 5 volts will give a 5 volts PWM output.

UART Circuit [USB to UART Module]

LU9685-20CU USB to UART_bb.png
LU9685-20CU USB to UART_schem.png

I have done the connections using Fritzing so that it is clear.

This is the simplest way to connect to the LU9685-20CU module.

  • Note using UART is a one to one connection. One UART Serial can only talk to One LU9685-20CU module.

Connect it all as shown in the Fritzing diagrams. (The number of servo is your choice)

  • If the USB to UART module has a jumper to set the voltage set it to 5 volts.
  • Servo use quite a bit of power, so it is best to have a good power supply for the servo.

You should now be able to control the servo with my application.

  • Set the Mode to UART.
  • Turn Off "Use Handshaking"
  • Set the COM Port to the one allocated to the USB to UART module.
  • Set the Baud rate to 9600. This is the speed the LU9685-20CU module UART communicates.
  • As we are connecting direct using hardware, we need to set the baud to that of the LU9685-20CU module.

UART Circuit [Arduino]

LU9685-20CU Arduino UART_bb.png
LU9685-20CU Arduino UART_schem.png

I have done the connections using Fritzing so that it is clear.

This is using a Microcontroller (Arduino) to pass on USB to Soft Serial.

  • Note using UART is a one to one connection. One UART Serial can only talk to One LU9685-20CU module.
  • As we need to talk to the Microcontroller using the main USB connection which uses the Microcontrollers main UART, we need to create another UART connection.
  • In this setup I am using the "SoftwareSerial" library to create a second UART on pin D6 (TX) and pin D7 (RX).

Connect it all as shown in the Fritzing diagrams. (The number of servo is your choice)

  • Power to the LU9685-20CU microcontroller is from the Nano.
  • Servo use quite a bit of power, so it is best to have a good power supply for the servo.

You should now be able to control the servo with my application.

  • Set the Mode to UART. (The commands for UART are different to I2C )
  • Turn On "Use Handshaking" Becouse we need to know when the Arduino is ready for another command we need to use Handshaking. My application uses "ok" as a ready signal from the Arduino.
  • Set the COM Port to the one allocated to the Arduino.
  • Set the Baud rate to the Main UART speed. This is the Hard Serial of the Microcontroller.
  • The code I have written for this Instructable, I have set it to 9600, the same as the LU9685-20CU module.
  • This is the speed the LU9685-20CU module UART communicates.

Arduino Code

I am using the same code for the Arduino UART Connection as I am using for the Arduino I2C connection.

  • There are some things in the code that need changing.
  • I have done a Step about the code.

I2C Circuit [Arduino]

LU9685-20CU Arduino I2C_bb.png
LU9685-20CU Arduino I2C_schem.png

I have done the connections using Fritzing so that it is clear.

This is using a Microcontroller (Arduino) to pass on USB to I2C (Inter-Integrated Circuit).

  • Using I2C enables you to connect more than one LU9685-20CU module.
  • In this setup I am using the "wire" library to create an I2C bus on pin A4 (SDA) and pin A5 (SCL).
  • The address for I2C starts at 0x80 (128) + up to 31 more.

Connect it all as shown in the Fritzing diagrams. (The number of servo is your choice)

  • Power to the LU9685-20CU microcontroller is from the Nano.
  • Servo use quite a bit of power, so it is best to have a good power supply for the servo.

You should now be able to control the servo with my application.

  • Set the Mode to I2C. (The commands for I2C are different to UART)
  • Turn On "Use Handshaking" Becouse we need to know when the Arduino is ready for another command we need to use Handshaking. My application uses "ok" as a ready signal from a microcontroller (Arduino).
  • Set the COM Port to the one allocated to the Arduino.
  • Set the Baud rate to the Main UART speed. This is the Hard Serial of the Microcontroller.
  • The code I have written for this Instructable, I have set it to 115200. This is what I have set it to inn the code.
  • We can talk to the Microcontroller at whatever the microcontroller can handle.

Arduino Code

I am using the same code for the Arduino UART Connection as I am using for the Arduino I2C connection.

  • There are some things in the code that need changing.
  • I have done a Step on about code.

Arduino Code

LU9685-20CU Arduino Code 001.png

I am going to assume you know about Arduino.

I have written just one Arduino file, but depending on how you want to connect the LU9685-20CU module, some things may need changing.

  • I have tried to make it easy to change the code.
  • I have made "definitions" to comment or un-comment.
  1. #define DEBUG - Leave this as is, This sends back conformation of the command sent.
  2. #define HAS_LCD - I have an I2C LCD attached to my Arduino Nano, This displays the command sent. Comment this out if you don't have an I2C LCD connected.
  3. #define I2C_CONNECTION - This is 1 of 2 choices, Comment out if using UART connection.
  4. #define UART_CONNECTION - This is 2 of 2 choices, Comment out if using I2C connection.

Only one of these two I2C_CONNECTION or UART_CONNECTION should be active.

What the code does is:

  • Receives the command via the USB.
  • Then sends the command on to either the Soft UART or the I2C bus.

Remember to put the LU9685_20CU_Universal.ino file inside a folder with the same name.

/*
This is a little sketch for using the new Servo Controller LU9685-20CU
This is controling the LU9685-20CU via I2C via Serial.

By Tim Jackson.1960 https://www.timsnet.co.uk/

Use with Tim's LU9685-20CU Controller.
Commands are sent to the Arduino via Serial, then passed on to the LU9685-20CU via I2C.

Below is what I use for Visual Studio 2022
It is for the Inteli-sence to be able to read Arduino Libraries.
It is not needed for the Arduino IDE.
#include <Tims_Arduino_NANO.h>

Below this is DEBUG and HAS_LCD
Comment out HAS_LCD if you don't have an I2C LCD connected.
DEBUG sends back Feedback to my controller.

I2C_CONNECTION or UART_CONNECTION
Only one ov thes should be active.
*/

#define DEBUG
#define HAS_LCD
#define I2C_CONNECTION
//#define UART_CONNECTION

#include <Wire.h>

#ifdef HAS_LCD
#include <LiquidCrystal_I2C.h>
#endif /* HAS_LCD */

#ifdef UART_CONNECTION
#include <SoftwareSerial.h>
#endif /* UART_CONNECTION */

/* Serial */
#define MAX_BYTES 24
byte buffer[MAX_BYTES];
byte i2cAddress = 128;
unsigned int no_data = 0;
unsigned int sofar = 0;
bool processingCommand = false;

/* Soft Serial */
#ifdef UART_CONNECTION
const byte UART_RX = 7;
const byte UART_TX = 6;
SoftwareSerial UART_SoftSerial(UART_RX, UART_TX);
#endif /* UART_CONNECTION */

/* I2C LCD */
#ifdef HAS_LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
#endif /* HAS_LCD */

/* One Time Run  */
void setup() {

/* Start the serial port */
#ifdef UART_CONNECTION
Serial.begin(9600);
#else
Serial.begin(115200);
#endif /* UART_CONNECTION */

/* Start the Wire Comunication */
Wire.begin();

/* Soft Serial for UART Connection */
#ifdef UART_CONNECTION
/* Define pin modes for TX and RX */
pinMode(UART_RX, INPUT);
pinMode(UART_TX, OUTPUT);

/* Start the SoftwareSerial object at 9600 baud rate */
UART_SoftSerial.begin(9600);
#endif /* UART_CONNECTION */

/* I2C LCD */
#ifdef HAS_LCD
lcd.init();
lcd.backlight();
lcd.print(" LU9685-20CU  ");
#endif /* HAS_LCD */

}

/* Constant Run  */
void loop() {
if (!processingCommand) {
ReadSerial();
}
}
/* Read from Serial */
void ReadSerial() {
byte c;
if (Serial.available() > 0) {
c = Serial.read();
no_data = 0;
if (c != '\n' && c != '\r') {
buffer[sofar] = c;
sofar++;
}
}
else {
no_data++;
delayMicroseconds(100);
if (sofar && (c == '\n' || c == '\r' || no_data > 100)) {
no_data = 0;

processingCommand = true;
#ifdef I2C_CONNECTION
Send_I2C();
#endif /* I2C_CONNECTION */

#ifdef UART_CONNECTION
Send_UART();
#endif /* UART_CONNECTION */

Initiate_Serial();
}
}
}

/* Initialize Serial */
void Initiate_Serial() {
for (byte i = 0; i < MAX_BYTES; i++) {
buffer[i] = 0;
}
sofar = 0;
Serial.println("ok");
Serial.flush();
processingCommand = false;
}

/* Write the data bytes to the I2C bus */
#ifdef I2C_CONNECTION
void Send_I2C() {

i2cAddress = buffer[0];

#ifdef HAS_LCD
lcd.setCursor(0, 1);/* bottom line */
lcd.print("        ");
lcd.setCursor(0, 1);/* bottom line */
#endif // HAS_LCD

#ifdef DEBUG
for (size_t i = 1; i < sofar; i++) {
Serial.print(buffer[i], DEC);
Serial.print(" ");

#ifdef HAS_LCD
lcd.print(buffer[i], DEC);
lcd.print(" ");
#endif // HAS_LCD

}

#endif // DEBUG

if (sofar) {
Wire.beginTransmission(i2cAddress);
Wire.write(buffer + 1, sofar - 1); /* Skip the first element in buffer  */
Wire.endTransmission();
}
}
#endif /* I2C_CONNECTION */

/* Write the data bytes to the UART Soft Serial */
#ifdef UART_CONNECTION
void Send_UART() {

#ifdef HAS_LCD
lcd.setCursor(0, 1);/* bottom line */
lcd.print("        ");
lcd.setCursor(0, 1);/* bottom line */
#endif /* HAS_LCD */

if (sofar) {

for (size_t i = 0; i < sofar; i++) {

#ifdef DEBUG
Serial.print(buffer[i], DEC);
Serial.print(" ");
#endif /* DEBUG */

#ifdef HAS_LCD
lcd.print(buffer[i], DEC);
lcd.print(" ");
#endif /* HAS_LCD */

UART_SoftSerial.write(buffer[i]);

}
}
}
#endif /* UART_CONNECTION */

LU9685-20CU Module

LU9685-20CU.png
Tims LU9685-20CU Controller 005.png

The LU9685-20CU module can control 16 Servo.

  • This is similar but not the same as the PCA9685 (An LED Driver Chip).
  • The LU9685-20CU module does not need Libraries in the code to communicate with it.
  • The LU9685-20CU module takes command direct. (there is of course a format to the commands)

This module uses a Microcontroller from the STC8H family of Microcontrollers to control the servos.

  • STC Micro 8H1K16
  • 1.9 to 5 volts.
  • FLASH 16 K Byte.
  • DATA RAM 256 Byte.
  • SRAM 1 K Byte.
  • EEPROM 12 K Byte.
  • I2C. Base address = 0x80 + up to 31
  • UART. Set to 9600. Address = 0x00
  • Servo pins PWM default set to 50Hz

You can communicate with one LU9685-20CU via UART Serial.

  • UART commands are different to the I2C commands.
  • UART commands have a header and footer command.

You can communicate with up to 32 x LU9685-20CU via I2C.

  • I2C commands are different to the UART commands.
  • I2C commands do not have a header and footer command.

If you try to scan for the I2C Address with an Arduino I2C Scanner you will not find these modules.

  • The I2C is controlled by the Microcontrollers internal I2C component and the firmware does not reply to an I2C ping.

To get a reply from this module's microcontroller you need to send a Query command.

  • This only works with UART connection.

5 of the microcontrollers JPIO pins are used for selecting different I2C Addresses.

  • None bridged = 0x80 (128)
  • A0 to A5 act as binary values, A0 being the least significant bit.
  • So that's Zero plus 11111 gives a total of 32 Modules.

There are 16 Servo channel GPOI pins broken out from the Microcontroller to control 16 Servos.

  • There are another 4 JPIO that are not broken out. I suspect them to be temperamental.

The Module has a Voltage Regulator to supply power to the Microcontroller from the Servo Power V+.

  • Check the voltage of the regulator.
  • If there is a 3.3 written on it will be 3.3 volts.
  • If there is a 5.0 written on it will be 5 volts.

I don't recommend using the Voltage regulator to power the LU9685-20CU's Microcontroller for Servo of the same voltage as the Microcontroller, there will be a voltage drop through the Linear Regulator.

  • A 3.3 volts Linear Regulator can be useful if you are using a 3.3 volts microcontroller, but there will be other considerations to apply.

The Linear Voltage Regulator has a protection diode on the output pin.

  • The protection diode will protect the Linear Regulator from voltage applied to the DVCC Pin.

Commands

Tims LU9685-20CU Controller 004.png
Tims LU9685-20CU Controller 003.png

Commands to move the servo is simple.

  • There are two versions of command, there is a slight difference depending whether connected via UART or I2C.
  • The commands are sent as bytes.

I2C

To move a servo you send the I2C Address, the Servo Number and Servo Position.

Arduino example code:

Wire.beginTransmission(128); /* I2C Address    */
Wire.write(0);  /* Servo Number   */
Wire.write(90); /* Servo Position */
Wire.endTransmission();

UART (Serial)

To move a servo you send a Header (250) the I2C Address (0), the Servo Number and Servo Position finish with Footer (254).

Arduino example code:

Serial.write(250); /* Header Always 250  */
Serial.write(0);  /* Address Always 0   */
Serial.write(0);  /* Servo Number   */
Serial.write(90);  /* Servo Position   */
Serial.write(254); /* footer Always 254 */


Note!

When communicating with UART (Serial)

  • Do NOT have any solder jumpers Soldered.