Arduino Forum

Forum 2005-2010 (read only) => General => Bar Sport => Topic started by: Fenrisulfr on Jan 15, 2011, 03:18 pm

Title: Baby steps
Post by: Fenrisulfr on Jan 15, 2011, 03:18 pm
Hi All

This is my first post along with my first foray into the 'black art' of coding. I have some experience with programming '........................' . Sorry that pause was whilst I laughed myself silly. For programming please read ZX81 - and perhaps 10 lines of basic.

I dabble in electronics and despite some success, DIY voice modulator manual on the project dalek boards, I am and always will be a rank amateur.

Due to some issues with retention of information I find it a bit of a slog. I have been avoiding uP's like the plague but am wondering if it may be a worthwhile path to follow. I will at least have a bash and see if I can do anything 'interesting'.

Or I may be swapping one set of 'problem solving' for another  ;D

For my Birthday my Lovely wife has ordered a arduino diecimila clone with a 328 uP on board. I have the IDE software installed on my Linux box and 3 weighty tomes, OK PDF's, to read and guide my first steps.

I have a few ideas, simple fare, of what I want to have a bash at but not a patch on the majority of applications the membership seem to be conjuring up.

I draw up my own PCB's and make them using the toner transfer method. I converted a laminator using a clothes iron thermostat  to get the hotter range needed to do the job.

Successful electronic projects I have done-
Voice mod for Dalek use. A lot of people from the UK, US and AU have taken up the design to use in their builds.
Knight rider LED array for 'Dalek Storm'
Sound and lights for dalek weapon system......you can see a pattern here cant you  ;)
A few LED props for a 'Doctor Who' Look a like, working on a 'Berylium chip' prop for him now to.
and various breadboarded circuits just to play with.

That's about it I think. Hopefully I'll have my arduino mid week and can start asking stupid good questions.

regards

Fenrisulfr
Title: Re: Baby steps
Post by: wossname on Jan 15, 2011, 03:32 pm
I'm fairly new to Arduino too, but I have a coding background (C/C++, C#, VB etc etc etc...).  I was pleased to discover that my programming skills from regular computers are very transferrable to the Arduino platform.  This is good news for you because it gives you the option to hone your coding skills by writing regular (non uP related programs) on a normal PC (and run them on the PC too).  In fact it's possible to take chunks of standard C code from a PC application and dump them straight into the arduino IDE and make them work with only a little tweaking needed.

I don't know what PC platform you use (Windows/Mac/Linux/other) but I tend to do most of my day-to-day coding (for my job) on Linux.  Writing C apps on linux is pretty similar to writing code for the Arduino, except that your IO and resources are obviously more limited on the Arduino.  The coding environment is familiar to any C/C++ coder, although the Arduino IDE itself is painful to use in my opinion.

Writing code for arduinos does make you consider resource usage a lot more than you would on a PC, which can only be a good thing.
Title: Re: Baby steps
Post by: Valalvax on Jan 15, 2011, 07:08 pm
What is uP? I tried a Google search but it wasn't very helpful, first I found the movie Up, and then I tried adding coding to it and got some sort of medical coding information...

>.>

Also... go Doctor Who whooo! :D
Title: Re: Baby steps
Post by: Osgeld on Jan 15, 2011, 07:11 pm
uP = microprocessor
Title: Re: Baby steps
Post by: Valalvax on Jan 15, 2011, 07:14 pm
... Oooohhh

Yea, makes sense now, thanks :P
Title: Re: Baby steps
Post by: u0421793 on Jan 15, 2011, 08:10 pm
Well, it's really µP.
Title: Re: Baby steps
Post by: Ran Talbott on Jan 15, 2011, 09:55 pm
Quote
although the Arduino IDE itself is painful to use in my opinion

