Lab Resources:
There's a pretty long list of links from this Adafruit page. They are all relevant and interesting but the core stuff is in the overview and the Forward Voltage/KVL links.
It's a pretty short tech spec but if you need basic information this is the sort of document you need to be able to understand.
PWM (Pulse Width Modulation) and the analogwrite() function:
One of the skills I want you to develop/confront during the term is the ability to go to the 'manual' and learn what you can about a particular command/function. The Arduino Reference library is pretty good as these things go and has useful links at the bottom to provide more information. Here is the analogwrite() page. Be sure to explore the link at the bottom that defines PWM (think about it's relationship to duty cycle). Not all pins on your Arduino are available for PWM. They are defined in the Arduino Tech Spec above.
Downloading Arduino Sketches:
Remember that Arduino sketches are actually computer code and therefore are essentially computer viruses. For this reason they are usually stored and downloaded as compressed data files called ZIP files (.zip extension). A zipper file can't be executed until it's unzipped which makes it safe until you choose to let it out of the box. The assumption is that if you unzip the file and open it or run it you accept the responsibility for any unintended consequences. You may also find that some email servers will not allow you to attach files unless they are zipped for the same reasons.
What I was thinking:
My focus this term is your learning strategies and how they might be strengthened. What I noticed during the first night that we worked on this lab is that there was a lot of focus on getting the Arduino to do something with the LED's as described in the tutorials embedded in the lab. What I'd like to walk through, in some ridiculous level of detail is what I think is maybe a different model. Takes a lot more time but in the end I think it models how we all have to learn new skills when we're on the job and we have to learn it on our own.
Blink: Blink Sketch
The Blink tutorial gets us talking to the Arduino and controlling the LED that is built into the Arduino board as a first step (because it requires no external wiring or tools).
Here's the standard code from the Arduino site: My comments and thoughts are in red
/* --- so what is this? Why would code start with this symbol? Here's the reference. Where does this comment end? Some kind of comment symbol exists for every kind of computer language. Look for it and know it.
Blink-- comments are incredibly useful for learning and if you don't use this tool all the time. Highly recommended. In this case Blink is a name and what follows below is a description. For this simple example it doesn't take much but for complex settings feel free to insert pages of description here. A future you will really thank you......
Turns an LED on for one second, then off for one second, repeatedly.
-- still inside the comment block here. What the various coders have done is document their understanding of the technical specs that are relevant to this sketch/program. You will notice that the comment block has been modified 3 times before and you can't tell what was changed by which coder. If you want to be more careful the you put your initials in parentheses (be) before or after the change you made in the comments so the information can be tracked if needed.
Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to -- LED_BUILTIN is predefined to describe the pin which is connected to the onboard LED used in this and many other sketches. What this means is that you should be able to replace LED_BUILTIN with 13 -- on an UNO -- and the sketch would work the same. This is actually worth testing as you get to know how to use your Arduino. Who knows if the manfacturer of your Arduino clone uses exactly the standard pin assignment. Have you looked to see where the pin numbers are on your Arduino board? Are all the labels just the same? -- answer is usually no, the next question is why? (not answered here:))
the correct LED pin independent of which board is used.
If you want to know what pin the on-board LED is connected to on your Arduino
model, check the Technical Specs of your board at:
https://www.arduino.cc/en/Main/Products -- nice to tell the future you where the documentation is.modified 8 May 2014
by Scott Fitzgerald
modified 2 Sep 2016
by Arturo Guadalupi
modified 8 Sep 2016
by Colby NewmanThis example code is in the public domain. -- what does this mean in our modern world of digital intellectual property? Worth a quick read about public domain software. Be sure you understand the difference with Creative Commons licensing.
http://www.arduino.cc/en/Tutorial/Blink -- this doesn't actually tell what the link is for though it is perhaps clear.
*/ -- Finally! Here's the end of the comment block. That means you should be able to cut out all of this stuff and the code runs the same. Save a duplicate copy and try it.// the setup function runs once when you press reset or power the board -- another comment, what does it mean? setup is a function (a process) that the small brain of the Arduino runs every time the power is cycled.
-- what the heck does 'void' have to do with anything? Try leaving off the 'void' and see if the sketch works. If you have some coding experience this link on Functions might help but for newbies probably not. Hidden in all the verbiage is the idea that a computer does not like to be surprised. It wants to know what you are doing and what it should expect. One of the things it might expect is to get information back from a process that it executes. The computer wants to know whether the information coming back is an integer, a floating point number, a character, or a string of characters. Perhaps there are other things it might be. 'void' tells the computer that no information is coming back from the process and to chill out!
The brain of the Arduino runs through the steps in the sketch sequentially as it loads though there are some important caveats that will become apparent later. Basically it confuses the system to say c = a + b before you tell the computer what a and b are. Think order of operations in math....
void setup() { -- curly brackets begin the section, what does () mean? -- () provides a place to pass information back and forth to the function (setup is the function) and in this case nothing is needed but the () MUST be there.
// initialize digital pin LED_BUILTIN as an output.-- single line comment lets us know what's next
pinMode(LED_BUILTIN, OUTPUT); -- what other pinMode choices are there? ...here...notice command line ends with ';'. This is a command rather than a function so there is no return value to worry about though there are values that must be passed to the command. This is why it is important to read the command description including the related commands.
} -- curly bracket ends the section. The IDE helps us make sure we close all parentheses and brackets.-- in coding languages it is important to notice small syntax features of the language like upper and lower case in names or colons and semicolons. Unlike human languages coding languages are 'syntactically rigid' because that actually makes them easier to interpret for the computer. What do you notice about syntax in this list of Arduino commands?
// the loop function runs over and over again forever -- single line comment explaining next step.
void loop() { -- loop function described above. What does the void mean? ..the ()? ... the {?
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) -- read about digitalWrite..
delay(1000); // wait for a second -- read about delay.. how would you delay 100 microseconds?
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
} -- close the loop functionTo show your understanding of this sketch remove every comment and empty line and see if you can still make the light flash under your control.
Change to pin 13 instead of LED_BUILTIN and observe changes if any --what do you expect?
Can you use any of the pins 1-12 to do the same thing? What is the difference between digital and analog pins?
If the LED is on and off for the same amount of time what is the minimum cycle time which you can still see if flicker? Is that different if you wave the Arduino back and forth?
Go back into the sketch and make individual intentional errors in the syntax and look at the error messages you get when you try to load the sketch -- can you make sense out of any of them? ...important to consider.
So... for me this took about 2-3 hrs to think about many of the understandings that are embedded in this simple blink sketch. Many of these explorations were ones that I did the very first time I sat down to use my Arduino. I totally support following someone's directions to get it going but after that the careful exploration I've tried to illustrate above is how I learn how to do things I haven't done before.
Here's a sketch that is completely uncommented - not a good model
Here's a sketch that is very well commented which is more complex than the previous one -- but you could figure it out!