via HW: Blink LED and SW: hello world
- HW needed: Arduino Uno R3 (or Tinkercad Arduino Uno)
- SW needed: Arduino IDE 2.x is now there. Total rewrite. Even if using simulation, it is helpful to see default and example codes. so File>Examples> ... is still useful.
- Alt. HW/SW: Tinkercad, a design and simulation tool will be used for examples. Nice for design and testing before buying. [Also at of post, I'm traveling with no HW.] It is useful for more than just Arduino simulations.
Programming language: C
Hello world s
HW Connection working?
Blink an LED is the HW Hello World when using a microcontroller. It tests that the communication between your computer and the microcontroller work.
So running blink example is a good way to test if your Arduino to your computer communication is working correctly. The blink example code blinks the LED next to pin 13.
file>examples>basics>blink
From Arduino IDE 1) Verify and 2) Upload
If the LED on the Arduino board is blinks then the communication is working.
Notice:
In blink C code notice that LED must be setup via a C #define name is used to identify the LED.
The pin mode must be initialized in setup() via calling the pinmode(LED pin, mode)
SW Hello World
file>new Provides and empty setup() and loop() functions.
Print "hello world" once only needs setup() function.
Arduino "print" output goes to the serial monitor,
so need to use Serial.print(...) and Serial.println(,,,).
- in setup() function add: Serial.begin(9600) // where 9600 is the baud rate most commonly used.
- Then Serial.println("Hello world") can be added.
Remember anything in loop() function" will be keep being repeated. If value changes then want print in loop(). If value doesn't change, then want print only in setup() function, like a title line.
Output appears in the Serial Monitor.
Try both HW blink and SW Hello World to serial monitor.
HW:
Create + > Circuit Design
Drag an Arduino Uno into your design area
SW:
1, Click on Code button
Arduino Uno component comes with blink code (blocks, text, both) in Tinkercad.
Default to seeing the block code. You may find this helpful if moving from block code to C.
2, In dropdown chose text to just see the C code
3. Start Simulation button does both the equivalent of Compile and Upload