Sunday, November 18, 2012

Atmel to Arduino Pin Mappings

Everyone should have this image from Tinkerlog printed out and handy. It's such a waste of time to search for the mapping between Atmel physical pins and what the Arduino environment calls 'pins'.



And corresponding mappings for the AT 84, which aren't in the image above:




And a slightly 'better' view of the hardware pin functions of the Atmel Tiny 84 and 85 from the data sheets:



The AT Tiny 85 - the 8 pin package:



And the bigger brothers, the 168 and 328 DIP package versions:











Monday, November 12, 2012

I2C and Wire.h - A match made in hell...

I2C in the Arduino environment is probably one of the simplest things to get working. And frustrating... the behaviour of the write() command within the protocol doesn't even come close to following it's own conventions, let alone those of I2C (which are sloppy, at best).

Case in point: I was just debugging an I2C conversation between the Max32 as master (which uses receive() instead of read() - don't get me started...!) and the Leonardo as slave, with the objective of moving the code on the Leo to an AT Tiny 84 later on.

It wasn't working... I requested 5 bytes, and got 5 "ÿ" characters.... W.T.H.?

My terminal session on the Max32 wasn't line wrapping, so I decided to also send a "\n" which is a newline character. I was getting the occasional valid character, depending on how I structured the sender, but mostly it was a long string of "ÿ". Stunningly, that worked the first time, every time.

So I was getting invalid garbage, and a valid newline character. Weird.

I went looking for this mysterious looking lower-case-y character (it came out as either -1 or 255 if I displayed the ascii code for it) and found this post that had the answer: You can't do multiple writes from the onrequest slave to answer a single request.

http://arduino.cc/forum/index.php?action=printpage;topic=109335.0

So if you think you should be doing a beginTransmission, writes, and an endTransmission in the slave to send bytes as a response... nope.

Just one single write().

That little gem is actually buried on one of the first articles I read on I2C on the Arduino, so it shouldn't have been a surprise to me:

http://www.dsscircuits.com/articles/arduino-i2c-slave-guide.html

It's a bit of a long read, but I2C is a bit of a confusing mess, since there protocol is somewhat open-ended.

Saturday, November 10, 2012

Bot Shopping

I've never been a fan of all-in-one robot kits, even as a kid, so I tend toward places that I can actually get the widget I need, and then cobble things together myself. Here is where I'm currently doing my shopping:

Solarbotics - I live in the same city as these guys (Calgary) and I like to buy local, so it's really nice that they are a friendly bunch, and they actually do some fun work in the community, and have their own designs. Check out the Ardweeny, or if you want an afternoon project, the Useless Machine.

RobotShop.ca - I'm not a huge fan of overpaying for customs and shipping from the US stores, so I always check here for things I can't get from Solarbotics; they ship from Canada, so... YAY!

The two US stores below I have used, and both have reasonable shipping, and both survived the trip through customs without me having to pay double what I expected to.

Sparkfun - Easily the most down-in-the-weeds geeky site if you really want to know the dirt on that $20 sensor you're about to buy. Does it work they way you thought? Does it work at all? Each product has a discussion thread which is super-duper helpful. And the New Product Post videos on Fridays... nice!

Adafruit - Not 100% robotics, but one of the coolest places on the 'net. They have a ton of tutorials, are super-organized, and the different parts are actually intended to work together, which sort of hints at the genius lurking there.

ServoCity - I haven't tried these guys yet, but I do need a bucket or so of the types of parts they sell, so it won't be long now before I order. Anyone order from them before?

Let's toast some 'droids!

After compiling hundreds of pages of notes, hundreds of lines of code, and hundreds of Atmel processors* I decided a blog was the best way to keep my ideas for robots, gizmos, and widgets organized and accessible. And besides, what use is an evil plan for world domination by my robot army if I can't share it?

But let's start at the beginning...

If you're in the market to start work on your own robot, thingamajig, or doohickey, and feel the need for a microprocessor, or more specifically a microcontroller, where would you start?

You might start with an Arduino, and you'd be right, at least partly. There are a lot of Arduinos, and a lot of Arduino clones, some better than others. Even within the official Arduino family there are ... minor compatibility issues. The boards and processors aren't all the same, and it does take some time to understand the differences. The community and software support is absolutely awesome, so it's an easy start. Just pick up an Uno or Leonardo, and get going.

Or you might want something with more processing power, like I did, lured by the friendly promise '100% Arduino Compatible' - a promise that turns out to be nearly impossible to deliver on.

I took both paths, and neither was 100% right for what I imagined. For a start, I bought two boards, an Arduino Leonardo, and a chipKit Max32. Neither are terrific first-time robot building boards.

The Leonardo might look like a classic Arduino shape, but they've moved enough pins around to make it tough for a newbie to use with several of the shields that are out there. Shields are add-on cards that 'stack' on top of an Arduino, with a clever system of pins and sockets. The idea is that you can stack a bunch of shields on an Arduino, and create something that has unique capabilities. But it's not quite that easy - and less so with a Leonardo.

So is the Leonardo a dud? And with the new 32 bit 'Due' shipping, is everything else obsolete? Not a bit. The Leo turns out to be a perfect standalone development board. It's inexpensive, it's a terrific passthrough to program your own $3 Atmel chips, and it has a great mix of I/O pins. It's turned out to be my favourite to use so far, although I bet one day soon that will change, and the Leo will find a permanent home in one of my creations.

How about the Max32? It's 32 bit (and available long before the Due), it's 10x the clock speed, and it has a TON of I/O pins. But it has ever-so-slightly limited pin capabilities, some lacklustre library support, and the documentation, although improving, is taking some time to stitch together. So it's not quite 100% Arduino compatible... but neither is the Leonardo, so I can't really complain. It is very fast, has more memory than you can shake a stick at, and it does have a permanent robot-home planned for it. For the bucks I think it's a great purchase, just not for a beginner.

If I were to start again, I'd probably start with a Ruggeduino. I don't own one yet, but the maker has a lot of good points of improvement, and if you think you're going to put your precious controller in anything that might short circuit, fall down a flight of stairs,  or staying out late playing pool and drinking, you might want to take a look there. If you own one, I'd love to hear your comments!

* I don't have hundreds... yet... I have a handful of AT Tiny 84's, 85's, and 328's. You should, too, these are incredibly useful little chips, and only cost a couple of dollars each.