Program Arduino UNO from Raspberry Pi

Image for Program Arduino UNO from Raspberry Pi
Tinkerer: Lory Livezey

In this tutorial we're going to connect the Arduino UNO to the Raspberry Pi and modify the Blink sketch. This should get your feet wet with the simplest of Arduino projects!

Previous Step

  Installing Arduino Software onto Raspberry Pi #tt15

What you will need

(or other compatible)
Windows PC or Mac

Open Arduino Software on the Raspberry Pi

Remote into your Raspberry Pi using RealVNC. You should have set this up and installed the Arduino Software in the previous tutorials. If you haven't done so, follow the link under "Previous Step".

Blink - Preloaded

Open the Blink Sketch

Next, we're going to open "Blink", a sample "sketch" (program) that the Arduino comes loaded with. You can tell that the sketch is working when you turn on the UNO and see a light blinking once per second, like this:

Blink - Preloaded

File > Examples > 01.Basics > Blink

Ensure the Arduino/Genuino UNO board is selected:

Tools > Board > Arduino/Genuino UNO

Ensure the port where the UNO is plugged in is selected:

Tools > Port > COMXXX

The Arduino has two main functions. The Setup() function runs once when it starts up. LED_BUILTIN is a name (constant) that refers to the LED light on the board. The line below sets the LED to "OUTPUT" so that we can write values to it.

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

The second function is a Loop() function. The loop will continue for as long as the board is on, constantly checking to see if something interesting has happened, or to run something over and over. In our case, below, the light is turned on (HIGH), there is a 1000 millisecond (1 second) delay, then it's turned off (LOW) for another second. Because it's looping, it will continue to do this 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
}

The Pre-Loaded Blink Sketch

Blink - Preloaded

Modify the Blink Sketch

In this example, we're going to modify the Blink sketch to blink faster. Change the delay from 1000 ms (1 second) to 500 ms (1/2 second)

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(500);                       // wait for a second
}

Once you've made the changes, download them to the Arduino

Blink - Modified

The Modified Blink Sketch

Blink - Modified

Be sure to subscribe to our channel!