kwrite (or Notepad2 if you're using Windoze) has good syntax highlighting for C and C++.

I only use the IDE as a sort-of "GUI make" and serial terminal.  Just load the source and go.

Title: Re: Baby steps
Post by: Fenrisulfr on Jan 15, 2011, 11:40 pm
Hi Chaps

I have an Ubuntu OS (Linux). I have been Windows free for 2 years......good grief I sound like a client at a 'Windows Users Anonymous' meeting  ;D

I have been reading sketch's, tutorials and watching youtube video's of everything Arduino. My mind is set to explode out of both ears I think. I get the drift but I fancy there is some subtlety in good coding which I hope will make more sense when I have my module and start trying the various tutorials.

It should be a laugh.....depending on your point of view.

regards

Fenrisulfr
Title: Re: Baby steps
Post by: cowjam on Jan 15, 2011, 11:45 pm
Quote
there is some subtlety in good coding


Good coding is an art form, your code should be as elegant as possible.
Title: Re: Baby steps
Post by: Fenrisulfr on Jan 18, 2011, 02:13 pm
I can do elegant.......It's the coding that's going to be iffy  :-/

My Module arrived today! It is in fact a clone, but no matter, it works!

The board is marked -

DFROBOT
DFRduino
Duemilanove

The make up of the board includes the 'auto' voltage/power input. Overall I am very pleased and my only niggle is that the crystal isn't sat flat to the PCB which is a non issue really.

As soon as I plugged the USB cable in the 'Blinky' sketch started running. So I placed an LED in Pin 13/GND and that completes my first lesson  ;D

(http://i200.photobucket.com/albums/aa97/Fenris_2007/SV600020.jpg)

I'll just scratch my head and wonder what to do next I think.....Over a lovely cup of Yorkshire tea!

regards

Fenris
Title: Re: Baby steps
Post by: AWOL on Jan 18, 2011, 05:12 pm
My coding is an art-form, a fusion of Jackson Pollock and Tracey Emin.
Title: Re: Baby steps
Post by: Fenrisulfr on Jan 18, 2011, 09:25 pm
Mine will be a mix of Copy/Paste mixed with a generous side order of desperation!

I have a pair of tri colour LED's flashing from red to blue in antiphase just copy/pasting code and adjusting pin numbers. A minuscule step but it works.

I think I need to go to Maplins and grap some 'proper' breadboard wires and a dedicated breadboard.

regards

Fenrisulfr
Title: Re: Baby steps
Post by: STDummy on Jan 19, 2011, 02:29 pm
I think I can safely say that you're not the only one floundering at the deep end.  This forum is a definite lifebelt, but no one put any instructions on it!

I think my own problem is that I have a distinct purpose I want to use the Arduino for, and most of the newby-orientated info I have come across so far assumes that you already have a degree in C!! - which I don't.  I haven't found anyone else's code that does anything near to my requirements - otherwise I would have plagurised the heck out of it already!!!

With my learning speed, I don't have enough of my allotted span left to start from scratch.  I just wish I had a compiler that could take BASIC instructions and convert them to C.  I might stand a chance then!  Yes, I had a ZX81 as well  :-[

There are some good deals on breadboards and patch leads on eBay I've noticed, if you want a low budget approach btw.
Title: Re: Baby steps
Post by: Fenrisulfr on Jan 19, 2011, 11:44 pm
One tip I'm going to follow is to 'flow diagram' what I want to do with a given circuit. It wont make the programming any easier but at least it can be broken down into 'chunks' that may be easier to get my head round.

I've looked at a lot of sketches and how-to guides and there seems to be the long hand method of coding and, when your really smart, the short hand method which uses array's and values to minimize the amount actual code needed to do the job.

I've just looked at Maplins for jumper wires...........£4 sterling for 10 pcs  of one length. ............ Ebay  70 pcs in 4 lengths £4. I know where my money will be going  ;D

I to have one specific project in mind. Actually I have already drawn it up and simulated it with out using a processor. The Arduino, once I get my head around the coding, will at the same time make the design simpler but allow a greater complexity to the control without having to add extra components here and there.

What have I let myself in for?

regards

Fenrisulfr
Title: Re: Baby steps
Post by: Valalvax on Jan 20, 2011, 12:09 am
I worked through this book and thought it was a very good basic intro course: http://www.amazon.com/Getting-Started-Arduino-Make-Projects/dp/0596155514

It gives a couple of examples and walks you through understanding the code involved... note that all code involved is in the basics code available in the IDE

The final project they give is kind of to completely blow the poor newbie's mind, going from making a light blink when you push a button to pulling information from a website and making a tri-color LED glow a certain color based on the number of times particular words appear
Title: Re: Baby steps
Post by: cowjam on Jan 20, 2011, 12:14 am
Quote
I've just looked at Maplins


I've got a maplin locally, it's handy if I need the occasional part and I can't wait for delivery but everything they sell is expensive.
Title: Re: Baby steps
Post by: Fenrisulfr on Jan 20, 2011, 01:15 am
As a rule I only use them if I have to. Other than that it's a selection of online electronic suppliers and ebay. With all the benefits of spending less.

regards

Fenrisulfr
Title: Re: Baby steps
Post by: Ran Talbott on Jan 20, 2011, 02:24 am
Quote
most of the newby-orientated info I have come across so far assumes that you already have a degree in C!! - which I don't.

Have you checked out Lady Ada's tutorials (http://www.ladyada.net/learn/arduino/)?  I've heard good stuff about them from other newbies (I'm not necessarily a good judge,  since I've been doing software for about 40 years, and electronics for almost 50).

Quote
I just wish I had a compiler that could take BASIC instructions and convert them to C.

There used to ba critter known as BASTOC (possibly back in the days of DOS).  It didn't turn up in a quick google search, but something called BCX (http://bcx-basic.sourceforge.net/) did.  I have no idea whether it's any good, but it might be useful to run it against some simple BASIC programs and see how the constructs you're familiar with are expressed in C.  Or it might generate godawful (bleep) that teaches you terrible habits.  Caveat programmafactor  :)
Title: Re: Baby steps
Post by: pwillard on Jan 20, 2011, 03:40 am
I'll be honest, I've not always been a fan of C.  I started learning it in 1982/1983 (oh what a giveaway).  I still have my tattered 1978 Kernighan and Ritchie book handy.  My problem was that I had started to learn Basic and Pascal before I looked at C and every time I looked at it it gave of an... "I'm not finished" vibe.

I eventually found C inescapable and pervasive in both work and hobby.  Finally, thanks to somewhat to the Arduino influence, I find C not so bad anymore.  I even now find it elegant in it's simplicity at times.  I guess it just takes looking at it from a different angle to gain a new appreciation for something you once thought of as disarranged and somewhat sloppy.

And I LOVE THIS comment:

Quote
My coding is an art-form, a fusion of Jackson Pollock and Tracey Emin.
Title: Re: Baby steps
Post by: cowjam on Jan 20, 2011, 04:05 pm
Quote
I just wish I had a compiler that could take BASIC instructions and convert them to C.


I feel your pain but the other way round. I've just had to do some work in Visual Basic.net and it nearly made my ears bleed! I'm used to more formal languages and couldn't cope with VB, not when coding in Notepad.
Title: Re: Baby steps
Post by: gadman58 on Jan 20, 2011, 06:11 pm
I started with LISP because my background is on the CAD side of things, progressed to VBA then .NET and then got into creating Gcode.   Found if I did not want to do things manually in the CAM software, I was going to have to learn some C.  Been doing that off and on for 12 years now.
Even have learned a little Ruby for helping a friend.

I think C/C++, have to include C# as well, syntax is much harder to learn but there is so much more you can do.

I can always tell when I have spent too much time (about 30 minutes)coding in C though, I put a semi-colon at the end of every sentence.  :)

Glenn
By the way I do not consider myself a good C programmer, I am definitely on the bad hack side.
Title: Re: Baby steps
Post by: cowjam on Jan 20, 2011, 06:25 pm
Quote
I put a semi-colon at the end of every sentence.


All good languages require a semicolon.
No good language uses a single = in a comparison.
Title: Re: Baby steps
Post by: Fenrisulfr on Jan 20, 2011, 11:28 pm
I have just had a brown trouser moment! I changed some code to try and get a row of LED's to run from right to left instead of left to right..........Locked the board up the green LED was going bonkers!

Programmer could not be uploaded to =O

Went to the directed to web page. Nothing similar to the listed issues.

So in the end I did the following. Partially based on resetting a router when it goes AWOL =D

I held the reset button down inserted the usb and hit upload.....my timing seems to have been perfect as It's now all working again......thought I'd fried it! And me with 70 breadboard hookup wires on the way =D
Title: Re: Baby steps
Post by: STDummy on Jan 21, 2011, 12:19 am
Oooooooooops!  Close call!!   :o

Now, if that had been me, I'd have pulled the USB connection, gibbered a bit, crossed my fingers whilst praying to the god of fried circuit boards, then plugged it in again.........

Then I'd cry, bin the board, which with my luck would be giving a good impression of a fine Cuban cigar, and get drunk.

The next morning, whilst desperately searching the internet for a hangover cure, I'd undoubtedly order up a new Arduino board.  Some people never learn - although I have ordered a second hand copy of Kelley and Pohl's Book on C, so maybe I might be able to disprove the theory of old dogs and new tricks.....although I doubt it ::)
Title: Re: Baby steps
Post by: Fenrisulfr on Jan 21, 2011, 02:51 pm
It looks like I tried to change the wrong part of the code. I think, and I'm only guessing, I sent the arduino into a loop that was so fast it couldn't communicate with the PC.

I found the correct bit of code today and have changed the direction of the 8 LED's.........GOSH! Aren't I clever  ;D

regards

Fenrisulfr
Title: Re: Baby steps
Post by: graynomad on Jan 21, 2011, 04:01 pm
I may be wrong but I don't think there's any way your program can kill the upload. The processor is reset at the start of an upload, nothing you can do will affect that unless you're playing with writing to the flash and overwrite some of the boot loader, which I doubt.

______
Rob

Title: Re: Baby steps
Post by: Fenrisulfr on Jan 21, 2011, 04:41 pm
I guess I may have just terrified the chip to death  ;D

At least it is working again though.

I changed the some numbers around and symbols to change the direction of the LED's.

Then I realised I only had to swap the 'HIGH' and 'LOW' of the two lines that loop to change the direction  ;D ;D ;D

So much to learn so little lifespan!

regards

Fenrisulfr