Thursday, August 29, 2013

Why Write a Tech Blog?

I have been asked why I began writing this blog. To answer anyone who might want to know, I have decided to write this blog post. I'll just dive in.

1) Writing a blog encourages documentation. I tend to work on things in a scattered manner. Knowing that I will need to post pictures and a summary of the process encourages me to keep my thoughts focused and my records organized. At the very least, I have to finish the project before I forget what I did.

2) Writing a blog helps immortalize documentation. When I hit publish on a blog post, I can (generally speaking) count on Google to put that post out there. If my house catches fire and burns to the ground the next day, all I have to do is go to the library and type in "", and all my previous projects are right there. Even if I forget my password, this data will still probably stay out on the inter-webs until long after it has become irrelevant (which isn't that long).

3) Writing a blog helps increase documentation accessibility. Obviously, if I write down my projects on a notepad and tack it to my wall, not too many people will ever see it. What I am doing may be completely useless to some people. However, it may be invaluable to others. When I begin a project, the first thing I do is Google the problem and see if anyone has done it before. My blog just adds to the list of things that have been done. Sure, there is a post on how to run stepper motor x140 out there. But if I want to run a x143 wouldn't a post on running an x143 be helpful too?

"But if everyone posts what they are doing, the internet will become so clogged that no one will be able to find anything!"   Well there again, thank our friends at Google. It isn't easy to get on the first list of hits for a Google search. All we can hope for is that the articles that will help you are there, and the junk ones are off in the weeds.

Technology is advancing faster than ever before. The best technology today is the discarded second of tomorrow. Universities release exciting new papers that are outdated before people have time to read them. Individual men have always been great innovators, but this boom has come about from the share of information. The internet is a fundamental part of the way life is lived and problems are solved. Open source and open hardware projects are a major part of the internet. Something that one man does because it is cool becomes something that another man uses to solve a problem. The internet is a dark and scary place, but no one can deny its profound impact on technology.

So go blog away about your projects. I plan to as long as I can. Will my blog become a trusted resource for hobbyist? Probably not. Will 3,000 people read this post? Probably not. But someone Googling "Why Write a Tech Blog?" might, and that person is this post's intended audience.

Why write a tech blog? I have my reasons. Now it's time to get back to my projects.

Tuesday, August 27, 2013

Introduction to myrobotlab (MRL)

First, let me say that I am a user of myrobotlab. Not a developer. With that in mind, it is also safe to say that I really know very little about the software. This post is just a collection of things I have learned and observations I have made from a user's perspective.

For a while I have been wanting to do a little vision processing, and being a FIRST robotics alumni I had seen a bit of this done. While I had never been actively a part of the programming, I also knew that FIRST teams get a "free" copy of roborealm with their kit every year, and that is what many teams use for vision processing. Well that is all well and good, but I like free. I began looking for a free version of roborealm and found myrobotlab.

Well for those that may be coming from the land of Arduino (like me) MRL is completely foreign. At first glance, it looks all GUI and friendly, then you discover a hidden underworld of features that can only be found by someone who already knows where they are. Regardless, after getting it installed, getting OpenCV (a widely used computer vision library. See HERE) up and running is pretty simple. You can have your camera finding your face in a matter of seconds. Now, doing something with that data is more tricky.

Now like I said, I am in no way a trusted source on this, but this is my take on how MRL works. You have a set of services running within a Java infrastructure. These services can do just about anything. At the time of this writing the main way you link these services together is by a Python service. From there you can set up the links from service outputs to service inputs. There's just one problem. How do you know what each service can input and output?

Well that is where not being a real programmer is a real pain. Basically, play around with stuff. Look at the examples on each service page and HERE. If you encounter a problem, post on the forum or in the chat and ask a developer. With features progressing so quickly, sometimes examples get left behind. One useful forum topic on this is found HERE. In it GroG discusses several ways to look at the various methods for communicating with each service.

That's about all I can say about it. I have been playing around with it, and as someone who learned to "program" on an Arduino less than a year ago I can say that the fog does lift. Play with some examples and ask questions, and you will figure it out. Of course, if you already know Java or are a real programmer, I'm sure you will have no problems with it.

I have been playing around with the serial, keyboard, and opencv services mostly. Hopefully I will be able to post some cool projects with them in the very near future. Until then, check out myrobotlab. Such opensource projects are always neat to check out even if you aren't going to use them. The people on there are always nice, and I'm sure there's room for one more user.


Friday, August 23, 2013

Arduino Mega 2560 r3 Doesn't Show Up in Tools Menu

Recently, I have had problems with my Arduino Mega 2560. Serial communications would drop in and out. It would not show up in the Arduino IDE Tools menu. Annoying stuff. Looking around on the internet, it appears that this is a fairly common problem, so I thought I would post what I know about a solution.

If your Arduino Mega doesn't show up in the Tools menu, the first thing you need to do is open the device manager (on Windows. If you have a Mac then you should mail it to me and go by a Windows machine). From the device manager we can further diagnose the problem.

1) Your Arduino shows up nicely under the COM ports tab. This is quite possibly the most frustrating problem, and as far as I can tell no one really knows why this happens. Here are some things that I did that sometimes worked. Try a combination of them.

  • Disconnect and reconnect the Arduino
  • Re-install the Arduino Drivers 
  • Re-install the Arduino Drivers deleting them when you remove them. ( I believe there was an update to the Mega driver somewhere around Arduino 1.0.2)
  • Restart the Arduino IDE
  • Turn off  your WiFi (My computer has bluetooth built into the network card. Bluetooth COM ports can cause problems sometimes. Turning off networking solves this).
  • Reinstall the ATmega16U2 firmware. (Instructions HERE)
  •  Get frustrated and go work in your garden
