Building a Robotic Arm — Part 1


Apparently a quarter life crisis is a real thing. Not wanting to miss out on this phenomenon I decided to build myself a robotic arm. Not the sort of arm that replaces a missing limb, but the sort that are used in factories around the world to pick, place, and construct products.

Unfortunately living in an city quickly shrunk my dream of building a giant robot to a more apartment friendly size. Probably for the best!

I have absolutely no idea what I will use a robotic arm for. I suspect the desire to make one came from watching Simone Giertz and her “Shitty Robots”. These robots are designed to complete a single task, but instead fail spectacularly often resulting is a huge mess.

Since I am mainly interested in electronics and software I opted to buy a kit for the mechanical parts. There are several options out there; searching ebay, amazon, and Alibaba for “robot arm” yields 1000’s of sensible results. Most variants are built around standard hobby servo motors that are typically used in remote control cars and planes. While these motors are not exactly known for their repeatability, smoothness, or accuracy they are very cheap!

I opted for a “Mirocle Aluminium Robot 6 DOF Arm” from amazon which was £22.50. Unfortunately it has subsequently gone out of stock, but searching ebay for “6 DOF robot arm” gives many identical kits.

My kit, like most of the ones I saw, did not come with servos. I ended up buying six super cheap “Tower Pro MG996R” clone servos off ebay for £21.50 delivered. Given the price the servos are actually of reasonable quality, and have metal gears. However, if you are not a cheapskate like me, buy better servos!

Tower Pro MG996R servo with top removed

The servo horns supplied with the servos were plastic. I believe my robot arm kit was supposed to come with some replacement metal ones, but they weren’t in the box. Instead, I purchased some metal ones off ebay relatively inexpensively.

Now I had everything I needed to build the mechanical assembly of the arm. I was very happy to find that no instructions were included with kit. Figuring it out myself is much more fun 🙂

All the parts ready for assembly (Knolling)

Click below to read the next post:

Part 1 — Introduction (You are here)
Part 2 — Building the Mechanical Assembly
Part 3 — Designing the Electronics System (Pending)
Part 4 — Developing the Microcontroller Software (Pending)
Part 5 — Developing the PC control software (Pending)

Beginners Guide to I2C

I2C (or I²C) is a synchronous, half-duplex, serial, communication protocol commonly used to communicate between several integrated circuits on a PCB. I2C is often used to interface between a microcontroller and devices such as temperature sensors, accelerometers, and EEPROMs.

The are two different types of I2C devices, master devices and slave devices. The master controls the I2C bus and sends commands to slave devices on the bus. Slave devices respond to commands from the master. Both master and slave devices can transmit and receive data, however only the master device can initiate a communication event. In most situations there is a single master on an I2C bus, while there can be many slave devices. It is possible to have multiple master devices on an I2C bus, however this is not that common and is outside the scope of this article.

Physical interface

I2C communication uses two wires, SDA (Serial data line) and SCL (Serial clock line). I2C devices connect to the bus in parallel as shown in the diagram below.

I2C devices use open drain outputs for both the SDA and SCL lines. This means that each device can either pull the line low, or allow it to float. When in the floating state pull up resistors are used to pull the voltage of the line up to VCC. The reason for using open drain outputs is that it prevents two devices on the bus from trying to force the line to both VCC and GND at the same time, which would cause a short circuit.

The value for the pull up resistors is typically a trade off between the rise time of the signal and the current draw of the bus. A common choice is 4.7kOhms. If the I2C lines are long or there are many devices on the bus the capacitance of the I2C bus can be high. In order to meet signal rise time requirements the pull up resistance can be reduced (Tau = R*C). As a rule of thumb start around 4.7kohms and reduce the resistance gradually if that doesn’t work.

I2C addressing

Each I2C device has a 7 bit address meaning there are 127 possible addresses (Although some are reserved for special purposes). The address of each device on the bus must be unique. The address of an I2C device is typically set by the manufacturer. Unfortunately there are tens of thousands of different I2C devices available so many devices have conflicting addresses. To get around this some devices allow several of the address bits to be set by connecting pins on the I2C device to VCC (1) or GND (0). The I2C specification also allows for 10 bit addresses, however these are not as common and are outside the scope of this article. If two devices with conflicting non user settable addresses must be used then either two separate I2C buses are required, or each IC must be enabled only when required via a chip select pin (like in SPI communications).

I2C protocol

When the I2C bus is idle both SDA and SCL are HIGH. When a master device wishes to start a communication event it first pulls SDA LOW and then after pulls SCL LOW. This special sequence is known as a start condition and lets all devices on the bus know that the bus is now in use. The stop condition tells all devices that communication is complete and the bus is now free. The stop condition occurs when the master allows the SDA line to go HIGH when the SCL line is already HIGH. The start and stop conditions are shown in the diagram below.

With the exception of the start and stop conditions all other changes of the SDA line occur only when SCL is LOW. Data is clocked into devices on the rising clock edge. The clock (SCL) signal is generated by the master device. Almost all I2C devices support clock speeds up to 100kHz, many support up to 400kHz, and some can go as high as 3.4MHz.

I2C communications transmits data in 8 bit chunks. After the start condition has been set the master device transmits the address of the device it wishes to communicate with. Since the addresses are 7 bits long the address is shifted to the left and the least significant bit it set to either a 0 or 1 depending on if the master device wishes to read (1) or write (0) to the slave device. This is shown in the example below.

After each byte of data is transmitted, the receiving device acknowledges that it received the data and that the communications should continue. The acknowledge takes place on the 9th rising clock edge. The master allows the SDA line to float HIGH. If the slave has successfully received the data it pulls the line LOW, this is known as an ACK. If the slave is not present or is unable to process the data the line is left HIGH, this is known as a NACK (negative/no acknowledge). Read More

Using an HD44780 alphanumeric LCD screen

The Hitachi HD44780 is an LCD screen controller used to control small alphanumeric LCD displays. Many cheaper displays don’t actually use the HD44780 IC. However, they use the same pin-out and control scheme, and therefore can be operated in the same manner.

Connecting the display

Most screens use the following pin-out, however it is best to refer to the screen’s datasheet if available.

1.  Ground
2.  VCC (Normally 5V)
3.  Contrast adjust input (Voltage between VCC and GND)
4.  Register select (For a command RS = 0. For data RS = 1)
5.  Read/Write (To write to the display = R/W = 0. To read = R/W = 1)
6.  Enable
7.  Data bit 0 (DB0)
8.  Data bit 1 (DB1)
9.  Data bit 2 (DB2)
10. Data bit 3 (DB3)
11. Data bit 4 (DB4)
12. Data bit 5 (DB5)
13. Data bit 6 (DB6)
14. Data bit 7 (DB7)
15. Backlight +
16. Backlight -

The screen has 3 main control lines. RS, R/W, and Enable. The RS and R/W lines determine the operation of the screen, as shown in the table below.

The Enable line acts like a clock signal. To clock data in or out of the display the enable line should be set high for 1uS. The enable signal is registered on the falling edge.

The screen has 8 data lines which are used to both read and write data to and from the display. The screen can also operate with 4 data lines, where only DB4, DB5, DB6, and DB7 are used. In this case DB0 to DB3 can be left unconnected. This article will only cover operation of the display using all 8 data lines. Read More