Blink sketch in detail

Disclaimer:

It’s been years since I looked at anything resembling programming. As I’m hyper-associative, my big challenge is immediately understanding the code, as my mind is firing off random questions, that can de-rail thinking.

I think the best is to look at it from multiple perspectives. For example, this whole deal about pin 13. The board has a hole for (digital) 13. The LED on the board is linked to pin 13 – I think. LED_BUILTIN is a constant for “13”, I think. I could enter: pinMode (13, OUTPUT); . What is VOID all about? Does “return something” not include the LED flashing?

See what I mean? My plan is to accommodate my natural tendency by following the program details from inventr, and also cross-reference with documentation from arduino.cc. When I see different ways of describing the same thing, it will start clicking together. My hope is that, over time, it will start sinking in and become easier. In my opinion, this is what active learning is all about. I will maintain engagement and interest by asking questions of curiosity, that are pertinent to current area of focus.

I could opt for just loading sketches, skipping over details unknown to me, and primarily focusing on whatever is the current topic, but I’ve found that catches up to me at some point (during troubleshooting, typically). I need understanding of all elements.

When I cross-reference to another site, I’ll place the URLs at the bottom within my REFERENCE section

Comment section:

I covered this topic in another post. There are two forms of comments, that originate from c programming:

  • /* This is my comment, which can span multiple lines*/
  • // This is my comment, which extends from the “//” to the end of the current line (useful for in-line documentation)

Note: I’m impressed with the documentation, included in the sketch, by inventr – it’s actually quite clear – on the 4th reading. LOL!

Pin 13 linked to LED on UNO board

For some reason I had some initial confusion with this. I think it’s because there is reference to a Pin 13, where you attach a wire from #13 to the breadboard and then to an LED. The UNO board also has a red LED. Now, my understanding is that I can (without attaching to the breadboard) reference Pin 13, and it’s going to the onboard red LED.

void setup() {

}
Q: What does void mean?

A: I’ll probably understand this more later, but it means that the program is not expected to return information.

In this sketch – it turns a light on and off.

One good analogy is that If I asked someone to turn a light off and on, and they came back saying that they happened to be in the bathroom at the time – that information (I didn’t know) – the bathroom – would be an example of data being returned to the function. I think…

The “setup” part means that this is run each time the unit is powered up, or if the button is pushed on the board

pinMode(LED_BUILTIN, OUTPUT);

Q: What does pinMode mean?

A: You can configure pins to be either input or output. This will make more sense later.

In this case, I want the Pin to do a mode – output something – LED lighting up.

Q: What is a constant?

A: A constant is a way of assigning something to a variable which is then uniform across entire code or within specific sections of code. The concept allows: uniformity; not having to remember the associated answer (in this case: 13); theoretically being able to uniformly changing the answer by just changing the constant value.

Q: Outputting to…:

A: Well… Pin 13 is associated with LED – so, the LED

void loop() {

}

Void meaning it doesn’t return anything. Loop – it loops forever

digitalWrite(LED_BUILTIN, HIGH);

I’ll understand more soon about volts, amps, etc soon.

For now, Pin 13 is a digital pin. I’m telling it to send to LED_BUILTIN (digital pin 13) 5 volts (High) to turn on the light (LED anode)

Voltage 5 volts

delay(1000);

This causes a timed delay – about a second


digitalWrite(LED_BUILTIN, LOW);

In this case, it’s turning off the flow of 5 volts to digital pin 13 (LED Anode)

delay(1000);

More delays – 1 second

Code (sketch) for Arduino – Blink

