Let's Make Robots!

From Picaxe to Arduino, it's not hard.

AttachmentSize
Programming_Notebook.pdf381.63 KB
Mr__General.zip3.24 KB

When I joined LMR I had just written my first picaxe program.The picaxe was easy to learn since I knew basic and the manuals gave you all the information you needed. As my projects became more complex I started running into limitations with the picaxe.

After 16 months I have finally crossed over to Arduino. It was easier than I thought, the biggest problem I found was that all the commands were not in one neat package like the picaxe manuals (Manual 2 in particular).

After some Googling I found the "Arduino Programming Notebook" by Brian W. Evans. Although hardly an all inclusive guide it is a nice simple guide on the programming structure and common commands used. Perfect for an absolute begginer! Along with the examples built into the Arduino Enviroment I soon understood the basics. The "C" language used by the Arduino is easy to learn and not all that different from basic.

Four basic parts to any Arduino program.

1. At the very start you need to include any tabs or libraries you are using. Where a basic program has everything in the one file, C programs can be made of multiple files.

2. Declare variables. While the picaxe has so many bytes which can be paired into words, C has bytes, integers (words), long variables (32 bit) and float variables (32 bit with decimal point). Unlike the picaxe, negative numbers can be stored in your variables so where a picaxe word would store a number between 0 and 65535, an Arduino integer will store numbers from -32768 to 32767.

3. The setup function is a necessary part of an Arduino program, It runs at the very start and is usually used to define pins as inputs or outputs, initialize servos etc. Even if your program doesn't need this function it still must be present.

4. The loop function is where your main program is written.

Sub routines are now called functions and can be a bit confusing at first because they can pass results back. Because I am use to basic I found it easier to just declare all my variables at the start of the program so they are global (can be accessed from any part of the program) and not pass any information.

Once I could make a LED blink and use PWM to dim it or vary the speed of a small motor I then found the reference page on the Arduino home site made more sense an became useful. With the odd Google search when I was stuck it wasn't long before I had translated "Mr. General.BAS" for use with an Arduino Nano plugged into Mr. General's breadboard.

IMG_0152.jpg

Arduino users will have to forgive my poor program structure. This is partly because the program was an almost direct translation of a picaxe basic program and mostly because I was learning as I went. Those familar with the example code for "Tune" will see I am a plagiarist and copied the example with almost no change. 

It was while learning about the tune command that I discovered that the Arduino program enviroment had a "Tab" feature. Each tab is saved as a seperate file and must be included into the main program. By defining my IO pins in one tab and constants in another it makes my code neater and easier to adjust.

I still have a lot to learn and still like picaxe for many things such as it's commands for using IR leds and receivers. For those picaxe programmers wanting to learn Arduino I found the Arduino Nano plugged into a breadboard was a great beginners platform at a good price.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I refuse to leave the Picaxe environment on favour of the Arduino... but it is nice to see that other people have traveled that road and survived. :)

That is your choice. In the end I just found that the picaxe enviroment (which is designed to teach young students) had too many limitations.

Since I changed to Arduino there have been several improvements in the Picaxe Hardware, now the issue for me is the limitations of the math and logic of the language.

Absolutely, Oddbot. I was just being a smartass. I can see why someone of your talents, who also makes a living with this, would feel constricted by the limitations of the Picaxe environment.

For me, Picaxe was one the most wonderful discoveries. It opened up so many doors for me, that I feel personally attached. Of course, I work very long hours and have very little (although precious) to work on my mad creations. I don´t foresee the Picaxe limitations ever being an issue for me.

However, I promise that if I ever start to look at Arduino with certain fondness, this page will be my first stop. Thanks for sharing, as always!

Andrés  

Brilliant! We are going to open some form of "Arduino Land", and this will be a perfect help on the transition! Wait and see :)

Thanks a lot, Odd!

I hope this helps :)