Programming language to interact with electronics?

Thread Starter

tomydom

Joined Dec 7, 2016
24
I'm very new to this but I have a question.
I want to learn a programming language which can be used efficiently to interact with electronics. I'm not sure how or what yet but I'm going to make it a hobby and learn it over several years.

I already know C++ but I thought that something like Assembly language might be my best bet. Is that the case?

I also know that there's micro-controllers out there such as Arduino to do all this but I want to learn how to get my programs to turn things on and off in a circuit and learn how to make programming and circuitry interact.

I know this question is a little broad but I'm staring off by looking at potential programming languages for this kind of thing.

Any help would be greatly appreciated. (maybe some books)
Thanks
 

JohnInTX

Joined Jun 26, 2012
4,338
Welcome to AAC!
If you haven't done embedded programming to control electronic stuff but know C++ an Arduino would be ideal. Cheap and and gentle introduction to the field. Adding shields takes care of hardware and a big user base for code resources.
If you want to get down and dirty with assembler or C even, take a look at PIC (much steeper learning curve). Try one of the 'Curiosity' demo boards. They are dirt cheap and include resident debuggers/programmers for about $10. Microchip has free IDE, compilers and assemblers, too.
Lots of help here either way you go.
Good luck!
 

Thread Starter

tomydom

Joined Dec 7, 2016
24
Thanks for that. Very useful information here.
I'm still trying to piece together the whole process in my head.
So, how, for example, does assembly language run a washing machine?
Is the code written on a computer and then uploaded to something in the electronic washing machine?
What is that thing that the code is uploaded onto to make things work when a button is pressed? Are there mini computers in washing machines which can use small programs?

If I was to create something like this, would assembly language be best or C/C++ ?

This is the part I eventually want to understand.

Thanks
 

Veracohr

Joined Jan 3, 2011
726
Depends on the chip and the IDE probably but you can use either assembly or C/C++ I think. If you want something simple on a limited RAM MCU, assembly might be the way to go. But for something complex, assembly might be too cumbersome. You have to do everything explicitly.
 

MrChips

Joined Oct 2, 2009
22,067
We covered this recently here.

Be aware that one can easily spend four years or more at a college or university learning to become an embedded systems engineer or programmer. And even after that training you can still be good for nothing.

This is not meant to discourage you. You can get a head start learning to program microcontrollers as a hobby. Within 6 months or a year you might just begin to get the hang of it. It would be interesting to come back and visit your initial post after two to five years and see how far you have come along.

The fact is there is a long road ahead. A journey of 1000 miles begins with the first step.Then you never stop learning.

I always suggest this Freescale/NXP primer as first time reading.

http://www.nxp.com/assets/documents/data/en/reference-manuals/M68HC05TB.pdf
 

dannyf

Joined Sep 13, 2015
2,197
I thought that something like Assembly language might be my best bet. Is that the case?
depending on what you want to do and what resources you have in doing that. Assembly language is some of the simplest and most difficult languages to learn and to use. it is often used on the simplest things, or when you want to push the mcu to its performance envelope and beyond.

Rarely in between.
 

Thread Starter

tomydom

Joined Dec 7, 2016
24
Ok, thanks.. I tried to ask this in another thread but the moderator ended it so I'll ask it here.

Let's take for example, a washing machine. I understand that some of the functionality of these appliances are running of some embedded code such as assembly language.

What I'm trying to understand is this.... Is the embedded code built on an IDE or other, then compiled and then uploaded to a computer in the washing machine or appliance? What is the code placed in to help it to run functions in the washing machine?

Is this the job of a micro-controller? Or....is a computer a pre-step to this.. What holds the program in the washing machine?
 

OBW0549

Joined Mar 2, 2015
3,566
I want to learn a programming language which can be used efficiently to interact with electronics. I already know C++ but I thought that something like Assembly language might be my best bet. Is that the case?
Yes. No. Maybe. It depends. C, C++ and assembly language are all useful. Java, Python and others are used, too. I don't think you can designate any one language as "best" because what's best, in my opinion, is to become proficient in multiple languages.

I also know that there's micro-controllers out there such as Arduino to do all this but I want to learn how to get my programs to turn things on and off in a circuit and learn how to make programming and circuitry interact.
Ummm... you are making a distinction where there is none. People use Arduinos (which are not microcontrollers, but rather microcontrollers plus power supply plus USB communication plus I/O connections, on a compact little circuit board) to do exactly that, and that's what they're for.

