Arduino Leonardo’s style boards, upload and serial terminal issues

Trying to add a bit more wisdom to all the existing information that is around the web based on my tribulations with a SwarmRobot 32u4 based board (core of the Leonardo) and a SeeedStudio Xadow.

As everyone notes, on uploading your code, BOTH the computer AND the Leonardo drop/break the USB connection and then attempt to re-establish. The practical issues that this can cause, is where I had issues and found little information. So here are my 2 cents worth:

If both ends successfully re-connect:-

  • the port may have a different name/number. Recent Arduino programming GUI versions usually auto-detect the change. If not, you may have one of the other issues below.  Older Arduino programming GUI versions did not auto-detect and you had to manually change the port.
  • Sometimes auto-upload works, other times you have to press the Leonardo reset button. It seems to run in streaks, working reliably for auto, then for manual reset. Don’t know how to reliably fix this. Sometimes solutions here work, often not.
  • Sometimes Arduino autodetects the port correctly, but does not select it, so you need to check and select it.

If either end does not re-connect, try:-

  • unplug USB cable, wait a few seconds then replug it in, then recheck port shows correctly in the Arduino GUI
  • sometimes moving USB cable to a DIFFERENT USB port helps
  • close and reopen the Arduino programming GUI, especially if you see red messages like “lib rxtx cannot access the com port”.
  • reboot your computer and power off/on the Leonardo and if you see the above message. Under Windows 7, the following message usually means a computer reboot for me “ Couldn’t find a Leonardo on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board’s reset button after initiating the upload.
  • do all BOTH of the above
  • If the com port is greyed out, try selecting the com port during that brief moment of disconnection and before reconnection after board is reset. Using your operating system sound events for this is very handy!
  • in addition to HID control of mouse or keyboard that you have programmed, I suspect that on some Leonardo style boards active HID control sometimes causes issues. I use a few seconds delay in setup function to avoid this at least while developing my code, in addition to the generally suggested method to easily disabled HID mouse/keyboard control.
  • Sometimes you end up with multiple copies of Avrdude running and using a lot of CPU. For me this occurs occasionally under OpenSuse.
  • All my attempts to get OpenSuse working with Xadow failed for weeks, until I left the Xadow plugged in at computer power on/boot, then ran the Arduino GUI with root privilege, then after that the GUI ran OK with userlevel privileges. I really do not understand why this is so!

MMU 6050 6 axis / 6 DOF gyro and accelerometer interrupt & data summary

The most excellent Xincehjian maker Edward introduced me to the also excellent MMU 6050 that has a 3 axis gyro and a 3 axis accelerometer and in addition has a bucket load of on-board digital motion processing (DMP) to give a huge range of 6 axis (DOF) outputs as well as motion, free fall, tap and shake detection. Amazingly, in China, you can buy it on a break out board for about $4 and get it delivered for another $1, a day or so later.

A popular library for this chip, seems to be the I2cDev library from Jeff Rowberg which not only provides access to this chip, but a HOST of other sensors AND it also provides a generic I2C lib (hence the name I2Cdev) that can and has been ported to many different host processors!

But wait there’s more, the I2cDev library offers a choice of several underlying I2C libaries, and even when using the default Arduino Wire library to provide the I2C, the common blocking – hanging issues that seem to plague many people when using the Arduino Wire library for I2C, have been resolved! I can now run I2C code for many hours, even overnight, instead of previous seconds or rare minutes!

So, I am really stoked, because the MMU 6050 delivers a lot of features that I really want to use (see Assistive devices) and those Wire I2C issues have caused me a lot of grief over the last 2 years as I tried to use several different sensors and motor controllers and even recently when I tried several different libraries, that others have created to get past these issues!

click for the A3 page of information
Screenshot of MMU 6050 interrupts & data summary


But wait there’s still more, there is also the freeIMU library, which I have been using successfully. It sits on top of the I2cDev library and provides additional features.

The last “But wait there’s more” is that as part of trying to get my head around all, well so far some of the above (tap, shake and motion detection), I delved into the documentation and code and summarised my understanding of interrupt configuration, interrupt status, raw data access and access to the DMP data. The document is still a work in progress, so please add comments to this post or contact me with updates and corrections!

Assistive devices and “Helper sessions” at Xinchejian

Kicked off establishment of “Helper sessions” and making assistive devices in a talk at Xinchejian.

