Wednesday, March 3, 2010

Moving on?

I've been struggling for a long time now, to see if there is a way to develop programs for PICs that can be done on one of my macs. It is very tempting to jump over to the MS side of town, just to make it so much easier on myself. It is, however, not easy to do this, since I've been a mac user now for about 20 years. Still, it is very tempting. I did buy an old PC with Windows XP installed on it, and although this works very well, it is a somewhat old and noisy computer, which is part of why I'd like to stick to my iMac for as long as possible. It is nice to have all your programs, IDEs, and whatnots in one place as well. Apart from doing PIC-programming, I also like to develop apps for use with a computer, for example with the likes of Processing/Java, and OpenFrameworks. These programs works like a charm on my mac. They would probably work very well under Windows as well, though, so the question is still there: Should I go for a PC with Windows instead? At some point, I probably will. So, instead of just blabbering on, I will make a list (not sorted in any way) with some interesting software and hardware (all related to Microcontrollers somehow) I have found so far.
I guess this is what I have so far. If you are an absolute beginner, I would say Arduino and Processing is a very good place to look. This is meant as a list of tools and hardware that goes one step further, where things might not be so easy and instructive (and really top notch learning tools) as Arduino and Processing. Nevertheless, with these tools, the flexibility and power of your projects can be greatly improved, not to forget, way cheaper as well. Feel free to ask any questions if anything here is unclear. Cheers!

Sunday, June 14, 2009

Pots and pans





[Click on images to see large version]

