Author Topic: programming 101  (Read 12107 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: 12604
  • 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: 12604
  • 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.
 

Offline 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/
 

Offline 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.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6352
  • 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.
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4392
  • 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/
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4392
  • 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.
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 12604
  • Country: us
Re: programming 101
« Reply #25 on: November 18, 2014, 10:57:42 pm »
... 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.

It's really not so complicated. The Windows extensions are just that--extensions--not differences.

If you write standard C in Visual Studio the compiler will compile and run standard C. It is a standards conforming compiler.

See the attached screenshot, for example.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2828
  • Country: nz
Re: programming 101
« Reply #26 on: November 18, 2014, 11:57:41 pm »
It's really not so complicated. The Windows extensions are just that--extensions--not differences.

If I was interested in Electronics and programming, with minimal existing skills in either, my preference would be: Arduino, then Linux on Small ARM board (e.g. Pi), then PC Linux and finally Windows.

Solid example - creating a burglar alarm alarm for a reed switch on a door, and make a noise when it is open.  Code to support it

1. Arduino - nice and simple - and fully understandable.
Code: [Select]
   setup()
   {
      PinMode(1,INPUT);   -- to switch in door;
      PinMode(2, OUTPUT); -- to beeper
   }
   loop()
  {
     if(DigitalRead(1) = 0)
     {
        // Waggle the beeper
         DigitalWrite(2,1);
         delay(1);
         DigitalWrite(2,0);
         delay(1);
     }
     else
         delay(1);
   }

2. On small Linux box, after a bit of cut-and-paste from various pages. Quite a bit of black magic
Code: [Select]
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

#define MODE_FILE_FORMAT "/sys/devices/virtual/misc/gpio/mode/gpio%d"
#define PIN_FILE_FORMAT  "/sys/devices/virtual/misc/gpio/pin/gpio%d"

int main(int c, char *v[])
{
  char buffer[128];
  FILE *modefile, *pinfile;
  int pin;

  if(c != 2) {
    fprintf(stderr,"usage: %s [pin]\n",v[0]);
    exit(2);
  }
  pin = 1;

  /* Open the GPIO control files */
  sprintf(buffer,MODE_FILE_FORMAT,pin);
  modefile = fopen(buffer,"w");
  if(modefile == NULL)
  {
    fprintf(stderr,"Unable to open mode file: %s\n",buffer);
    exit(2);
  }

  sprintf(buffer,PIN_FILE_FORMAT,pin);
  pinfile = fopen(buffer,"r");
  if(pinfile == NULL)
  {
    fprintf(stderr,"Unable to open pin file: %s\n",buffer);
    exit(2);
  }

  /* Set the pin to be an input pin */
  fwrite("0",1,1,modefile);

  /* Read and display the value of the GPIO pin */
  while(1)
  {
    char buffer[4];
    fseek(pinfile, 0, SEEK_SET);
    if(fread(buffer,1,4,pinfile) <= 0) {
      fprintf(stderr,"Error on read\n");
      break;
    }
    if(buffer[0] = '0')
       system("aplay alarm.wav");
    usleep(100000);
  }

  fclose(modefile);
  fclose(pinfile);
  return 0;
}

3. On PC Linux box, just like 2, but with no Hardware GPIO pins to play with, so find something like http://numato.com/32-channel-usb-gpio-module and adapt the code to it. A bit more black magic and very few hits in Google for howtos.

4. On Windows
   First, work out what you are trying to do (which is hard when you don't know what you are doing)
   Then find and buy a  GPIO board - which will cost more than an Arduino.
   Then read a lot on how to access the GPIO pins (usually involves importing DLLs and other tricks) and custom setting in the build environment
   Then work out how to play sounds through the Win32 API multimedia interface
   Then work out how to use timers to check the pin at regular intervals.
   Then finally start writing code - something as newbie-incomprehensible as this, but would include calls to "PlaySound(TEXT("recycle.wav"), NULL, SND_FILENAME);" and some thing to do the timer.

Then write code like this, where the actual code that does real work ("SetPinLevel(133, 0);") looks pretty much the same as the Arduino code:

Code: [Select]
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;   ///< To use Toradex C Win32 DLLs
 
namespace GPIO_LED
{
    public partial class Form1 : Form
    {
        [DllImport("GPIOLib.dll", CharSet = CharSet.Auto)]  ///< Importing DLL
        public static extern bool SetPinAltFn(Int32 pinNum, Int32 altFn, bool dirOut); ///< External function declaration
 
        [DllImport("GPIOLib.dll", CharSet = CharSet.Auto)]
        public static extern void InitGPIOLib();
 
        [DllImport("GPIOLib.dll", CharSet = CharSet.Auto)]
        public static extern bool SetPinLevel(Int32 gpioNum, Int32 val);
 
        [DllImport("GPIOLib.dll", CharSet = CharSet.Auto)]
        public static extern void DeInitGPIOLib();
 
        public Form1()                       
        {
            InitializeComponent();       
            SetPinAltFn(133, -1, true); ///< To set the SODIMM_133 as GPIO output
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            SetPinLevel(133, 1);        ///< Sets SODIMM_133 as high when button1 is pressed
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            SetPinLevel(133, 0);        ///< Sets SODIMM_133 as low when button2 is pressed 
        }
 
        private void FormClose(object sender, EventArgs e)
        {
            DeInitGPIOLib();            ///< Deinitializes GPIO library and frees up system resources upon closing the program
        }       
    }
}

Which takes me back to my original advice - if you want to play around with programming and electronics then don't use your PC - buy and Arduino starter kit.
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 zapta

  • Super Contributor
  • ***
  • Posts: 6352
  • Country: 00
Re: programming 101
« Reply #27 on: November 19, 2014, 12:11:42 am »
If you get the Arduino Uno, get also this excellent book. 

http://exploringarduino.com/

http://amzn.com/1118549368
« Last Edit: November 19, 2014, 12:13:34 am by zapta »
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 12604
  • Country: us
Re: programming 101
« Reply #28 on: November 19, 2014, 12:58:27 am »
Solid example - creating a burglar alarm alarm for a reed switch on a door, and make a noise when it is open.  Code to support it

Let me fix this for you:

Quote
1. Arduino
   First, work out what you are trying to do (which is hard when you don't know what you are doing)
...

2. On small Linux box,
   First, work out what you are trying to do (which is hard when you don't know what you are doing)
...

3. On PC Linux box,
   First, work out what you are trying to do (which is hard when you don't know what you are doing)
...

4. On Windows
   First, work out what you are trying to do (which is hard when you don't know what you are doing)
...

If you are an absolute beginner, then you can't avoid figuring out where to begin, on any platform.

Also, I don't understand why you have used simple C style programming on Linux, but have passed that by on Windows and gone for something very complicated and obfuscated instead? Especially when my prior post showed that free Windows tools support standard C console programming perfectly well.

Quote
Which takes me back to my original advice - if you want to play around with programming and electronics then don't use your PC - buy and Arduino starter kit.
Your point may be perfectly valid, but that's not news since I pointed to the Arduino in Reply #1 right at the top.

On the PC, you can learn to program. To program, note. Not necessarily learn to interface to external hardware. That's a different dimension.
 

Offline SirNick

  • Frequent Contributor
  • **
  • Posts: 589
Re: programming 101
« Reply #29 on: November 19, 2014, 01:14:55 am »
It's really not so complicated. The Windows extensions are just that--extensions--not differences.

If you write standard C in Visual Studio the compiler will compile and run standard C. It is a standards conforming compiler.

OK, but taking the char stuff for example, what are the limitations of using char[]?  Most of the tutorials I see have the T() macro and all kinds of other crazy stuff going on, plus all these API calls ending in _A and _W.  I assume things aren't much different provided you stick to ASCII <127, but I have no idea what happens to international characters in filenames or text strings.

Advice I've read online varies from "don't bother -- just use char[]" to "always use t_char, stay away from w_char" to "never use t_char, only use w_char" to "depends on whether you've defined UNICODE".  Then, there are the file I/O functions.  I'm sure open() and read() -- or fopen() and fread() -- do exist, but there are a whole slew of C API functions native to Windows that appear to be preferable, given the examples online.

I'm sure I'm making it worse than it needs to be, but I'm ignorant of why there are so many ways to do the same thing, and therefore, what those things do differently to warrant their existence.

In Linux, you just use plain old C.  If large character sets are necessary, it's probably in UTF8 and can mostly be ignored unless you're mangling text yourself.
 

Online IanB

  • Super Contributor
  • ***
  • Posts: 12604
  • Country: us
Re: programming 101
« Reply #30 on: November 19, 2014, 01:24:57 am »
In Linux, you just use plain old C.  If large character sets are necessary, it's probably in UTF8 and can mostly be ignored unless you're mangling text yourself.

In Windows also, unless you have a specific reason to do otherwise, just use plain old C.

There are no limitations of char[] that you need care about. The char data type stores 8 bit bytes and will handle ASCII text. If you are a native English speaker, and have no special need for extended character sets or Unicode, then you can pretend Unicode doesn't exist. (Unless you happen to open a file that was saved by another program with multi-byte character encoding, but that will mess with you on Unix just as much.)

If you want or need to interact with the Windows APIs for graphical programming, then you may need to start caring. But I write nearly all my experimental C and C++ programs as simple text console programs that use standard input and standard output. I just use the standard language features and everything is hunky dory.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: programming 101
« Reply #31 on: November 19, 2014, 01:41:43 am »
char can handle EFIGS languages if you use what people call the ANSI char set, so you are good for English, French, Italian, German & Spanish. But that's no longer the case and UTF8 is wasteful for some languages while wide chars with UTF16 is not (although it would be wastefull for just EFIGS implementations).

tchar allows you to have code that will support wide characters without changing anything other than defining UNICODE. Would that be complicated to a beginner? maybe, but then again if that's how it is done then a beginner will learn it that way 8 bit chars are fading to a thing of the past.

As for Arduino for a beginner, I don't buy that it's hard to figure out what you want to do, we all started from the beginning and we managed just fine, the Arduino IDE enables rookies to get a lot of things done without a lot of complications, just like when someone discovered how powerful a peek and a poke where back in basic and we didn't have any trouble figuring how the interrupts worked and i/o etc.

The ramp up time to get things done in an Arduino is orders of magnitude lower (as in faster) than other platforms, I will dare to say that it's easier than basic back in the days where you had to learn about the bios and what addresses did what and call those from your assembly code because memory restrictions and there was code in the bios that will do what you wanted to do. Now we have libraries and a ton of them so there is more flexibility and we have better documentation.

As far as windows, if you think it's complicated give the windows 8 api a try. Even for experienced windows programmers it's a big leap but at least it's more asynchronous processing friendly and complicated just translates to job security :) Even as much as people moan about COM it's better than CORBA and even if I hate that marshalling is going on behind the scenes, it allows  your code to scale on multi core/multi processors and it's able to give you more concurrency on your code.

Also there are so many samples out there for anything that learning any of them is really not an issue, but just do something instead of thinking that it's hard to do.

Edit: objects are rest, just want to keep on resting, once they are in movement, they just want to keep on moving :)
« Last Edit: November 19, 2014, 01:46:06 am by miguelvp »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6352
  • Country: 00
Re: programming 101
« Reply #32 on: November 19, 2014, 01:58:22 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.

That's incorrect, Arduino gives you full avr GCC c/c++ and you can write your code as efficient or low level as you want.
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2828
  • Country: nz
Re: programming 101
« Reply #33 on: November 19, 2014, 01:58:43 am »
Also, I don't understand why you have used simple C style programming on Linux, but have passed that by on Windows and gone for something very complicated and obfuscated instead? Especially when my prior post showed that free Windows tools support standard C console programming perfectly well.
Google for "wIndows GPIO programming in C" and see what you get - I get answers for the BeagleBone Black before I get any usable Windows Code!

 Maybe I should have instead used WindowsCE code (that I guess won't run on a PC) - it has at least a dozen lines that look like ANSI C, most of them the ones with just a brace on it:
Code: [Select]
#include <Windows.h>
#include <GPIO_API.h>
 
int WINAPI WinMain(     HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   LPTSTR    lpCmdLine,
   int       nCmdShow)
{
  HANDLE hGPIO_API;     
  DWORD count;
 
  RETAILMSG( 1, (TEXT("Testing GPIO\n")));
 
  hGPIO_API = InitGPIOAPI();
 
  if( hGPIO_API != INVALID_HANDLE_VALUE )
  {
    SetOutputGPIOPin( hGPIO_API, 30 );
 
    for( count = 0; count < 20; count++ )
    {
        SetGPIOPin( hGPIO_API, 30 );
        RETAILMSG( 1, (TEXT( "set GPIO 30 is %s\r\n"), ReadGPIOPin(hGPIO_API, 30)?TEXT("Set"):TEXT("Clear")));
        Sleep( 1000 );
 
        ClearGPIOPin( hGPIO_API, 30 );
        RETAILMSG( 1, (TEXT( "clear GPIO 30 is %s\r\n"), ReadGPIOPin(hGPIO_API, 30)?TEXT("Set"):TEXT("Clear")));
        Sleep( 1000 );
    }
    DeinitGPIOAPI( hGPIO_API );
  }
  RETAILMSG(1,(TEXT("Done\n")));
 
  return 0;
}


Rant mode on. Having done *a lot* of C programming on Windows, going back to using WinSock() under Windows 3.0, I find systems programming C on Windows is an abhorrence. Well, maybe that is a little strong, but it sucks big-time.

Have you ever tried to write a true Windows service? ever tried to receive and send data to/from a Serial Port while also doing other stuff? writing network services that need to service multiple sessions? Process multiple file streams at once? accessing physical disks devices to query their size? ever used shared memory and other IPC?  And then accessing GPIO, DACs  or ADCs where no standard API exists? It is a bit like the Chewbacca Defence - "To learn to use C on a platform where the underlying system APIs are not compatible with the native C paradigm - it does not make sense! you must acquit!"

Yep, I'll agree that the random nature of IOCTLs are a bit dodgy on UNIX, but at least the UNIX paradigm is somewhat consistent - almost everything ends up being a file handle to a character or block device, and you can read or write to it.

If I have to program C for pleasure, give me UNIX any day. If you are paying me to program, well that is somewhat different...
« Last Edit: November 19, 2014, 02:03:06 am 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 kjn4685Topic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: us
Re: programming 101
« Reply #34 on: November 19, 2014, 05:30:16 am »
Is there software to wright code and then simulate the code that I have written with out a broad.
 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: programming 101
« Reply #35 on: November 19, 2014, 11:38:14 am »
Yes and no, depending on what code you have written.
================================
https://dannyelectronics.wordpress.com/
 

Offline kjn4685Topic starter

  • Regular Contributor
  • *
  • Posts: 154
  • Country: us
Re: programming 101
« Reply #36 on: November 20, 2014, 11:14:12 pm »
Like c
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2828
  • Country: nz
Re: programming 101
« Reply #37 on: November 21, 2014, 01:14:05 am »
AVRstudio has a simulator in it...
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 #38 on: November 21, 2014, 11:46:42 am »
Quote
Like c

You may or may not debug like C, depending on the code you have written.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf