Author Topic: programming 101  (Read 12178 times)

0 Members and 1 Guest are viewing this topic.

Offline kjn4685Topic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: us
programming 101
« on: November 16, 2014, 09:34:09 pm »
Well guys I want to start learning to program a microcontroller. So I want to know if I can build my own programmer can it be done and if someone out there has a schematic I would appreciate it very much. I have never programmed anything ever. So I mite have a lot of help.

Thank you in advance.
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 12614
  • Country: us
Re: programming 101
« Reply #1 on: November 16, 2014, 09:40:07 pm »
Do you mean you have never written any computer programs? Because programming a microcontroller can mean two different things. It can mean sending an existing program over the wire and storing it in a microcontroller for execution. Or it can mean writing the program code that the micro will later execute.

If you have never written any program code before and you want to learn, you should pick a learning environment with ready made hardware so that you only have one thing to learn at a time. For instance you could try beginning with an Arduino, or you could try learning to program on a PC first.
 

Offline kjn4685Topic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: us
Re: programming 101
« Reply #2 on: November 16, 2014, 09:56:18 pm »
Well yes I have written in basic about 25 year's ago. I had a ti computer I don't know if you know what that is. It came out about 1985 it was made by Texas instruments. Was interfaced with a tv.
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 12614
  • Country: us
Re: programming 101
« Reply #3 on: November 16, 2014, 10:14:03 pm »
Well yes I have written in basic about 25 year's ago. I had a ti computer I don't know if you know what that is. It came out about 1985 it was made by Texas instruments. Was interfaced with a tv.

A TI-99/4A?

I still would suggest getting your feet wet with an Arduino and working up from there. There's no shame in starting at the beginning.
 

Offline kjn4685Topic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: us
Re: programming 101
« Reply #4 on: November 16, 2014, 10:28:06 pm »
I agree you are right so I will do that and thank you very much for your help.
 

Online hamster_nz

  • Super Contributor
  • ***
  • Posts: 2828
  • Country: nz
Re: programming 101
« Reply #5 on: November 16, 2014, 10:28:35 pm »
If you have never written any program code before and you want to learn, you should pick a learning environment with ready made hardware so that you only have one thing to learn at a time. For instance you could try beginning with an Arduino, or you could try learning to program on a PC first.

Part of me thinks that programming on a PC (or Android) has become too complex. For me, small projects on a microcontroller like an Arduino would be the best place to learn to elementary programming if you also had an interest in electronics too.

To be an interesting learning experience there must be a purpose behind it (be that to blink an LED, make a beep or to build robot, a simple burglar alarm...), rather than doing something where there is a $2 app for that.

In general Arduinos are a mighty fine platform to start programming in C - in my opinion far better than Visual Studio Express.
« Last Edit: November 16, 2014, 10:41:25 pm by hamster_nz »
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: programming 101
« Reply #6 on: November 16, 2014, 10:36:28 pm »
Quote
I want to start learning to program a microcontroller.

I would start with C on a PC. Get yourself a modern IDE, like Code::Blocks.

Once you have mastered C, move to CB + gcc-avr or Atmel's compiler for AVR.
================================
https://dannyelectronics.wordpress.com/
 

Offline kjn4685Topic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: us
Re: programming 101
« Reply #7 on: November 16, 2014, 10:42:54 pm »
My other question is can I build my own programmer. Like the pic 2 or some other programmer.
 

Offline Hideki

  • Frequent Contributor
  • **
  • Posts: 256
  • Country: no
Re: programming 101
« Reply #8 on: November 16, 2014, 11:07:04 pm »
You can, but that type of in-circuit-programmer is based on a microcontroller, so how do you intend to program the programmer to make it work as a programmer? :D
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: programming 101
« Reply #9 on: November 16, 2014, 11:12:23 pm »
Before you think about building your own programmers, you will need to think about which mcus to learn on. AVRs / PICs are quite popular. PICs have a larger installed base so lots of code, but quite antiquated hardware. AVRs are more popular and have more compiler / ide support, particularly due to the arduino crowd. Both are good to learn on.

If I were to start today, I would probably pick PIC24, or STM8. The 32-bit chips are considerably harder for a beginner.