So, how, for example, does assembly language run a washing machine?
By taking inputs from the user's control panel and from sensors (water level sensor, load-imbalance sensor, etc.) and processing them appropriately to generate outputs to drive various actuators (motors, clutches, valves, control panel indicators, and so forth).

Is the code written on a computer and then uploaded to something in the electronic washing machine?
Yes.

What is that thing that the code is uploaded onto to make things work when a button is pressed?
The code is loaded into non-volatile memory (usually FLASH) residing in the microcontroller chip.

Are there mini computers in washing machines which can use small programs?
Microcontrollers are "mini computers." They are not minicomputers, which is something different (and largely obsolete these days, as a distinct class of computer).

If I was to create something like this, would assembly language be best or C/C++ ?
See answer to first question. In my opinion, it's best to become adept (to some degree or other) at all three.

Let's take for example, a washing machine. I understand that some of the functionality of these appliances are running of some embedded code such as assembly language. Is the embedded code built on an IDE or other, then compiled and then uploaded to a computer in the washing machine or appliance?
Yes.

Is this the job of a micro-controller? Or....is a computer a pre-step to this..
Not sure what distinction you're trying to draw, here.

What holds the program in the washing machine?
Non-volatile memory located inside the microcontroller chip.
 

dannyf

Joined Sep 13, 2015
2,197
On a comouter (typically), You write the code, and the compiler compiles it and the linker produces an executable for the target MCU. A programmer then burns it into the MCU.

All of that process can be integrated into an ide.
 

Thread Starter

tomydom

Joined Dec 7, 2016
24
OBW0549,, thanks for the explanations. It's definitely helped a little.

Just so you know.. I'm not trying to make any distinctions at all.. I'm just trying to understand a little more.
I can't make any distinctions because I don't understand anything yet. I'm sure I will shortly going off some of the information you and others have provided.
 

ErnieM

Joined Apr 24, 2011
8,058
A micro controller is a self contained chip that includes a processor, memory, and oft several other functions such as A2D converters, pulse width modulators, and so on. It merely runs code, it is not used to make code.

Code is made with a separate compiler usually run inside an IDE on a PC. This produces a code image that another piece of hardware called a programmer will load (flash) into the micro.

For something like a washing machine the micro will monitor the buttons and switches of the front panel, drive the display lights or whatever, and most importantly control some sort of relay to turn on the high voltage AC to run the motors, heaters, valves and whatever the machine needs to do the washing.

The micro is designed as part of the whole system, what needs to be monitored and what needs to be controlled.

While I can write assembly I much rather use some sort of higher level language as it is just faster and better checked for errors than base assembly. Many may differ but the vast majority of code is written this way. Those who do use assembly have other constraints to meet, such as bare bone cost per unit so a higher design charge is spread over many many units.

C is used in many micros as a first choice. The Arduino uses a language similar to C and is worthwhile to learn. Actually any language is a good choice since if you keep this as a career you will be learning different languages suitable for a given task. (C++ is less oft used since many micros have limited memory to let C++ make objects.)

I would suggest getting any development board with some sort of tutorials. This way you get a pre tested set of hardware with code you know works. Once you get that then you will have the experience to first modify the tutorial code then write your own from scratch.

