Go Down

Topic: Moments when you were learning to code? (Read 1 time) previous topic - next topic

vivekkulal

Jan 17, 2020, 01:41 pm Last Edit: Jan 22, 2020, 10:13 am by Coding Badly
So I'm new to coding Arduino and coding in general.  For a while now  I've kind of been able to piece bits of code from other people and bang my head against the problem until I could get something to sort of work.

Not really rewarding and while I may have got something to work, I didn't really understand how it was working.

So I decided to really hunker down and try and actually learn what the code does and why.

Moderator edit: multiple spammy links removed; user banned

UKHeliBob

Quote
So I decided to really hunker down and try and actually learn what the code does and why.
Good for you.  If only more people took that approach instead of trying to cobble together something for an assignment that is due to be handed in tomorrow and expecting someone to help get the credit for it
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Robin2

So I decided to really hunker down and try and actually learn what the code does and why.
Good idea.

Start with some of the short example programs that come with the Arduino IDE. If you have a question about some specific part that you don't understand people here will be happy to help.

All programs should be thought of as a collection of small pieces that can each be tested separately before being brought together.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

larryd

#3
Jan 17, 2020, 03:32 pm Last Edit: Jan 17, 2020, 03:38 pm by larryd
Arduino links of interest.



How to use this forum:
https://forum.arduino.cc/index.php?topic=149014.0 



Listing of downloadable 'Arduino PDFs' :
Either Google   >>>- - - - >       arduino filetype: pdf
Or
https://www.google.ca/search?q=arduino+filetype%3A+pdf&rlz=1C9BKJA_enCA739CA739&oq=arduino+filetype%3A+pdf&aqs=chrome..69i57j69i65.1385j0j7&hl=en-US&sourceid=chrome-mobile&ie=UTF-8



Listing of downloadable 'C++ PDFs' :
Either Google   >>>- - - - >       C++ filetype: pdf
Or
https://www.google.ca/search?q=c%2B%2B+filetype%3A+pdf&rlz=1C9BKJA_enCA739CA739&oq=c%2B%2B+filetype%3A+pdf&aqs=chrome..69i57.22790j0j7&hl=en-US&sourceid=chrome-mobile&ie=UTF-8



Arduino cheat sheet:
https://dlnmh9ip6v2uc.cloudfront.net/learn/materials/8/Arduino_Cheat_Sheet.pdf



Watch these:
Arduino programming syntax:
https://m.youtube.com/watch?v=CbJHL_P5RJ8 

Arduino arithmetic operators:
https://m.youtube.com/watch?v=UUx0_s-ElSs   

Arduino control flow:
https://m.youtube.com/watch?v=QpPGGuaGbCA

Arduino data types:
https://m.youtube.com/watch?v=xmZXWMEltEc 

Jeremy Blume:
https://m.youtube.com/playlist?list=PLA567CE235D39FA84



Understanding Destructive LC Voltage Spikes:
https://www.pololu.com/docs/0J16/all
OR
https://www.pololu.com/docs/pdf/0J16/destructive_LC_voltage_spikes.pdf   

Why MOSFET gate resistors:
https://youtu.be/o0OHGWCZ7B0   



Some things to read

LCD information:
https://learn.adafruit.com/character-lcds?view=all   
OR
https://cdn-learn.adafruit.com/downloads/pdf/character-lcds.pdf?timestamp=1573085286     

Reading a schematic:
https://learn.sparkfun.com/tutorials/how-to-read-a-schematic

Language Reference:
https://www.arduino.cc/en/Reference/HomePage

Foundations:
https://www.arduino.cc/en/Tutorial/Foundations



How and Why to avoid delay():
http://playground.arduino.cc/Code/AvoidDelay

Demonstration code for several things at the same time.
http://forum.arduino.cc/index.php?topic=223286.0



Multitasking:
Part 1:
https://learn.adafruit.com/multi-tasking-the-arduino-part-1?view=all   

Part 2:
https://learn.adafruit.com/multi-tasking-the-arduino-part-2?view=all   

Part 3:
https://learn.adafruit.com/multi-tasking-the-arduino-part-3?view=all   



Sparkfun Tutorials:
https://learn.sparkfun.com/tutorials?page=all   