You can build your own programmers. But you may not find it helpful - the commercial programmers are fairly cheap - mostly free or < $5 for AVRs, and $20 - 30$ for the PICs. Free or $5 for STM8.

Your tools are the last thing you need to worry about so I would say, at least when you start out, go with a commercial / pre-built programmer instead. Of the PIC programmers, I would go with a PICKIT2, unless you are dying to try out the newer chips.
================================
https://dannyelectronics.wordpress.com/
 

Online hamster_nz

  • Super Contributor
  • ***
  • Posts: 2828
  • Country: nz
Re: programming 101
« Reply #10 on: November 16, 2014, 11:15:11 pm »
My other question is can I build my own programmer. Like the pic 2 or some other programmer.


Sure you can, but it is not like the old days when you could bit-bang a parallel port or serial port programmer. Most solutions usually they involve a microcontroller that needs to be programmed with software that is somewhat complex to write yourself. So you will need to at least borrow a programmer to bootstrap the process.

You can even use one Arduino as an ISP programmer to program other Arduinos (http://arduino.cc/en/Tutorial/ArduinoISP).

However, an ready-made inexpensive programmer might allow such things as debugging that can be tricky to impossible on a roll-your-own programmer.

But is it really worth it? You could pick up something like a TI Stellaris Lunchpad (http://www.ti.com/tool/ek-lm4f120xl) for $13, and it includes a USB interface that support the standard on-board Stellaris in-circuit debug interface?

The TI parts are pretty good value - For $13 you get a 32-bit ARM Cortex-M4-based microcontroller with 256 kB Flash memory, 32 kB SRAM, 80 MHz operation, USB host, device, and OTG connectivity, and if you want it to be more Arduino-like you can always use Energia (http://energia.nu/)





Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Online zapta

  • Super Contributor
  • ***
  • Posts: 6376
  • Country: 00
Re: programming 101
« Reply #11 on: November 16, 2014, 11:34:18 pm »
OP, get an arduino uno and you will have all the tools needed to program and run microcontroller programs. In addition you will find tons of examples on the internet and books and a vibrant community and you will have a free world class C/C++ compiler.
« Last Edit: November 16, 2014, 11:35:50 pm by zapta »
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: programming 101
« Reply #12 on: November 17, 2014, 12:55:56 am »
Not for microcontrolers but for C/C++ programming you can get the full Visual Studio Professional Edition for free with the Microsoft Visual Studio Community 2013. Also supports Python, HTML5, JavaScript, C#, VB, and F#.

https://www.eevblog.com/forum/chat/visual-studio-community-2013-a-full-featured-ide-free/msg550822/#msg550822

Add the 20 free seats for Perforce source control and you are using a professional environment. I know you can use CLang on VS so there is no reason you couldn't use a third party compiler,debugger,deployment toolchains with that offering, but I haven't look into that yet.

Maybe too much of a tool for a beginner.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4397
  • Country: us
Re: programming 101
« Reply #13 on: November 17, 2014, 12:57:25 am »
Note that if you do get an arduino (which I agree is a good starting place, probably), then you should get an "Uno" class board, which doesn't need an external programmer of any kind (just plug it into a USB port and you're good.)  After you progress a bit, the Uno can be used AS A PROGRAMMER for programming other devices.
 

Offline DG41WV

  • Regular Contributor
  • *
  • Posts: 51
  • Country: lk
Re: programming 101
« Reply #14 on: November 17, 2014, 01:52:16 am »
Quote from: Hideki on Today at 05:07:04 AM
You can, but that type of in-circuit-programmer is based on a microcontroller, so how do you intend to program the programmer to make it work as a programmer? :D




I used this programmer to program my pickit2 firmware. the programmer is just 8 diodes and a resistor and a capacitor connected to a parallel port.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: programming 101
« Reply #15 on: November 17, 2014, 11:27:15 pm »
Which boards to get is quite dependent on what you're trying to do. Within the arduino world, I would get an atmega32u4 based board - Leonardo - for its analog module.

For arm boards, I would go with the f3 discovery or nuclei boards, for its analog functions, or the f4 discovery or nuclei boards, for speed.

The ti board is very feature rich but a little buggy.
================================
https://dannyelectronics.wordpress.com/
 

Offline SirNick

  • Frequent Contributor
  • **
  • Posts: 589
Re: programming 101
« Reply #16 on: November 18, 2014, 12:12:11 am »
The Arduino Uno is the de-facto choice for learning microcontroller development.  It's cheap, ubiquitous, there are tons of demos and books and tutorials, the community's vibrant, there are tons of hardware add-ons, and when/if you blow up the chip, you can snap in a new one and off you go.  (Just make it a point to try out the Arduino-as-ISP sketch and burn the bootloader to a few bare ATmega 328P chips before you damage the one you have.)
 

Offline kjn4685Topic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: us
Re: programming 101
« Reply #17 on: November 18, 2014, 03:23:04 am »
Hey. Thanks guys
 

Offline Alex30

  • Regular Contributor
  • *
  • Posts: 197
  • Country: au
Re: programming 101
« Reply #18 on: November 18, 2014, 03:38:42 am »
When I got into microcontrollers I didn't bother with arduino and all the rest of it. They are great platforms but I wanted a more bare bones experience of working from the ground up. I picked up one of these https://learn.adafruit.com/usbtinyisp/overview . I really love it. Very easy to use and quite cheap. Plus you can use it for an easy +5V from your usb port. Works with almost any AVR chip. I started with an ATMega32 and just did this tutorial https://www.newbiehack.com/MicrocontrollerIntroductionABeginnersGuidetotheAtmelAVRAtmega32.aspx . Which pretty much set me up and on my way to doing lots of different projects. Good luck!
 

Offline janengelbrecht

  • Regular Contributor
  • *
  • Posts: 181
  • Country: dk
    • JP-Electronics
Re: programming 101
« Reply #19 on: November 18, 2014, 04:27:12 am »
The small problems with Arduino:
1) The programming language is in essence C - the Arduino language is merely a set of C/C++ functions that can be called from your code. Your sketch undergoes minor changes (e.g. automatic generation of function prototypes) and then is passed directly to a C/C++ compiler (avr-gcc+). In general it is not as efficient as the code made in avr gcc+/WinAvr alone.

2) The Bootloader takes up flash code space.