I suggest this because without these training wheels you will be left staring at a brick (computer that doesn't do anything) wondering if you have a code issue, a hardware issue, or something else you can't figure out and this leads to you getting discouraged.

Best have a board or more you no longer use but one day look back on with fond memories for the things it taught you.
 

BR-549

Joined Sep 22, 2013
4,938
tomydom.......instead of thinking of programming code.........think about patterns and positions. With a 8 bit machine......we have 255 different patterns that can make a word. In the memory we have an instruction pattern list and a data pattern list.
When you turn the computer on.......the cpu will load the first instruction pattern into the cpu. Now depending on the instruction, it might or it might not load data from the data list. The cpu just loads instructions, and data if needed, executes the instruction......then goes back and gets the next instruction pattern.

These instruction patterns tell the cpu what to do. Programming code, no matter what...ASM or C or whatever...........just organizes the instruction patterns and data patterns in memory.
 

OBW0549

Joined Mar 2, 2015
3,566
If you're just getting started with microcontrollers and electronics, you might consider getting one of the Arduino starter kits on the market. Vilros makes a good one; in addition to an Arduino Uno R3 it includes a solderless breadboard, jumper wires, USB cable, and an assortment of electronic components such as transistors, resistors, LEDs, switches and potentiometers, and output devices such as a piezo beeper, a servo motor and a relay, plus a very well-written instruction book. It's an excellent beginner's kit that will help you get past most of your present questions, very quickly.
 

hp1729

Joined Nov 23, 2015
2,304
I'm very new to this but I have a question.
I want to learn a programming language which can be used efficiently to interact with electronics. I'm not sure how or what yet but I'm going to make it a hobby and learn it over several years.

I already know C++ but I thought that something like Assembly language might be my best bet. Is that the case?

I also know that there's micro-controllers out there such as Arduino to do all this but I want to learn how to get my programs to turn things on and off in a circuit and learn how to make programming and circuitry interact.

I know this question is a little broad but I'm staring off by looking at potential programming languages for this kind of thing.

Any help would be greatly appreciated. (maybe some books)
Thanks
I'm not sure what you mean by "programming that interacts with electronics". I don't think any instruction set is oriented to specific electronics. All circuits of microcontrollers are electronics. Do you mean referenced to specific addresses (like a microprocessor) instead of registers?
 

Thread Starter

tomydom

Joined Dec 7, 2016
24
hp1729 - When you don't understand something, it's hard to know what to ask. Bear with me ;)

Everyone, thanks for the help.. As mentioned It's difficult to know what to ask sometimes but you answers have really helped. I've got something to go on now.

By understanding the chain of events, I at least can make sense of some of the things I read on the web.
 

edwardholmes91

Joined Feb 25, 2013
210
@tomydom When I was at school we used PICAXE microcontrollers and I really enjoyed using them. They're basically a PIC microcontroller which has been pre-programmed with bootstrap firmware code which allows you to program them using simple BASIC language. They can also be programmed with simple flow charts. They're nice because you can get almost instant results with very little knowledge of programming and you can also achieve quite complex tasks when you already have a good understanding of programming.

If you are looking for something a little more in depth, you can program something like an MC68HC11 microcontroller using C, learning how to address the different ports and registers etc. but as people have already mentioned, there is a much steeper learning curve with this. Or as you mentioned, you could go one step further and look at using assembler. If you really want to get to the nitty gritty, you can even look at the machine code for a microcontroller, but this really is painstaking!
 

OBW0549

Joined Mar 2, 2015
3,566
In large volume produced items is the use of a mask still used for firmware ?
I don't know for sure, but I suspect not. Most, or nearly all, microcontrollers nowadays are made with FLASH memory for program storage rather than masked ROM. The customer can load his code into the micro and verify it using a production programmer at his facility, or the chip manufacturer can do it so the chips arrive already programmed.
 

hp1729

Joined Nov 23, 2015
2,304
Just starting? I suggest following history. Start with an older processor, 8085, Z80, or such. Then move toward the newer microcontrollers.
 

OBW0549

Joined Mar 2, 2015
3,566
Just starting? I suggest following history. Start with an older processor, 8085, Z80, or such.
I see absolutely zero benefit to doing that; none whatsoever. He's not going to learn anything useful from them, and about all he's going to get out of the exercise-- maybe-- is an appreciation for what pains in the butt those things were to work with compared to what's available today, and how pitiful their performance was in comparison.

Then move toward the newer microcontrollers.
Far better to start with the newer ones, and not waste the money on antiques.
 

ErnieM

Joined Apr 24, 2011
8,058
A micro computer is a different animal from a micro controller. The computer needs several other components before it can work, such as memory (both RAM and ROM), maybe a clock, and also anything for getting d'état in or out of the beast. True it teaches you what these blocks are doing but you can also just read the data sheet for a modern industry standard micro controller.

My company actually has a standard sub component (a system monitor) that is such an old design it actually uses a micro computer. It is in redesign now as the computer chip itself is going end of life and will no longer be available.

Aside: I am unaware of anything that uses mask programming at the chip level for mass production. Modern devices are so easily programmed in circuit there really is not a need for this added step and expense for a device you may end up throwing away if your firmware turns out not to be so firm.
 
Top