[Also, here is a link to a show where I used the panel. The show was mostly for an experimental animation class, but with some cross over to my physical computing class ... http://www.rsd.no/documenta_web/ ]


Useful Experience:


Since my goal was to put together something that could be displayed in public, I had to think about some of the problems that might occur. First of all, would they understand my 'analog interface' and what to do with it? Since I planned on staying in the room where the 'show' took place all the time anyways, it did not really matter so much in this case. But in any other case, under normal circumstances, it would have mattered a great deal. I think four knobs are pretty easy to understand (especially because they look just like any other normal knob would do [see images]) but what those four knobs represent is not given at all. My intention was that people would test the knobs, and by receiving feedback from the screen, they would understand what was going on. In some cases, it might be more or less random things that happened, and that would be okay too, as long as the subject did not stop playing with the knobs, because of confusion or any other reason for that sake. There would be little use in having a 'user controlled piece of digital art' if the user were either not willing to control it, or did not understand that this was the whole point of it.

In any case, I learned that making a good interface is not easy. I was actually pretty confused myself many times when I tried controlling the different parameters with the knobs on my panel. To make it easier to understand, I could have labeled them on the panel itself, but that would be hard, since their function changed from piece to piece. I had about 4-5 usable pieces in which they all took use of the inputs from the potentiometers, but in quite different manners. The other thing I tried, was to have bars and labels on the screen itself. That worked somewhat, and is probably the best solution for now. An even more hi-tech, exclusive, expensive, and usable solution, might have been adding an LCD display to the panel itself. I might do that at some point. Also, it would have been very interesting to make it a wireless solution, something I do not think is too hard, given the right hardware.

In any case, making the potentiometer panel, and having it to work, was very fun and interesting indeed. I had a hard time doing the soldering, mostly because I do not have 'helping hands' to help me, yet, and partly because I do not have the necessary training and skills required for work like that. I am hoping that practice will help eventually. Despite the trouble, I managed to get some of the wires stick to what they were supposed to stick to, and without making any short cuts, so that was all good. The panel itself was part of an old Ikea metal shelf I found behind my house, left there by my old renters. It suited the purpose perfectly. I only had to file a small notch in each of the holes to fit the pots, which only took a couple minutes for each. It is possible to add many more pots to it, or maybe adding some LEDs on the underside could be nice? Either way, I found the whole idea of controlling an application like this very satisfying, and surprisingly easy to extend. I mean, I had some trouble making the first one work, due to a somewhat badly explained example in Arduino, but after figuring out that one, adding more pots was no problem at all.

I was a little bit disappointed that I had to go back to Arduino after spending an immense amount of time trying to learn assembly, and utilizing the PIC, but to have the PIC communicate with a PC/Mac through a serial communication (i.e. USB in my case) was just too much for me to get my head around. This is partly because I could not find any good tutorials on the matter, and also due to the fact that there are a lot of different types of PICs out there, and they all have slightly different ways of doing things like this. Also, this was a matter of hardware, since Arduino works with Mac out of the box, something PICs generally do not do, making it even easier to use the Arduino. So, having said that, when I first went back to the Arduino, it was a dream to work with compared to the PIC. This is not only because of the hardware, on the contrary, but because Arduino and Processing are such popular and wonderfully easy applications to work with, and even more importantly, with so many working examples straight up. I mean, you can find an example of a working application for every function there is, literally. That is a huge help, and makes the learning curve almost go downhill instead of up.

There are many aspects to consider making user controlled digital art pieces, and many skills are necessary to master. One of those skills is something I completely lack, and that is the physical electronics part. I am a total 'newbie' when it comes to that, and for all the tutorials I am looking at, I feel like they are not basic enough for me. That said, some of the tutorial are so basic that they get complex because of that, since they start with the atoms and go from there. So, I would really like to see a good book, that deals with both micro-controlling, thoroughly explaining the electronic parts of it, in addition to having working examples. It seems that most tutorials take for granted that the electronics part is understood, having a much more thorough explanation of the coding, which for me, really is the easy part.

Conclusion:
There is a lot more to learn, of course, in all aspects of making art that involves interactive, physical, digital, aesthetic, and not the least, conceptual parts to it. Together, but also individually, these aspects are all huge fields in and by themselves, that easily can fill up a lifetime of learning, experimenting, and fun. I really hope I will be able to continue to work with all of these fields, with the goal to have them to work as a fully whole at some point in the future.

Thursday, May 28, 2009

Arduino to the rescue



I think it was worth the effort to learn assembly, and to use PICs for experimental prototyping and the like. My biggest problem, though, is to get the PIC to 'talk' to the computer. It might not be too hard (everything is easy if you know how to do it, right?) but after reading several tutorials, a book (I did not read through the whole book, though, since I was hoping to find an easier way to gain the knowledge. Apparently, there are no short cuts to take, and I will just have to take the time it takes to read the book, and hopefully learn something new and interesting. But, since I do not have the time, or do not want to take the time, to read that book now, I opted to go with Arduino instead, which is about a 100 times easier when it comes to solve my problem. Again, what I could not figure out, was how to do the serial communication (or any other communication for that matter), which, in my opinion, is a crucial component when it comes to interactivity and usability in general. So, trying to do the same thing with Arduino, was more or less a piece of cake. I spent 3-4 hours debugging my code, though, since it behaved really strangely for a while, and it took me that long to figure out that it was not anything wrong with the code, but with my breadboard(!). Anyway, it did eventually work, and with that I could set up a simple interface with four potentiometers, making it really useful, at least in my opinion, for a lot of different applications.



Wednesday, May 20, 2009

Limits, indeed ...

Assembly is fun and interesting to learn. But, to make more complex programs with assembly requires far more experience and knowledge than I can possibly acquire in a few months. I have spent the last few days trying to figure out how to get an LCD-panel to work with a regular PIC (particularly the 16F690 which is the one I have been using lately), and it does not seem to be a problem to control an LCD-panel with this PIC, it is just that I can not find any examples of anyone using exactly this PIC for it, and I have not been able to successfully convert the few examples I have found from other PICs either. It shall be said, I have only tried to make this work in a software simulator (http://www.oshonsoft.com/pic.html), and it could be that I do not use this software as intended, thus not getting it to work. It seems to be a pretty nice piece of software, but as with all software, it has a learning curve to it. Anyway, what I decided to do, was to go back to my Arduino board, follow the tutorial found here: http://www.ladyada.net/learn/arduino/lcd.html, and see if I can get that to work. Of course, to make that happen, I once again needed to order some hardware (Futurlec.com is my friend), this time headers, both female and male. The result of that is of course that I will have to wait for a few days (between 5 and 10 they say) before I can actually start with the soldering etc. I any case, seeing how easy it is to control the LCD-panel with Arduino, especially after having the hardware done (which will have to be done in any case, either I decide to go with a PIC and assembly, Arduino or other platforms), I will definitively give that a try. When I got that working, I might try other options as well. I mean, it still sounds better to me to pay $5 for some hardware that will do exactly the same as some other hardware costing $35 (to $50 depending on if you want to use a 'shield' or not). And, as a third option (among several others), it is possible of course to use PICs with Basic or C, which also will make a lot of things much easier to do, than trying to do the same in assembly. I might actually look a bit more into what options I have for Basic, or even C, in the next few days, as I will be waiting for my hardware in any case ...

Thursday, May 7, 2009

Memory? What memory?

Well, I know the memory is there, but how to get to it is the trouble. It is confusing for several reasons to me. First of all; there is more than one way to do it, but how and why they differ is not very well explained anywhere. First some general info from Microchip's PIC16F690 Data Sheet:

Data Memory is held in file registers. Instructions referring to file registers use 7 bits, so only 128 file registers can be addressed. Multiple file registers are arranged into “pages”. Two extra bits RP0 and RP1 (in the Status register) allow accessing multiple pages. These two bits effectively become the top two bits of the file register address. The additional pages may or may not be implemented, depending on the device.


So, this is the reason as to why we need to think about it at all, and then there is the means of how to do it. Again, from Microchip's, this time the "Low Pin Count Demo Board USer's Guide":


EXAMPLE 2-1: DEFINING DATA MEMORY


#define Length 0x20 ;c-like syntax

Length equ 0x20 ;equate 0x20 with the symbol

cblock 0x20 ;start a block of variables
Length ;this will be at address 0x20
Width ;this will be at address 0x21
Area:2 ;this is 2 bytes long, starting at address 0x22
Girth ;this will be at address 0x24
endc




So, here we can see three different ways of assigning variables to memory. But, there are other ways too. Here is an example from a template made by Microchip:


TEMP_VAR UDATA
temp RES 1 ;example variable definition

... and:


TEMP_VARS UDATA_SHR
temp1 RES 1
temp2 RES 1


... where the difference is that UDATA_SHR stands for shared, which is all good, but nowhere can I find what that means in terms of being different from just straight UDATA, or any of the other options. Maybe this is unimportant altogether, but I feel like this is maybe the least well explained topic when it comes to basic PIC programming. Hopefully I will get the picture later.

Thursday, April 30, 2009

Moving bits ...

Finally I got something working! Not much to brag about, but it is a step further than just making the LED blink! :) So instead of having an LED blinking, I had a typical 7-segment LED display blinking. That is, first I had it blinking, which is important by itself of course, so that I know that everything is hooked up right (which of course it was not in the beginning) and that I can communicate with the 'device' through my PICKIT2 programmer. When all that was in order, it was time to try more complex things, like a 7-segment LED chaser (oh, what fun!), and then the over impressive creation of a 7-segment count down device! Well, okay, it is not very exciting to look at, but it is fun (honestly) to be able to do the programming required in assembly and then put together enough bits and parts on a solderless breadboard also to make it come alive. The solderless part was of course working already after the blinking test was done, so the next challenge was the programming, which really needs some hands on experience to make sense. But when you get the hang of it, it really is kind of fun. Assembly is an extremely low level way of programming, making it very compact and structured. The most difficult thing to overcome with assembly language, in my opinion, is how to handle memory. I believe this is not as big an issue in, say, C or BASIC. Nevertheless, in assembly you have to controll it in a very strict manner. And I do not quite have to hang of that yet, but I am getting there. I am sure it is not all that difficult, the problem lays more in the fact that it seems to be more than one way to do it, thus you get a good mix whenever you try to read different tutorials and books about it. Also, many tutorials tend to skip the issue all together, because it 'confuses the reader' or something like that. Nevertheless they use it in their own code but do not explain it, which only makes it even more confusing and hard to find out by your self. Again, I will strongly suggest using the tutorials from gooligum.com as a beginners guide, not because they are simple and easy to understand, but because they are thorough and very logically structured. They are not easy to understand after just one reading, but by reading them over and over again, their quality show through.

My next goal is either to manage to control a DC-motor through the PIC, or have an LCD-display work. For that, I probably need some more equipment. I ordered some vital things from electrokit.com around mid-January, and it still have not arrived (last day of April). Needless to say I do not recommend that store to anyone.

It feels strange to have read so much, and have produced so little. But I guess that is how it is, especially when one learns something totally new, and also as a self study. Some of the things that has baffled me that took me days (or weeks) to understand, could probably be explained to me in 5 minutes by someone experienced. Or maybe not ... :)



Blink!



Chaser!



Countdown!

Tuesday, March 31, 2009

PIC programming for dummies!

I thought I should make a short list of some of the sources I found useful after delving into to mysterious world of microcontrollers for the first time. I have experience with programming in general, but I don't think that is required, although maybe helpful. As a matter of fact, I think assembly programming and microcontrollers could be a good introduction to programming in general, because of its relatively simple language consisting only of a few commands (about 35 on a PIC microcontroller) and the direct link it has to its hardware. The direct link to the hardware is very important in this matter, since what you actually are programming is a small piece of hardware that can only do one very simple thing, namely sending out either 0 volt or 5 volt to a given number of pins. And since this is basically what a regular PC is doing too, albeit in a way so complex and fast that it is very easy to forget this fact, working with a microcontroller forces you to think about it. The thing that makes the microcontroller useful, though, is that it too is extremely fast! It is relatively slow compared to full fledged computer systems of course, running at speeds of 3GHz or faster, as opposed to a typical microcontroller running at a lousy 4MHz (making the PC about 750 faster than the microcontroller). On the other hand, a microcontroller usually only does one, or maybe a couple, tasks at the time, while a PC easily handles hundreds of tasks. Still, 4MHz for a microcontroller means a clock frequenzy of 4,000,000 beats per second. Every instruction on the controller requires 4 pulses from the clock (a very few requires 8) making it capable of doing something at a speed of 1,000,000 times per second, a number that makes it extremely suitable for a lot of tasks that requires repeated output of electric signals at a high speed.

Following is a list of tutorials, books, hardware vendors, and maybe some links to sites with some inspirational projects to start out with.

First and foremost, you will need to pick which brand of microcontrollers you want to try out. I went for Microchip's PIC microcontrollers. It looks to me that another major brand of microcontrollers would be the ATMega product line from Atmel. I do not know much of them, so I will concentrate on the PIC from Microchip. Then, there's the jungle of books out there, all of them claiming to be the best book for anyone who wants to learn about microcontrollers. Clearly, they can't all be the best, which is exactly my experience as well. I'll list up the books I have bought, with my very personal evaluation of each.

One of the great advantages of using PIC's from Microlab (and again, I don't know if this is also the case with other brands) is that they deliver a free IDE (called MPLab) for programming, debugging and uploading files to the microcontroller. It can be downloaded from their website, or, if you buy the pickit2 programmer, it also comes with a CD. You will need a programmer (hardware to get your software/program from your computer over to the microcontroller) and I strongly suggest going with the PICkit2 starterkit as it includes all you need to get started, is cheap, and handles a lot of different microcontrollers. It took me a while to figure out that not only do we have different brands of microcontrollers, but we also have a huge range of different types of microcontrollers, varying in ways like number of pins, amount of memory, speed, and other things like special functions etc. Allthough, they all more or less function in the same way, and by choosing the pickit2, you will be using a mid-range type of controller that works well for learning.

