Basic Arduino Programming
Notes
- Please note, I am not an expert in this area.
- I have accomplished every task I wanted to...
- But I don't know the language fully.
- And very few nuances.
- The Arduino IDE is a useful way to program.
- Available here
- When you install it will
- Ask for public or single user, just single user
- Ask for admin permissions, just no on these.
- Install a bunch of libraries, this is OK.
- You will need to set the board to be Arduino Nano.
- I tend to keep The Language Reference open.
- A first program.
- Hello world.
- In the
looproutine- We need to initialize the serial port
-
Serial.begin(9600);
- In the main routine
-
static bool firstTime{true}; if(firstTime ){ Serial.println("Hello World!"); firstTime = false; }
-
- Hit the
- Check mark icon in the green bar to compile
- Right Arrow icon in the green bar to compile and download.
- When I went to run this on my work machine, I had to install the Arduino ESP32 Boards library.
- When this runs, you may have to click on the magnifying glass on their right side of the green bar to see the serial output.
- The print command has two forms
- println - print line
- Either take zero to two arguments
- The first is the thing to print.
- The second is an optional format
- for integer: DEC, HEX, OCT, BIN
- For float: decimal places
- Note the static in the declaration of
firstTime- remind me what this does.
- Let's blink an led
- On the variable part of the language reference they provide
- predefined constants
- data types
- And other information.
- We are interested in the following constants for the next part.
-
LED_BUILTINrefers to one of the built in leds -
HIGHis a 1 in digital logic -
Lowis a 0 in digital logic -
INPUTtells the board you will be reading from this pin -
OUTPUTtells the board you will be writing to this pin - We will use other constants later.
-
- To write to a digital pin
- You must configure the pin.
-
pinMode(pin number, usage); - For our code, in the
setuproutine-
pinMode(LED_BUILTIN, OUTPUT);
-
- We will then need to write to it
- In the
looproutine-
digitalWrite(LED_BUILTIN, HIGH); -
digitalWrite(LED_BUILTIN, LOW);
-
- Since these would blink too fast, add a delay
-
delay(milliseconds); - Remind me, what is a millisecond
-
- On the variable part of the language reference they provide