/*
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
}

REFERENCE:

https://docs.arduino.cc/built-in-examples/basics/Blink/#schematic

Posted in Microcontrollers | Tagged , | Leave a comment

First sketch – Blink

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
}
Posted in Microcontrollers | Tagged , | Leave a comment

Arduino Uno R3 setup

inventr.io “30 Days Lost in Space” kit

While I was initially focused on Micro:bit (MicroPython programming), I kept receiving ads for inventr’s Arduino product (C/C++ programming), which was marketed to both adults and kids. Somehow, that was appealing to me.

They have a gamification approach, and first one getting my attention was “30 Days Lost in space”. Basic premise is that you have to complete various projects/tasks, in order to complete the mission – something like that. There’s someone called Astrid that is there to help.

Arduino HERO board and parts

The kit comes with an Arduino board; bunch of resistors; cables; USB cable to connect to computer; LEDs; OLED screen (cool!); Digital number display; DIP switch; rotating device; push buttons; speaker — all interesting part, bits and pieces. Note: I’m sure the above have official names, but that’s the idea.

“HERO” is named by inventr. They say it’s a derivative of the Arduino UNO R3 Reference Design. Right now, I’m not exactly sure what all that means, but good to know it’s an Arduino UNO R3, as I wanted to be able to cross-reference documentation between inventr and Arduino.

I also got (for $9.99) additional, a board that the HERO microcontroller mounts to (with supplied bolts, spacers, and nuts). The board is designed to also mount (with double-back tape) the breadboard. Looks like it keeps things orderly, as what will ensue are a series of cables going between the UNO and the breadboard.

My computer hardware and OS

Because several computers went south on me, I had to unbox a computer I only used for a couple years (from 2011 to 2015), and then started using it again in 2024. So far so good – working great.

It’s an Apple iMac 21.5″ (Mid 2011). Important to mention because I’m limited in the version of the Mac OS and also the Arduino IDE software. I was able to upgrade to macOS High Sierra (version 10.13.6) and the legacy Arduino IDE (version 1.8.19). I know there is an Arduino IDE 2.x version (which I can’t use with my computer), which includes a debugger. I’m hoping this is not too much of a limiting factor in learning all things Arduino for now.

Driver Install and config

Followed the instructions to first install the driver; approve a security setting; restart computer.

Software install and config

Followed the instructions to install the legacy IDE software; connect the USB cable between UNO and computer; select the board in IDE and chose the obvious serial port.

Cable connection

I’m not sure if it’s OK to keep the Arduino UNO connected to the computer for a long time. I found the cable connection to the UNO is quite tight. Therefore, I’ve loosened the USB cable connection to the back of the computer, and will push it back in again when ready to connect and program.

Posted in Microcontrollers | Tagged , | Leave a comment

Awareness of microcontrollers

Standard Disclaimer: Everything in this post is from top-of-mind memory, understanding and awareness – not necessarily the truth, and subject to change.

Primary intention of revisiting microcontrollers, after first learning about this in 2010, is current reality that (for career development/longevity), it behooves me to be technically savvy around Python/C/C++ and AI/ML, CyberSecurity, along with Data Science/Analysis.

Parallax

Going back to 2010, I heard about California-based Parallax, and purchased their “What is a Microcontroller kit”. Relatively inexpensive (and also received a hefty discount), but didn’t really take it on seriously – maybe because I didn’t have an underlying motivation/reason at the time.

One key attraction to their offering is that you can take programming to another level by building something tangible – a blinking light; a moving arm; a robot, etc. That made the project more intriguing and appealing.

The concept and interest didn’t leave, and I observed (over the years) various technologies developing: cloud; Big Data; storage; robotics; AI/ML; CyberSecurity – all maturing and collaborating with each other. Programming languages were still in play with: Python; C/C++.

Raspberry Pi

I was aware of Raspberry Pi in 2012, but was primarily focused on navigating/supporting IBM Domino and Notes. Dabbled a bit with Linux (Ubuntu and Centos), but not at any depth.

Over time, my readings of Raspberry Pi development, have introduced several (high-level) potential goals. Based on desired project, ability to customize building a relatively inexpensive hardware platform with a choice of various operating systems (including the default: Raspbian OS). Formerly considered standard within a 19″ rack – database servers – are now common-place in smaller form factors.

After acclimating with (Arduino and Microbit) projects, I foresee building a Raspberry Pi 5 Server for learning/integrating systems towards AI/ML. There are some cool cases I’ve read about from Pironman.

AI expansion

As of 2024, the marketing around Artificial Intelligence (AI) has really taken off. In reading about Raspberry Pi, there appears to be add-on boards that create additional compute capacity. I’m cautiously optimistic about AI – especially towards human case managers, who may benefit from an assist with decision support and manual processing. What I’m holding off on is a belief that some app called ChatGPTx is the immediate answer, without initial foundational understanding.

One idea that I’d love to work towards, is some form of GTD Assistant, that I can personalize to my own preferences.

Fun reflection to remember a conversation in 1986 at Fordham University, where my college buddy (Jose, who has now been at IBM for decades), eagerly talk about “Artificial Intelligence” and how he was learning Prolog on the personal computer. He wrote a book – “Pascal with Objects”.

Storage

My experience has always been with traditional spinning drives – laptops and servers. I have basic understanding of Solid State drives (that have minimal moving parts). I’m still learning the pros and cons; storage capacity; buffering; data transfer rates, etc. In looking at Raspberry Pi (Pironman) it’s a bit mind-numbing trying to figure out which brand, model, feature-set is appropriate.

I’ve had some experience with Micro SD Cards, but even then – which brand and storage capacity? In general, I’ve seen this used for loading of OS like Raspberry Pi, and then connecting an SSD drive to take it from there. I’ve always thought of drives as external, but now I’m seeing small (and thin) boards that go inside the case. Amazing how small things are getting lately.

Micro:bit

First heard about Micro:bit when on the Parallax site, looking at Cyber:Bot robots. Appears that BBC (British Broadcasting Corporation) funded a bunch of these boards to be manufactured and shipped to schools throughout the UK. Idea being to create awareness and interest to the younger generation for developing skillsets (programming, hardware, robotics, AI/ML, etc.) I’ve found the price point quite low, with add-ons being reasonable.

Programming language appears to be MicroPython (subset of Python), but you can integrate many other language.

Paralallax has a “What is a a microcontroller” kit that is the microbot board, breadboard, and a bunch of wires and resistors. From there you can upgrade to a Cyber:bot robot, and continue learning towards adding other sensors, movement, etc. Still working on understanding this, but there are courses in AL, ML, Cyber.

Only thing getting in way, in my mindset (for now), is that it’s all marketed primarily at a younger audience. I figured I’ll loop back in to this at some point, as I’m really interested in learning (and certifying) on Python – towards AI/ML and Data Analysis.

I read there’s a strategic collaboration with www.cyber.org – supporting teachers in teaching foundation in CyberSecurity to the next generation.

Inventr.io

Came across this organization from ads on my iPhone. I’m seeing a focus on Arduino (Uno), with their HERO brand, as their starter microcontroller. While it’s evident that an area of focus is younger generation, the video content is aimed at an older crowd – possibly the parent. That, for some reason, appealed to me. I shifted from immediately considering MicroBit to immediately choosing Arduino, to get started. Plan is to complete the gamification approach of “30 Days Lost in Space” program, then purchase the Microbit. Was able to put it together pretty quickly and made the onboard LED blink.

Posted in Microcontrollers | Tagged , , , , , , | Leave a comment