Here goes:

Hardware:
PicKit2 (this is starter kit, with a programmer, software IDE, and a microcontroller on a protoboard included)

Other hardware is a long list (that I will leave unspecified since others have done that job already) that never ends and includes sensors, motors, lights, tools etc

Books/tutorials:
http://www.gooligum.com (this is a _really_ good one, plus it is free, so don't miss it)

16F690 Datasheet (This is the data 'sheet' for the microcontroller that comes with the PICkit2 starterkit, and is another very good source of information. It is several hundred pages long, but it is easy to find specific and useful information.)

Easy microcontrol'n (despite the name of the book; this is a very useful and good introducton to PIC progamming; highly recommended)

Those three sources will take you a long way, especially in terms of understanding the assembly language (not the least -- why to use assembly, and not C or PBASIC or similar) but also in terms of actually get you starting on incorporating hardware, starting with lighting up LED's and seven segment displays etc. Not too complex, but very useful to get one going.

Also, the PICkit2 starter kit comes with a very good tutorial that demonstrates various aspects of the microcontroller and MPLab IDE in a very instructive and easy to follow way.

There are other books and sources that should be useful too (Physical Computing, Making Things Talk) but these three are very specific on the PIC programming part, so I will strongly suggest starting with them.

As for vendors: Jameco, Microchip, Futurlec, Adafruit, and Digikey are all good sources to hardware.