Help refining firmware for project

Hello all,

I'm working on an open source robot project geared for K-12 learners. The robot and control box are laser cut. The main repository is here for all files 2D, 3D and firmware: GitHub - davidcool/Mr-Roboto: Laser cut micro-controller based robot toy

I'm rough around the edges writing firmware. I have the base going but would love help refining/rewriting the firmware or suggestions on how to improve it. I'd love a collaborator or two if someone is willing.

Here's what I have so far: Mr-Roboto/robot_firmware_v5.ino at master · davidcool/Mr-Roboto · GitHub

Everything works, although not super refined.

The only real problem has been servo jitter, which is pretty bad. I'm using SG90 Servos Datasheet. Besides more elegant code, I'd really like to solve this issue. Here's some things I've tried so far after research:

  • Various power supplies... I'm currently using a 5V 3A wall power supply.
  • I've tried adding a 1000uF cap on between the positive/negative rails feeding the servos incase there was a spike.
  • I've also tried a single wrap of the servo wire on a ferrite core as suggested by someone who used this method with some success... They used 3 wraps, my was kind of rigged w/ only one, so not sure about this.

My suspicion is that my problems are code based, but I'd love input... I'm sure I'm not giving details the someone will want to know, let me know what I'm missing.

I've included some pics of the circuit. I'm using the copper tape as power rails so 4-5 graders can easily solder.

Also, this robot is connected to another project which is a MIDI touch sensor keyboard. The repository is here: GitHub - davidcool/Mr-Touch-Key: A laser cut touch MIDI keyboard project

In one mode playing the keyboard will make the robot "dance" and in another mode the robot dancing will play random notes on the keyboard. I'm connecting them via serial.

Just added a (terrible) quick drawing of circuit...

Thank you!






How to post images so that they don't need to be downloaded.

It would be best to connect the servos to the output of the 5V 3A power supply. Is that where they are connected?

Yeah, sorry, that drawing was quick... Everything is running from the 5V 3A supply... The 5V runs to the RAW pin on the arduino as well.

The 5V runs to the RAW pin

The RAW pin is connected to the input of the 5V regulator. The supply to the regulator needs to be about 7V for the regulator to operate properly. Feed 5V to the 5V power input.

Hi

Quick question is the jitter across the range of the servo movement or at one of the ends?

I ask this because I have found with the cheap SG90 clone servos assembly quality control is not all that great and the standard timings for min and max pulse width can overdrive the motors into the end stops. You can work around this by tuning the minimum and maximum pulse widths with the Servo.attach(pin, min, max) call. As well as specifying the pin you can also specify the min and max pulse width values.

If memory serves me correctly minimum controls the anti-clockwise position and maximum controls the clockwise position. Default values are 544us and 2400us

For example a servo that chatters at the anti-clockwise position:-

// Original code
// myServo1.attach(servo1Pin);

//Improved code
myServo1.attach(servo1Pin, 560, 2416); // An offset of 16us was required to stop the chattering

If this is the case it should be fairly easy to write a simple calibration sketch that would printout a set of offset values to import into your main sketch. This could be supplied as part of the kit which would allow the students to tune their robot. It could also lead into a discussion on manufacturing tolerances.

Ian

@groundfungus So run the 5V to VCC? Should I put something in between to protect the processor? Could the servos spike a voltage or something along those lines?

@IanCrowe I'll start some tests around your suggestions... But it doesn't just happen at the extremes, it happens in the middle more actually... Two of the servos have almost no jitter, but when one of the servos (the arms) come down a little over half way, it starts jittering and all the other join in... It lasts several seconds and then all the jittering stops.

It would be best to have separate Arduino and servo power supplies, with common grounds of course.

At least test that situation to see if that solves the problem, i.e. temporarily with a 9V block battery (won't last long) on the Arduino RAW input and the 5V supply for the servos.