Seems like there is a fair bit of interest – so these sessions will hopefully be be ongoing and produce some fun and “usable devices” (haha).

The trimmed presentation (cut out the waffle about me) has been published here as pdf and odp because XCJ blog and wiki have file size and type restrictions.

Started Xinchejian wiki pages for “Helper sessions” and making assistive devices.

Swarm Robot competition entry and workshop

SwarmRobot with new IR shield PCB
SwarmRobot with new IR shield PCB

Just put in a huge effort to enter the Xinchejian SwarmRobot into the AFRON competition.

Also used the assembly instructions created as part of the entry to help run a  workshop with other Xinchejian members making SwarmRobots. The workshop was pretty successful, although our preparation was lacking a bit with an untested PCB that just arrived and was assembled for the first time during the workshop and a different power switch that did match the board!

Definitely time for a more relaxed pace – exploring the Lophilo and a few other projects!

How much code can be “stuffed” into an Arduino?

In a quest to see how much code can be “stuffed” into an Arduino the Autonomous robot project has grown to several thousand lines of code.

The compiled code is currently about 16kB when all of the debug functions are included. This is only about half of what an Arduino with an ATMEGA328 can handle. To give some meaning to this, here is the call graph I generated with Doxygen, a marvellous code documentation tool:

Autonomous robot Main loop - Doxygen call graph.

Autonomous robot Main loop – Doxygen call graph.



This actually only gives a very tiny view of Doxygen’s full capability. But the real Arduino memory size limitation is not usually the code size, but the variables used, and typically the strings. Posts on using Doxygen with Arduino code and tips and utilities to help Arduino memory management are “coming soon”.

HY-SRF05 Ultrasonic Sensor for autonomous robot

Continuing the autonomous robot sensor theme with some updated sample code for the HY-SRF05 Ultrasonic Sensor that significantly reduces the blocking (delays in program execution where NO code is run!).

Once again, the code is placed on the Wiki as part of the move to help create re-usable community content.

Honeywell HMC5883L compass sensor for autonomous robot

One big part of my ‘relaxation’ project – ‘building’ an autonomous maze solving car is the sensors.

Installation of the four ultrasonic sensor and experimental avoidance code has shown (again) just how bad I am at visualising in 2 & 3D space. My simple avoidance logic attempts always end up avoiding big objects, but then get stuck in a tight loop “go forward” – “avoid = go back” – “go forward”.

So I thought it was time to add the Honeywell HMC5883L compass sensor (part of Christmas present to self). The sample code ran up easily (once converted all the wire-I2C commands to Arduino v1.0), so I ported the code into my code. Weeks later after umpteen different project sidetracks I noticed that the output from the compass was not linear and very different if you rotated clockwise or anticlockwise!

After lots of web searching and help from others with this sensor, I have now started to get more sensible output. While this work is not fully complete, it is a big improvement over the standard sample code that is commonly found, so I thought I better start publishing before I loose momentum on this.

Details are on the wiki, and I also updated the SeeedStudio site sample code on their wiki. The main point to note is that it takes some effort to calibrate, but hopefully the sample code provided helps simplify the tasks.

{U}sable{D}evices Wiki – collating and sharing useful information

One of the goals of this site is to share information, and of course that should not just be any information, but ‘useful stuff’.  With the Internet and growth of the information society or whatever buzz words spring to mind, there is a huge volume of information available. Lots of it is readily accessible and good quality, but a lot is hard to find, or easy to find – if you know what to look for or where to look, or information is easy to find, but only in bits that are widely dispersed and would benefit from a central summary.

This site is attempting to build a community to reduce these issues. I am making a start by collating the Inspiration posts onto the Wiki. This will provide a summary list view and detailed pages, as well as add the Semantic MediaWiki enhancements (web 2 features) and allow easier re-use of the information.

This site is not trying to be a repository, not trying to be a “web directory”, although there will be aspects of both, but trying to provide useful “stepping stones” to find targeted/structured information for people at all skill and knowledge levels. It is up to the readers of this site to see if this approach has any merit, to modify the approach, and hopefully join in and build the community.

The inspirations on the Wiki will soon be followed with more technically focussed information in several areas, so please keep an eye on the {U}sable{D}evices site, as these will be valuable resources to help you get started, and please join in with reviews and contributions.