3) Because you are not close to the microcontrollers hardware (register setups etc.) it can be a problem to switch to another microcontroller / IDE / compiler if all you know is the Arduino environment.

When all is said and done...the speed by which youre on your way and making code that works in the Arduino world is extreme compared to other environments...and other architectures.
You could stay in the Arduino world and make professionel results if you should wish so. (Arduino Due is an ARM based processor that means you can come a long way .... and there is the posibility to use a few other ARM based hardware boards too!). And all the above will never be a problem.....too small code memory because of bootloader ? Choose an Arduino Mega :) When all works...you just copy the board hardware to your own design: its open hardware :)

But go for the Arduino first.... in time when your skills are grown i would try some more advanced stuff as somebody has mentioned before me...

Myself ? I started with Z80 on a Sinclair computer (ZX81 i think the name was :P )  - moved on to Intel 8031 - further on to Motorola 6800 - 68000 - Intel 8086/80286/80386/80486 - Siemens 80535 - Atmel AT89C51 - Atmel AVR - Atmel ARM and now i seem to be stucked there :P A journey that took about 30 years :P
« Last Edit: November 18, 2014, 04:33:10 am by janengelbrecht »
 

Offline John_L

  • Contributor
  • Posts: 25
  • Country: au
Re: programming 101
« Reply #20 on: November 18, 2014, 07:14:03 am »
There is a PIC32 based small computer "Maximite" programmed with BASIC interpreter, very similar to 1970s/80 Commodore 64, ZX81 etc. Also a PIC32MX150/170 microcontroller "Micromite" with BASIC interpreter with number of modern functions, PWM, I2C, SPI, 1-WIRE, etc.

You would need to consider carefully where you want to go in the future, as Basic will not exactly lead you to programming in C.

http://geoffg.net/maximite.html


http://www.thebackshed.com/forum/forum_topics.asp?FID=16
 

Offline miceuz

  • Frequent Contributor
  • **
  • Posts: 387
  • Country: lt
    • chirp - a soil moisture meter / plant watering alarm
