• ### More human-friendly firmware

The revision 2 PCBs are have shipped but are expected to arrive on Tuesday, so unfortunately they won't make it for the Hackaday Prize robotics contest deadline. Meanwhile, I've been tweaking the firmware. The firmware is on Mbed, so you can compile it for other supported microcontrollers as well. I've been using the STM32L073 and STM32L476 MCUs, so these at least have the required PWM functionality on the correct pins.

The EEZYBot ARM MK2 uses three servos to control the arm and a fourth servo for the end effector. The Wii Nunchuck controller has a joystick and two buttons. This essentially allows control of three "axes". Two of these are from the joystick (up/down and left/right) and the third from the two buttons. Originally, my firmware used these three to control the three main servo directly, For example, moving the joystick up/down moved a single servo. This is easy to implement, but it is not very intuitive to use since the end of the arm does not move just horizontally or vertically, but rather along a more complex trajectory.

I thought it would be nice to be able to press up/down and have the end of the arm move just in the vertical direction. This is a little more complex to implement since it involves moving multiple servos and doing some math to figure out how they need to move. The math is just high school trigonometry, as shown in my sketch below. Essentially, I need to calculate the angles α (the sum of α₁ and α₂) and γ, which can be used to calculate the angles of the main arm (l₁) and the little arm labelled l₂.

This math is implemented in the pos_to_angle function:

```void pos_to_angle(double *horz_angle, double *vert_angle, double radius, double height)
{
double alpha2 = acos((bf_2 + L1*L1 - L5*L5)/(2*sqrt(bf_2)*L1));
*horz_angle = PI/2 - (alpha1 + alpha2);
double beta2 = acos((L1*L1 + L5*L5 - bf_2)/(2*L1*L5));
*vert_angle = PI - beta2 - alpha1 - alpha2;
}```

I made a quick video to show the firmware in action:

The firmware first allows you to calibrate, which involves positioning the arm so that the main arm is vertical and the other one is horizontal.  Pressing SWITCH 2 performs the calibration, which saves offsets for each of the servo motors. Note that the firmware is written so that it works with the EEZYBot ARM MK2. To use other robotic arms, you would need to adjust the constants (e.g. l₁) and perhaps the math, if the arm has a different kinematic linkage.

Actually operating the arm is very intuitive. Up/down on the joystick moves the end effector horizontally. The two buttons on the back move it vertically, and left/right on the joystick rotates the arm around the base. To open/close the end effector, pushing the two buttons simultaneously activates another "mode" where up/down on the joystick now opens/closes the end effector.

I'm pretty happy with how the project has gone so far. Assuming that the revision 2 PCBs that are shipping fix the issue with the power enable signal, this project will be done!

• ### Exported Rev 2 Gerbers

Gerbers for revision 2 are done. Changes from the first revision are:

• Changed POW_EN signal to a 5V tolerant pin on the STM32 MCU so that the protection diodes don't clamp the voltage and prevent the PFET from turning off (discussed in the previous log).
• Made the nunchuck connector a little wider. It was too narrow in the first version and I had to file it down a bit.
• Moved some of the PWM signals to different pins. The STM32 MCUs are not fully pin-compatible so I chose pins that have PWM available on more MCUs.
• Added some silkscreen labels for the supply headers (used mainly for debugging).

The PCB is over at GitHub.

• ### Trying out the first PCB

I got the PCBs in the mail this week and soldered one up using the reflow skillet method. So far, it is mostly working. The main issue that I have come across so far is that the power enable signal, which is pulled up to 5 V, has its gate a few hundred millivolts too low when it should be high, so the PFET that it is controlling does not turn off.

I am using pin PA4 on the STM32L476 in open drain mode to control it. I thought that this should work, but unfortunately this pin is not a 5 V tolerant pin. Looking at the datasheet, there are protection diodes on the pin that I believe are causing the issue. This means that the power enable signal unfortunately does not work on this revision of the PCB. It should be connected to a 5 V tolerant pin, also called a "TT" pin in the datasheet, such as PA2.

On a more positive note, the level-shifting circuitry is working. After debugging the above issue I had damaged the top copper layer so I did a messy soldering fix shown below to reconnect the 5V pull-ups. The NFETs convert 3.3V PWM from the micro controller to 5V for the servos. Note that since the FETs are inverting the duty cycle of the PWM signal also needs to be inverted. I was successfully able to move a servo motor, and have started putting together some firmware using the online Mbed compiler. The project is here.

Lastly, I also checked the Nunchuck interface. Unfortunately, the connector is slightly too narrow, so I had to sand it down a bit. But I2C communication worked great using the WiiNunchuck library on Mbed.