Micro Controllers:
https://learn.adafruit.com/mcus-how-do-they-work?view=all   

Useful links:
https://forum.arduino.cc/index.php?topic=384198.0

Arduino programming traps, tips and style guide:
http://www.gammon.com.au/forum/?id=12153

Call for useful programming discussions
https://forum.arduino.cc/index.php?topic=383980.0   

Arduino products:
https://www.arduino.cc/en/Main/Products

Motors/MOSFETs
http://www.gammon.com.au/motors

Switches:
http://www.gammon.com.au/forum/?id=11955

https://www.amazon.ca/Arduino-Cookbook-Recipes-Enhance-Projects/dp/1449313876/ref=sr_1_1?ie=UTF8&qid=1522801721&sr=8-1&keywords=arduino+cookbook   





Share tips you have come across, 500+ posts:
https://forum.arduino.cc/index.php?topic=445951.0 

Images from above:
https://www.google.com/search?q=%E2%80%9CShare+tips+you+have%E2%80%9D+larryD+site:https://forum.arduino.cc&prmd=nmvi&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiJw-zu68ncAhXPGTQIHWCDCNwQ_AUIFCgE&biw=1024&bih=653   



Debug discussion:
https://forum.arduino.cc/index.php?topic=215334.msg1575801#msg1575801   

Frequently Asked Questions:
https://www.arduino.cc/en/main/FAQ#toc10   



Number 'type's.
- boolean (8 bit) - simple logical true/false, Arduino does not use single bits for bool
- byte (8 bit) - unsigned number from 0-255
- char (8 bit) - signed number from -128 to 127. The compiler will attempt to interpret this data type as a character in some circumstances, which may yield unexpected results
- unsigned char (8 bit) - same as 'byte'; if this is what you're after, you should use 'byte' instead, for reasons of clarity
- word (16 bit) - unsigned number from 0-65535
- unsigned int (16 bit)- the same as 'word'. Use 'word' instead for clarity and brevity
- int (16 bit) - signed number from -32768 to 32767. This is most commonly what you see used for general purpose variables in Arduino example code provided with the IDE
- unsigned long (32 bit) - unsigned number from 0-4,294,967,295. The most common usage of this is to store the result of the millis() function, which returns the number of milliseconds the current code has been running
- long (32 bit) - signed number from -2,147,483,648 to 2,147,483,647
- float (32 bit) - signed number from -3.4028235E38 to 3.4028235E38. Floating point on the Arduino is not native; the compiler has to jump through hoops to make it work. If you can avoid it, you should.

You should always select the 'data type' best suited for your variables.

ex:
- your variable does not change and it defines a pin on the Arduino.  const byte limitSwitchPin = 34;
- since an analog variable can be 0 to 1023, a byte will not do, you can select 'int'.   ex: int temperature;
- if your variable needs to be within -64 to +64 a 'char' will do nicely.     ex:  char joystick;
- if your variable is used for ASCII then you need type 'char', ex: char myText[] = {"Raspberry Pie Smells"};
- if your variable enables some code then boolean can be used.  ex: boolean enableFlag = false;
- millis() returns the time in ms since rebooting,   ex: unsigned long currentTime = millis();
etc.



Oh, and have fun too :) !

.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

westfw

Quote
I decided to really hunker down and try and actually learn what the code does and why.
I suppose that there are basically two approaches:
  • Deeply analyze and research the particular sketches that you are interested in, to figure out how they work.
  • Study "high level" Computer Science until you know enough that the operation of simple Arduino sketches becomes "obvious."

In the end, you'll probably need a bit of both.

I'm a little sad that I haven't really seen online courses that provide the sort of "Intro to Computer Science" like they used to teach back when ... you didn't actually have a computer to use.   Nowadays, it's all "Intro to <language>", or "How to program your Arduino."  Not enough: "what's a variable, anyway?"  "Why is understanding Binary important?"  "What basic principles are common to computing?"
(And part of the problem is that I'm not sure I'd recognize such a class when I saw it, having done all of that long ago.  There's so much of a difference between "yeah, that agrees with what I already know", and "that would be a good explanation if I didn't know anything.

Go Up