Sketch
Until I learn a better definition, the code that Arduino runs is called a “Sketch”
Outcome of running the first program
Several benefits of running first program is: confirming the connection works between UNO and computer; making it do something (blink the onboard LED); be courageous and change a parameter to blink at different rate; reflect on prior known syntax and see what’s familiar; be open to learning new elements of programming; spending additional time to really understand the syntax (cross-reference different sources) – which granular detail I’ll place in another post.
Installing the included USB Cable: Kit comes with quite a sturdy looking cable that connects to the UNO board and to a USB port on back of computer. Simple enough. Pretty tight on the UNO board, so I’ll be connecting/disconnecting from the Mac, for now.
One steady LED next to “ON” on the board – makes sense. Steady flashing LED next to “L”, which tells me that the board remembers the last loaded program. That’s right – I’m blogging this, after I actually ran the first program.
Running the Arduino app: Icon looks like a Green circle (face) with goggles and a – and + . Confirming configured to board (Tools, Board, Arduino Uno) – remembered from last setting. Tools, Port, chose something with “serial” – good sign, because this means app is using driver to connect (serial) to the board. The app automatically loads boilerplate code to get you started. So far so good.
Loading the sketch: In this case, the app includes the blink sketch. I suppose I could copy/paste from the “Lost in Space” site, but I’ll use code from the app for now. Files, Examples, Basic, Blink. This opens a new window, which overlays the default window, so I’m closing default window. Note: In bottom right of app, I’m seeing confirmation of the Board Uno and serial port being connected. The code looks reasonably simple and high-level, but let’s dig deeper into this.
Memories of programming syntax: Brought back memories from c programming, where you can create either a single or multi-line comment beginning with a /* and ending with a */. If you want to comment on a specific line, to the end of the line, then leading with // – this is helpful if you want to comment, on the same line, after a piece of code.
Running the sketch: Looks like the code is ready to go. In top of app, there are two icons (checkmark that says “Verify” and right-arrow that says “Upload”). Clicked on “Verify” and it did a couple things and returned “Done Compiling” and how much storage space used – 2%. Clicked on “Upload” and returns “Done Uploading”. The board is doing the same thing – blinking the LED at a rate of 1 second.
Making a small change: I got the idea from a “Lost in Space” configuration video, so I’ll change the blink rate. I haven’t figured out what PinMode and DigitalWrite is yet (even though it appears obvious), but I see Delay (1000); . How about changing it to 500; click verify; click upload (while looking at the board) – I saw a couple LEDS on the board flickering as it talked to the board and… YES! the LED is now blinking twice the rate. 100 – now, I’m having too much fun. Changing to 5000 – On… stays on… Off… stays off. Also, I’m only clicking on Upload (and not verify) as I’m only changing the number. After doing this a couple times, I’m seeing on the board that Rx (receive) and Tx (transmit) were flickering – that makes sense.
Line-by-line granular detail
I’ll place details of this in another post, as I want to really understand the syntax, digital pin 13, and cross-reference to some of the documentation from Arduino. The concept of running a program which talks to pins on electronic hardware is a new animal for me. What’s also knew is needing to understand things like: amps, ohms, resistors, schematics – definitely going into new territory.
Impressions so far:
What I’m really liking is the physical/visual cause and effect this is offering. I have this external device (UNO board), connected to the computer. I modify the code on the screen; upload it; and something happens on the board – in this case blinks the LED. It gives me a sense of “this is cool, and all doable”. It’s also bare bones simple, as I haven’t connected the white brick (breadboard) yet. I’ve never connected anything to a breadboard before, so I’m sure there’s more to understand. While I’m only remember the c programming comment (/* and */) right now, there’s at least that – transferable skills.
The whole program
/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
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
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
modified 8 May 2014
by Scott Fitzgerald
modified 2 Sep 2016
by Arturo Guadalupi
modified 8 Sep 2016
by Colby Newman
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}