2) Your Arduino shows up as an unknown device. Install the drivers. I can't think of any other reason this would happen.

3) Your Arduino shows up as an unknown Atmel device. The Arduino Mega 2560 r3 has a ATmega16U2 that acts as a USB to serial chip. If you are getting an unknown Atmel device it means that this chip has been put into DFU mode. This is not the end of the world. Usually you can just disconnect and reconnect the Arduino, and it will go back into it's normal mode. If that doesn't work see my previous post on this subject.

4) Your Arduino shows up as an Atmel device called ATmega16U2. Well this means the same thing as above. It is in DFU mode except you have already loaded the Flip programmer driver. You have already started the process, so go HERE and finish.

5) Your Arduino does not show up in the device manager at all. This is a pretty major problem, but I found this one almost freeing. You can try various things. If you have an external ISP you may be able to reflash the ATmega16U2 and save it. I believe there are some instructions for doing so in a README file in the Arduino firmware folder. You should try a different USB cable obviously. Wiggle the wires. Blow out the connection with air. However... the chip may be fried. What does this mean?

If it is just the ATmega16U2 that is trashed then you can still use your Arduino Mega! Now you will just need an external programmer to program it. I recommend having one of these anyway. A USBtinyISP is maybe $15. I have used it extensively with ATtinys and even detail how to use it with a Mega HERE.

But now you want to get that nice Serial Monitor for debugging. Well that again will require extra hardware. You will need an external USB to UART cable. I talk about them HERE. Mine was $4. It's a worthwhile purchase anyway.

If none of those things tickle your fancy, buy another one. Places like HobbyKing sell them for less than $20 (HERE). Look for "Arduino compatible" boards. No one likes a counterfeit.

One last problem that I want to throw in here. The Tools menu freezes or crashes. There are mentions of this HERE. Like I said above, turn off your WiFi. You can also look and see if there are any Bluetooth scanning programs running. I haven't found any quick way of doing this besides looking through the system processes and closing stuff that sounds suspicious. Believe me, I know how annoying this problem is, but that's life. Arduino 1.5 does seem to do a bit better.

If you have other ideas, suggestions, or words of encouragement comment, and let the world know. There may be other things out there you can try.I hope this brings you success. Good Luck!

Wednesday, August 7, 2013

Serial Sonar Sensor: ATtiny85, HC-SR04, and Arduino SoftwareSerial

In this post I will detail how I used an ATtiny85 as a controller for an HC-SR04 sonar module (Ping sensor). The controller reads the inputs from up to 3 HC-SR04 modules and transmits the readings to an Arduino Mega via serial communication. This allows the Arduino Mega to pick up the readings whenever it is convenient rather than having to worry about complex timings. Let's get started

First things first, we need to run the NewPing library on an ATtiny85/45/25. Until version 1.6 is released you will need to modify the library to do this. However, this removes some of the functions you might want to use on other boards. For this reason, I created the TinyNewPing Library. In it, I removed the parts that cause the errors on an ATtiny and gave it a new name so you can distinguish between the two. All the function names remain the same. If you still need more details check out THIS prior post.

Next we need the SoftwareSerial Library on the ATtiny. Luckily, this comes with the IDE and I already did a post on it. Funny how that works.

For a first attempt, try a single HC-SR04 sonar sensor. This simplifies the code a bit. Load THIS code on the ATtiny (sensor side) and THIS code on the Arduino Mega. Note the code uses both Serial and Serial1 (thus the Arduino Mega).

To wire it up, connect the echo and trigger pin together and then connect them to pin 0. Wire in 5V and ground to both the ATtiny and the HC-SR04. Then connect pin 4 (Software Tx) on the ATtiny to pin 19 (Rx1) on the Mega. Finally, plug the Mega into the computer via USB.

Now if this is working ok, we can move on to 3 sensors. For that, we need to load THIS code onto the ATtiny and THIS code onto the Arduino Mega. The ATtiny takes the readings and sends them to the Mega. The Mega updates it's variables and sends them to the Serial Monitor for us to see.

Wiring it is cumbersome but simple. Regrettably, I did not take a picture when I did it, but just do what you did before an extra two times. Note again that we are using the same pin for trigger and echo, so they need to be wired together. Then wire up power and grounds. Finally connect the ATtiny to the Mega and the Mega to the computer.

Now open the Serial Monitor and watch the numbers scroll by.

Potential problems: If the ATtiny gets out of sync with the Mega (it will), an occasional bad value will come up. I couldn't come up with a quick fix for this. If that is a problem, maybe you could take the median of a few readings. They are coming in pretty quickly. The plan is to make an I2C version of this soon, but I make no promises on a deadline. One last download, get the entire package of sketches used in this post in a zip file HERE.

A few quick notes before we go.

  • Why not I2C? That's next (Done! Check it out HERE). Serial is easier because it doesn't require a 3rd party library to work on the ATtiny line. 
  • Why only 3 sensors? Short answer, ease of use. You might be able to get 4 or even 5 out of an ATtiny45 if you're persistant. I don't have that many sensors nor that much patience. You have 5 regular IO pins plus the reset pin (which can be used as an IO). You might be able to use the serial Rx pin as an input as well. 
  • Why not just buy a I2C ping sensor and be done with it? Well this reduces the number of wires going to the Arduino Mega. It also gives you more options and increases the number of micro controllers on board your robot (cool factor). Other than that, it's cheap. With HobbyKing or Ebay, this project could be done for less than the price of one I2C sonar sensors.
Hopefully someone will find this useful. If anything goes great, please comment! If anything goes wrong, contact your local internet service provider. I blame them (That's a joke. You can comment below as well).