Re: programming 101
« Reply #21 on: November 18, 2014, 07:56:00 am »
I've started teaching an Arduino programming course now and I must say, it's not that easy to teach programming on a microcontroller. My students don't have any programming experience, so it's not just programming microcontrollers, but programming in general.

The main problem I stumble on with Arduino are various inconsistencies. Like, why do I have to write Serial.begin() why upper case, why dot, why make such a basic functionality as a class? It creates unnecessary complexity - some "special case".

Another thing I've noticed is that my students declare pin as an input via pinMode(pin, INPUT) before doing analogRead() on it. Well, I can't blame them - I've said you have to declare pin as input before reading from it :) another special case - you don't have to declare pin as input before analogReading from it. But you still have to declare pin as an output before analogWriting to it.

The list goes on. Sometimes I think it would be easier if I would just teach them low level peripherals and register access.

Arduino is great for copypasting soething quickly, I myself do use it for prototyping and small noncritical projects, but for teaching / learning programming -- unfortunatelly no, its API is just an inconsistent mess.

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: programming 101
« Reply #22 on: November 18, 2014, 11:39:33 am »
You can  code an arduino board as if it is an avr, with all the glories of using registers.

The beauty of using an arduino board is their abundance of shields and low prices.
================================
https://dannyelectronics.wordpress.com/
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4397
  • Country: us
Re: programming 101
« Reply #23 on: November 18, 2014, 01:30:46 pm »
Quote
it's not that easy to teach programming on a microcontroller.
Yes; this.  "So hard to remember that you were trying to drain the swamp, when you spend all your time fighting alligators."
Unfortunately, a lot of "beginning programming" instruction for non-microcontroller environments has the same sort of problem, with the basic principles getting obscured by attempts to make the programs look like the snazzy GUI interfaces that people see as USERS.  Bring back the days of "program myprogram(input, output)" where most of what you did was neither input nor output (and thus those could be provided by assorted external mechanism.)
 

Offline SirNick

  • Frequent Contributor
  • **
  • Posts: 589
Re: programming 101
« Reply #24 on: November 18, 2014, 07:44:14 pm »
I tend to agree that programming microcontrollers is probably not the best way to start programming in general.  However, here are a couple counter-arguments to that:

1) PC environments are a lot more complicated than they use to be.  If we assume Windows, then your obvious choice is Visual Studio Express.  It's not terribly hard to use, but there's a little bit of a learning curve in figuring out an IDE (any IDE really) since all your options are right there all at once.  And while many C books start you out with:

Code: [Select]
int main (int argc, char *argv[]) {
    printf("Hello world\n");
}

... on Windows, you get all that char vs. tchar vs. wchar vs. whatever, for one of many such examples.  The first time I created a console project in VS, I was stuck for days trying to figure out how I'm supposed to deal with characters, since obviously Windows had it's own way of doing things that did not look like the examples in your typical book.  Having never really learned Windows programming, I'm still not sure of the right way to do many simple things because of architectural differences from the basic, portable coding practices that have been the staple of tutorials since C was created.  (I've actually helped a couple new Arduino users who couldn't figure out why the compiler kept complaining that DWORD was undefined.  I'm in a similar boat, but in reverse.)

IMO, Linux is a better environment for learning C, since it actually looks like normal C, but that could be personal bias.  Writing code in a simple text editor and then running gcc from the command line made it really easy to write my first working program, but you do have to consider the learning curve of an alternate OS as well -- which is not nothing.

In contrast, the Arduino IDE is stupid simple (in good and bad ways), there's zero tool-chain setup, and you can write and upload your first program within minutes of downloading the software.

Either way, you have to learn to code, but keeping the "other stuff you have to know" down to a minimum is a plus.

2) The biggest aid in learning anything is motivation.  If you're terrifically bored by writing four-function calculators and array sort routines, you may never get through a programming book.  OTOH, if you can write five lines of code and get a blinking LED, that might be enough to hook you.  It's a long journey either way, but if you're excited to take that journey, you'll actually do it.

So, while programming on a PC first is probably academically beneficial, if your goal is to nurture an enjoyable hobby, you might opt to go for the route that is most engaging.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf